Просмотр исходного кода

Add confirmation dialog before wallet regeneration

Alexande B 2 лет назад
Родитель
Сommit
d17600adf1
3 измененных файлов с 57 добавлено и 15 удалено
  1. 30 0
      flipbip.c
  2. 19 0
      flipbip.h
  3. 8 15
      scenes/flipbip_scene_menu.c

+ 30 - 0
flipbip.c

@@ -90,6 +90,23 @@ static void text_input_callback(void* context) {
     }
 }
 
+static void flipbip_scene_renew_dialog_callback(DialogExResult result, void* context) {
+    FlipBip* app = context;
+    if(result == DialogExResultRight) {
+        app->wallet_create(app);
+    } else {
+        view_dispatcher_switch_to_view(app->view_dispatcher, FlipBipViewIdMenu);
+    }
+}
+
+static void flipbip_wallet_create(void* context) {
+    FlipBip* app = context;
+    furi_assert(app);
+    scene_manager_set_scene_state(
+        app->scene_manager, FlipBipSceneMenu, SubmenuIndexScene1New);
+    scene_manager_next_scene(app->scene_manager, FlipBipSceneScene_1);
+}
+
 FlipBip* flipbip_app_alloc() {
     FlipBip* app = malloc(sizeof(FlipBip));
     app->gui = furi_record_open(RECORD_GUI);
@@ -148,6 +165,16 @@ FlipBip* flipbip_app_alloc() {
     view_dispatcher_add_view(
         app->view_dispatcher, FlipBipViewIdTextInput, text_input_get_view(app->text_input));
 
+    app->wallet_create = flipbip_wallet_create;
+    app->renew_dialog = dialog_ex_alloc();
+    dialog_ex_set_result_callback(app->renew_dialog, flipbip_scene_renew_dialog_callback);
+    dialog_ex_set_context(app->renew_dialog, app);
+    dialog_ex_set_left_button_text(app->renew_dialog, "No");
+    dialog_ex_set_right_button_text(app->renew_dialog, "Yes");
+    dialog_ex_set_header(app->renew_dialog, "Current wallet\nWill be lost.\nProceed?", 16, 12, AlignLeft, AlignTop);
+    view_dispatcher_add_view(
+        app->view_dispatcher, FlipBipViewRenewConfirm, dialog_ex_get_view(app->renew_dialog));
+
     // End Scene Additions
 
     return app;
@@ -168,6 +195,9 @@ void flipbip_app_free(FlipBip* app) {
     view_dispatcher_remove_view(app->view_dispatcher, FlipBipViewIdTextInput);
     submenu_free(app->submenu);
 
+    view_dispatcher_remove_view(app->view_dispatcher, FlipBipViewRenewConfirm);
+    dialog_ex_free(app->renew_dialog);
+
     view_dispatcher_free(app->view_dispatcher);
     furi_record_close(RECORD_GUI);
 

+ 19 - 0
flipbip.h

@@ -9,6 +9,7 @@
 #include <gui/view_dispatcher.h>
 #include <gui/modules/submenu.h>
 #include <gui/scene_manager.h>
+#include <gui/modules/dialog_ex.h>
 #include <gui/modules/variable_item_list.h>
 #include <gui/modules/text_input.h>
 #include "scenes/flipbip_scene.h"
@@ -23,6 +24,8 @@
 
 #define TEXT_BUFFER_SIZE 256
 
+
+
 typedef struct {
     Gui* gui;
     // NotificationApp* notification;
@@ -31,6 +34,7 @@ typedef struct {
     SceneManager* scene_manager;
     VariableItemList* variable_item_list;
     TextInput* text_input;
+    DialogEx* renew_dialog;
     FlipBipScene1* flipbip_scene_1;
     char* mnemonic_menu_text;
     // Settings options
@@ -45,6 +49,8 @@ typedef struct {
     char passphrase_text[TEXT_BUFFER_SIZE];
     char import_mnemonic_text[TEXT_BUFFER_SIZE];
     char input_text[TEXT_BUFFER_SIZE];
+
+    void (* wallet_create)(void* context);
 } FlipBip;
 
 typedef enum {
@@ -53,6 +59,7 @@ typedef enum {
     FlipBipViewIdScene1,
     FlipBipViewIdSettings,
     FlipBipViewIdTextInput,
+    FlipBipViewRenewConfirm,
 } FlipBipViewId;
 
 typedef enum {
@@ -86,3 +93,15 @@ typedef enum {
     FlipBipStatusSaveError = 12,
     FlipBipStatusMnemonicCheckError = 13,
 } FlipBipStatus;
+
+typedef enum {
+    SubmenuIndexScene1BTC = 10,
+    SubmenuIndexScene1ETH,
+    SubmenuIndexScene1DOGE,
+    SubmenuIndexScene1ZEC,
+    SubmenuIndexScene1New,
+    SubmenuIndexScene1Renew,
+    SubmenuIndexScene1Import,
+    SubmenuIndexSettings,
+    SubmenuIndexNOP,
+} SubmenuIndex;

+ 8 - 15
scenes/flipbip_scene_menu.c

@@ -3,18 +3,8 @@
 
 #define FLIPBIP_SUBMENU_TEXT "** FlipBIP wallet " FLIPBIP_VERSION " **"
 
-enum SubmenuIndex {
-    SubmenuIndexScene1BTC = 10,
-    SubmenuIndexScene1ETH,
-    SubmenuIndexScene1DOGE,
-    SubmenuIndexScene1ZEC,
-    SubmenuIndexScene1New,
-    SubmenuIndexScene1Import,
-    SubmenuIndexSettings,
-    SubmenuIndexNOP,
-};
-
 void flipbip_scene_menu_submenu_callback(void* context, uint32_t index) {
+    furi_assert(context);
     FlipBip* app = context;
     view_dispatcher_send_custom_event(app->view_dispatcher, index);
 }
@@ -59,7 +49,7 @@ void flipbip_scene_menu_on_enter(void* context) {
         submenu_add_item(
             app->submenu,
             "Regenerate wallet",
-            SubmenuIndexScene1New,
+            SubmenuIndexScene1Renew,
             flipbip_scene_menu_submenu_callback,
             app);
     } else {
@@ -130,9 +120,12 @@ bool flipbip_scene_menu_on_event(void* context, SceneManagerEvent event) {
         } else if(event.event == SubmenuIndexScene1New) {
             app->overwrite_saved_seed = 1;
             app->import_from_mnemonic = 0;
-            scene_manager_set_scene_state(
-                app->scene_manager, FlipBipSceneMenu, SubmenuIndexScene1New);
-            scene_manager_next_scene(app->scene_manager, FlipBipSceneScene_1);
+            app->wallet_create(app);
+            return true;
+        } else if(event.event == SubmenuIndexScene1Renew) {
+            app->overwrite_saved_seed = 1;
+            app->import_from_mnemonic = 0;
+            view_dispatcher_switch_to_view(app->view_dispatcher, FlipBipViewRenewConfirm);
             return true;
         } else if(event.event == SubmenuIndexScene1Import) {
             app->import_from_mnemonic = 1;