Quellcode durchsuchen

break out mnemo draw

Struan Clark vor 2 Jahren
Ursprung
Commit
7bb88e945d
1 geänderte Dateien mit 43 neuen und 41 gelöschten Zeilen
  1. 43 41
      views/flipbip_scene_1.c

+ 43 - 41
views/flipbip_scene_1.c

@@ -62,6 +62,46 @@ void flipbip_scene_1_set_callback(
     instance->context = context;
 }
 
+static void flipbip_scene_1_draw_mnemonic(FlipBipScene1Model* const model) {
+
+    // Delineate sections of the mnemonic every 4 words
+    char *mnemonic_working = malloc(strlen(model->mnemonic) + 1);
+    strcpy(mnemonic_working, model->mnemonic);
+    int word = 0;
+    for (size_t i = 0; i < strlen(mnemonic_working); i++) {
+        if (mnemonic_working[i] == ' ') {
+            word++;
+            if (word % 4 == 0) {
+                mnemonic_working[i] = ',';
+            }
+        } 
+    }
+
+    // Split the mnemonic into parts
+    char *mnemonic_part = flipbip_strtok(mnemonic_working, ",");
+    int mi = 0;
+    while(mnemonic_part != NULL)
+    {
+        char *ptr = malloc(strlen(mnemonic_part) + 1);
+        strcpy(ptr, mnemonic_part);
+        mi++;
+        
+        if      (mi == 1) model->mnemonic1 = ptr;
+        else if (mi == 2) model->mnemonic2 = ptr;
+        else if (mi == 3) model->mnemonic3 = ptr;
+        else if (mi == 4) model->mnemonic4 = ptr;
+        else if (mi == 5) model->mnemonic5 = ptr;
+        else if (mi == 6) model->mnemonic6 = ptr;
+
+        mnemonic_part = flipbip_strtok(NULL, ",");
+    }
+
+    // Free the working mnemonic memory
+    memzero(mnemonic_working, strlen(mnemonic_working));
+    free(mnemonic_working);
+
+}
+
 void flipbip_scene_1_draw(Canvas* canvas, FlipBipScene1Model* model) {
     //UNUSED(model);
     canvas_clear(canvas);
@@ -83,7 +123,7 @@ void flipbip_scene_1_draw(Canvas* canvas, FlipBipScene1Model* model) {
         canvas_draw_str_aligned(canvas, 1, 52, AlignLeft, AlignTop, model->mnemonic6);
     }
     // Seed
-    else if (model->page == 1) {
+    else {
         canvas_draw_str_aligned(canvas, 1, 2, AlignLeft, AlignTop, model->seed1);
         canvas_draw_str_aligned(canvas, 1, 12, AlignLeft, AlignTop, model->seed2);
         canvas_draw_str_aligned(canvas, 1, 22, AlignLeft, AlignTop, model->seed3);
@@ -104,45 +144,7 @@ static void flipbip_scene_1_model_init(FlipBipScene1Model* const model, const in
     //const char *mnemonic = mnemonic_generate(model->strength);
     model->mnemonic = "wealth budget salt video delay obey neutral tail sure soda hold rubber joy movie boat raccoon tornado noise off inmate payment patch group topple";
 
-    // START DRAW MNEMONIC
-
-    // Delineate sections of the mnemonic every 4 words
-    char *mnemonic_working = malloc(strlen(model->mnemonic) + 1);
-    strcpy(mnemonic_working, model->mnemonic);
-    int word = 0;
-    for (size_t i = 0; i < strlen(mnemonic_working); i++) {
-        if (mnemonic_working[i] == ' ') {
-            word++;
-            if (word % 4 == 0) {
-                mnemonic_working[i] = ',';
-            }
-        } 
-    }
-
-    // Split the mnemonic into parts
-    char *mnemonic_part = flipbip_strtok(mnemonic_working, ",");
-    int mi = 0;
-    while(mnemonic_part != NULL)
-    {
-        char *ptr = malloc(strlen(mnemonic_part) + 1);
-        strcpy(ptr, mnemonic_part);
-        mi++;
-        
-        if      (mi == 1) model->mnemonic1 = ptr;
-        else if (mi == 2) model->mnemonic2 = ptr;
-        else if (mi == 3) model->mnemonic3 = ptr;
-        else if (mi == 4) model->mnemonic4 = ptr;
-        else if (mi == 5) model->mnemonic5 = ptr;
-        else if (mi == 6) model->mnemonic6 = ptr;
-
-        mnemonic_part = flipbip_strtok(NULL, ",");
-    }
-
-    // Free the working mnemonic memory
-    memzero(mnemonic_working, strlen(mnemonic_working));
-    free(mnemonic_working);
-
-    // END DRAW MNEMONIC
+    flipbip_scene_1_draw_mnemonic(model);
 
     // Generate a BIP39 seed from the mnemonic
     //uint8_t seedbytes[64];
@@ -176,7 +178,7 @@ static void flipbip_scene_1_model_init(FlipBipScene1Model* const model, const in
 
     // END DRAW SEED
 
-    // WIP / TODO: Generate a BIP32 root key from the mnemonic
+    // Generate a BIP32 root key from the mnemonic
 
     // //bool root_set = false;
     HDNode *root = malloc(sizeof(HDNode));