Skip to content

Commit

Permalink
fix: remove haptic, add mnemonic import status text
Browse files Browse the repository at this point in the history
  • Loading branch information
xtruan committed Aug 11, 2023
1 parent 2e4023b commit 39c8dfe
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 74 deletions.
27 changes: 18 additions & 9 deletions flipbip.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#include "flipbip.h"
#include "helpers/flipbip_file.h"
#include "helpers/flipbip_haptic.h"
//#include "helpers/flipbip_haptic.h"
// From: lib/crypto
#include <memzero.h>
#include <bip39.h>

#define MNEMONIC_MENU_DEFAULT "Import mnemonic seed"
#define MNEMONIC_MENU_SUCCESS "Import seed (success)"
#define MNEMONIC_MENU_FAILURE "Import seed (failure)"

bool flipbip_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
FlipBip* app = context;
Expand Down Expand Up @@ -40,7 +44,7 @@ static void text_input_callback(void* context) {
// reset input state
app->input_state = FlipBipTextInputDefault;
handled = true;
view_dispatcher_switch_to_view(app->view_dispatcher, FlipBipViewIdSettings);
//view_dispatcher_switch_to_view(app->view_dispatcher, FlipBipViewIdSettings);
} else if(app->input_state == FlipBipTextInputMnemonic) {
if(app->import_from_mnemonic == 1) {
strcpy(app->import_mnemonic_text, app->input_text);
Expand All @@ -54,11 +58,13 @@ static void text_input_callback(void* context) {
status = FlipBipStatusSaveError; // 12 = save error

if(status == FlipBipStatusSuccess) {
app->mnemonic_menu_text = MNEMONIC_MENU_SUCCESS;
//notification_message(app->notification, &sequence_blink_cyan_100);
flipbip_play_happy_bump(app);
//flipbip_play_happy_bump(app);
} else {
app->mnemonic_menu_text = MNEMONIC_MENU_FAILURE;
//notification_message(app->notification, &sequence_blink_red_100);
flipbip_play_long_bump(app);
//flipbip_play_long_bump(app);
}

memzero(app->import_mnemonic_text, TEXT_BUFFER_SIZE);
Expand All @@ -68,7 +74,9 @@ static void text_input_callback(void* context) {
// reset input state
app->input_state = FlipBipTextInputDefault;
handled = true;
view_dispatcher_switch_to_view(app->view_dispatcher, FlipBipViewIdMenu);
// exit scene 1 instance that's being used for text input and go back to menu
scene_manager_previous_scene(app->scene_manager);
//view_dispatcher_switch_to_view(app->view_dispatcher, FlipBipViewIdMenu);
}
}

Expand All @@ -77,17 +85,17 @@ static void text_input_callback(void* context) {
memzero(app->input_text, TEXT_BUFFER_SIZE);
// reset input state
app->input_state = FlipBipTextInputDefault;
view_dispatcher_switch_to_view(app->view_dispatcher, FlipBipViewIdMenu);
//view_dispatcher_switch_to_view(app->view_dispatcher, FlipBipViewIdMenu);
}
}

FlipBip* flipbip_app_alloc() {
FlipBip* app = malloc(sizeof(FlipBip));
app->gui = furi_record_open(RECORD_GUI);
app->notification = furi_record_open(RECORD_NOTIFICATION);
//app->notification = furi_record_open(RECORD_NOTIFICATION);

//Turn backlight on, believe me this makes testing your app easier
notification_message(app->notification, &sequence_display_backlight_on);
//notification_message(app->notification, &sequence_display_backlight_on);

//Scene additions
app->view_dispatcher = view_dispatcher_alloc();
Expand All @@ -111,6 +119,7 @@ FlipBip* flipbip_app_alloc() {
app->bip44_coin = FlipBipCoinBTC0; // 0 (BTC)
app->overwrite_saved_seed = 0;
app->import_from_mnemonic = 0;
app->mnemonic_menu_text = MNEMONIC_MENU_DEFAULT;

// Text input
app->input_state = FlipBipTextInputDefault;
Expand Down Expand Up @@ -163,7 +172,7 @@ void flipbip_app_free(FlipBip* app) {
furi_record_close(RECORD_GUI);

app->gui = NULL;
app->notification = NULL;
//app->notification = NULL;

//Remove whatever is left
memzero(app, sizeof(FlipBip));
Expand Down
5 changes: 3 additions & 2 deletions flipbip.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <gui/gui.h>
#include <input/input.h>
#include <stdlib.h>
#include <notification/notification_messages.h>
//#include <notification/notification_messages.h>
#include <gui/view_dispatcher.h>
#include <gui/modules/submenu.h>
#include <gui/scene_manager.h>
Expand All @@ -25,13 +25,14 @@

typedef struct {
Gui* gui;
NotificationApp* notification;
// NotificationApp* notification;
ViewDispatcher* view_dispatcher;
Submenu* submenu;
SceneManager* scene_manager;
VariableItemList* variable_item_list;
TextInput* text_input;
FlipBipScene1* flipbip_scene_1;
char* mnemonic_menu_text;
// Settings options
int haptic;
int bip39_strength;
Expand Down
35 changes: 0 additions & 35 deletions helpers/flipbip_haptic.c

This file was deleted.

7 changes: 0 additions & 7 deletions helpers/flipbip_haptic.h

This file was deleted.

9 changes: 6 additions & 3 deletions scenes/flipbip_scene_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void flipbip_scene_menu_on_enter(void* context) {
}
submenu_add_item(
app->submenu,
"Import from mnemonic",
app->mnemonic_menu_text,
SubmenuIndexScene1Import,
flipbip_scene_menu_submenu_callback,
app);
Expand Down Expand Up @@ -137,8 +137,11 @@ bool flipbip_scene_menu_on_event(void* context, SceneManagerEvent event) {
} else if(event.event == SubmenuIndexScene1Import) {
app->import_from_mnemonic = 1;
app->input_state = FlipBipTextInputMnemonic;
text_input_set_header_text(app->text_input, "Enter mnemonic phrase");
view_dispatcher_switch_to_view(app->view_dispatcher, FlipBipViewIdTextInput);

scene_manager_set_scene_state(
app->scene_manager, FlipBipSceneMenu, SubmenuIndexScene1Import);
scene_manager_next_scene(app->scene_manager, FlipBipSceneScene_1);

return true;
} else if(event.event == SubmenuIndexSettings) {
scene_manager_set_scene_state(
Expand Down
31 changes: 20 additions & 11 deletions scenes/flipbip_scene_scene_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@ void flipbip_scene_1_callback(FlipBipCustomEvent event, void* context) {
void flipbip_scene_scene_1_on_enter(void* context) {
furi_assert(context);
FlipBip* app = context;
flipbip_scene_1_set_callback(app->flipbip_scene_1, flipbip_scene_1_callback, app);
view_dispatcher_switch_to_view(app->view_dispatcher, FlipBipViewIdScene1);

if(app->import_from_mnemonic == 1) {
// handle mnemonic seed import mode with text input, this only
// uses this scene to have a correct stack os scenes
text_input_set_header_text(app->text_input, "Enter mnemonic phrase");
view_dispatcher_switch_to_view(app->view_dispatcher, FlipBipViewIdTextInput);
} else {
// handle all other modes, these actually use this scene's logic
flipbip_scene_1_set_callback(app->flipbip_scene_1, flipbip_scene_1_callback, app);
view_dispatcher_switch_to_view(app->view_dispatcher, FlipBipViewIdScene1);
}
}

bool flipbip_scene_scene_1_on_event(void* context, SceneManagerEvent event) {
Expand All @@ -21,16 +30,16 @@ bool flipbip_scene_scene_1_on_event(void* context, SceneManagerEvent event) {

if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case FlipBipCustomEventScene1Left:
case FlipBipCustomEventScene1Right:
break;
case FlipBipCustomEventScene1Up:
case FlipBipCustomEventScene1Down:
break;
// case FlipBipCustomEventScene1Left:
// case FlipBipCustomEventScene1Right:
// break;
// case FlipBipCustomEventScene1Up:
// case FlipBipCustomEventScene1Down:
// break;
case FlipBipCustomEventScene1Back:
notification_message(app->notification, &sequence_reset_red);
notification_message(app->notification, &sequence_reset_green);
notification_message(app->notification, &sequence_reset_blue);
//notification_message(app->notification, &sequence_reset_red);
//notification_message(app->notification, &sequence_reset_green);
//notification_message(app->notification, &sequence_reset_blue);
if(!scene_manager_search_and_switch_to_previous_scene(
app->scene_manager, FlipBipSceneMenu)) {
scene_manager_stop(app->scene_manager);
Expand Down
18 changes: 11 additions & 7 deletions views/flipbip_scene_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//#include <dolphin/dolphin.h>
#include <storage/storage.h>
#include <string.h>
// #include "flipbip_icons.h"
#include "../helpers/flipbip_haptic.h"
//#include "flipbip_icons.h"
//#include "../helpers/flipbip_haptic.h"
#include "../helpers/flipbip_string.h"
#include "../helpers/flipbip_file.h"
// From: /lib/crypto
Expand Down Expand Up @@ -663,7 +663,10 @@ void flipbip_scene_1_enter(void* context) {
s_derivation_text = TEXT_NEW_WALLET;
}

flipbip_play_happy_bump(app);
// Wait a beat to allow the display time to update to the loading screen
furi_thread_flags_wait(0, FuriFlagWaitAny, 20);

//flipbip_play_happy_bump(app);
//notification_message(app->notification, &sequence_blink_cyan_100);
//flipbip_led_set_rgb(app, 255, 0, 0);

Expand All @@ -678,23 +681,24 @@ void flipbip_scene_1_enter(void* context) {

// nonzero status, free the mnemonic
if(status != FlipBipStatusSuccess) {
memzero((void*)model->mnemonic, strlen(model->mnemonic));
// calling strlen on mnemonic here can cause a crash, don't.
// it wasn't loaded properly anyways, no need to zero the memory
free((void*)model->mnemonic);
}

// if error, set the error message
if(status == FlipBipStatusSaveError) {
model->mnemonic = "ERROR:,Save error";
model->page = PAGE_MNEMONIC;
flipbip_play_long_bump(app);
//flipbip_play_long_bump(app);
} else if(status == FlipBipStatusLoadError) {
model->mnemonic = "ERROR:,Load error";
model->page = PAGE_MNEMONIC;
flipbip_play_long_bump(app);
//flipbip_play_long_bump(app);
} else if(status == FlipBipStatusMnemonicCheckError) {
model->mnemonic = "ERROR:,Mnemonic check error";
model->page = PAGE_MNEMONIC;
flipbip_play_long_bump(app);
//flipbip_play_long_bump(app);
}

// s_busy = false;
Expand Down

0 comments on commit 39c8dfe

Please sign in to comment.