Explorar el Código

fix: remove haptic, add mnemonic import status text

Struan Clark hace 2 años
padre
commit
39c8dfe480

+ 18 - 9
flipbip.c

@@ -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;
@@ -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);
@@ -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);
@@ -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);
         }
     }
 
@@ -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();
@@ -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;
@@ -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));

+ 3 - 2
flipbip.h

@@ -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>
@@ -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;

+ 0 - 35
helpers/flipbip_haptic.c

@@ -1,35 +0,0 @@
-#include "flipbip_haptic.h"
-#include "../flipbip.h"
-
-void flipbip_play_happy_bump(void* context) {
-    FlipBip* app = context;
-    if(app->haptic != 1) {
-        return;
-    }
-    notification_message(app->notification, &sequence_set_vibro_on);
-    furi_thread_flags_wait(0, FuriFlagWaitAny, 20);
-    notification_message(app->notification, &sequence_reset_vibro);
-}
-
-void flipbip_play_bad_bump(void* context) {
-    FlipBip* app = context;
-    if(app->haptic != 1) {
-        return;
-    }
-    notification_message(app->notification, &sequence_set_vibro_on);
-    furi_thread_flags_wait(0, FuriFlagWaitAny, 100);
-    notification_message(app->notification, &sequence_reset_vibro);
-}
-
-void flipbip_play_long_bump(void* context) {
-    FlipBip* app = context;
-    if(app->haptic != 1) {
-        return;
-    }
-    for(int i = 0; i < 4; i++) {
-        notification_message(app->notification, &sequence_set_vibro_on);
-        furi_thread_flags_wait(0, FuriFlagWaitAny, 50);
-        notification_message(app->notification, &sequence_reset_vibro);
-        furi_thread_flags_wait(0, FuriFlagWaitAny, 100);
-    }
-}

+ 0 - 7
helpers/flipbip_haptic.h

@@ -1,7 +0,0 @@
-#include <notification/notification_messages.h>
-
-void flipbip_play_happy_bump(void* context);
-
-void flipbip_play_bad_bump(void* context);
-
-void flipbip_play_long_bump(void* context);

+ 6 - 3
scenes/flipbip_scene_menu.c

@@ -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);
@@ -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(

+ 20 - 11
scenes/flipbip_scene_scene_1.c

@@ -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) {
@@ -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);

+ 11 - 7
views/flipbip_scene_1.c

@@ -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
@@ -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);
 
@@ -678,7 +681,8 @@ 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);
             }
 
@@ -686,15 +690,15 @@ void flipbip_scene_1_enter(void* context) {
             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;