Skip to content

Commit 7bb88e9

Browse files
committed
break out mnemo draw
1 parent 602c987 commit 7bb88e9

File tree

1 file changed

+43
-41
lines changed

1 file changed

+43
-41
lines changed

views/flipbip_scene_1.c

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,46 @@ void flipbip_scene_1_set_callback(
6262
instance->context = context;
6363
}
6464

65+
static void flipbip_scene_1_draw_mnemonic(FlipBipScene1Model* const model) {
66+
67+
// Delineate sections of the mnemonic every 4 words
68+
char *mnemonic_working = malloc(strlen(model->mnemonic) + 1);
69+
strcpy(mnemonic_working, model->mnemonic);
70+
int word = 0;
71+
for (size_t i = 0; i < strlen(mnemonic_working); i++) {
72+
if (mnemonic_working[i] == ' ') {
73+
word++;
74+
if (word % 4 == 0) {
75+
mnemonic_working[i] = ',';
76+
}
77+
}
78+
}
79+
80+
// Split the mnemonic into parts
81+
char *mnemonic_part = flipbip_strtok(mnemonic_working, ",");
82+
int mi = 0;
83+
while(mnemonic_part != NULL)
84+
{
85+
char *ptr = malloc(strlen(mnemonic_part) + 1);
86+
strcpy(ptr, mnemonic_part);
87+
mi++;
88+
89+
if (mi == 1) model->mnemonic1 = ptr;
90+
else if (mi == 2) model->mnemonic2 = ptr;
91+
else if (mi == 3) model->mnemonic3 = ptr;
92+
else if (mi == 4) model->mnemonic4 = ptr;
93+
else if (mi == 5) model->mnemonic5 = ptr;
94+
else if (mi == 6) model->mnemonic6 = ptr;
95+
96+
mnemonic_part = flipbip_strtok(NULL, ",");
97+
}
98+
99+
// Free the working mnemonic memory
100+
memzero(mnemonic_working, strlen(mnemonic_working));
101+
free(mnemonic_working);
102+
103+
}
104+
65105
void flipbip_scene_1_draw(Canvas* canvas, FlipBipScene1Model* model) {
66106
//UNUSED(model);
67107
canvas_clear(canvas);
@@ -83,7 +123,7 @@ void flipbip_scene_1_draw(Canvas* canvas, FlipBipScene1Model* model) {
83123
canvas_draw_str_aligned(canvas, 1, 52, AlignLeft, AlignTop, model->mnemonic6);
84124
}
85125
// Seed
86-
else if (model->page == 1) {
126+
else {
87127
canvas_draw_str_aligned(canvas, 1, 2, AlignLeft, AlignTop, model->seed1);
88128
canvas_draw_str_aligned(canvas, 1, 12, AlignLeft, AlignTop, model->seed2);
89129
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
104144
//const char *mnemonic = mnemonic_generate(model->strength);
105145
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";
106146

107-
// START DRAW MNEMONIC
108-
109-
// Delineate sections of the mnemonic every 4 words
110-
char *mnemonic_working = malloc(strlen(model->mnemonic) + 1);
111-
strcpy(mnemonic_working, model->mnemonic);
112-
int word = 0;
113-
for (size_t i = 0; i < strlen(mnemonic_working); i++) {
114-
if (mnemonic_working[i] == ' ') {
115-
word++;
116-
if (word % 4 == 0) {
117-
mnemonic_working[i] = ',';
118-
}
119-
}
120-
}
121-
122-
// Split the mnemonic into parts
123-
char *mnemonic_part = flipbip_strtok(mnemonic_working, ",");
124-
int mi = 0;
125-
while(mnemonic_part != NULL)
126-
{
127-
char *ptr = malloc(strlen(mnemonic_part) + 1);
128-
strcpy(ptr, mnemonic_part);
129-
mi++;
130-
131-
if (mi == 1) model->mnemonic1 = ptr;
132-
else if (mi == 2) model->mnemonic2 = ptr;
133-
else if (mi == 3) model->mnemonic3 = ptr;
134-
else if (mi == 4) model->mnemonic4 = ptr;
135-
else if (mi == 5) model->mnemonic5 = ptr;
136-
else if (mi == 6) model->mnemonic6 = ptr;
137-
138-
mnemonic_part = flipbip_strtok(NULL, ",");
139-
}
140-
141-
// Free the working mnemonic memory
142-
memzero(mnemonic_working, strlen(mnemonic_working));
143-
free(mnemonic_working);
144-
145-
// END DRAW MNEMONIC
147+
flipbip_scene_1_draw_mnemonic(model);
146148

147149
// Generate a BIP39 seed from the mnemonic
148150
//uint8_t seedbytes[64];
@@ -176,7 +178,7 @@ static void flipbip_scene_1_model_init(FlipBipScene1Model* const model, const in
176178

177179
// END DRAW SEED
178180

179-
// WIP / TODO: Generate a BIP32 root key from the mnemonic
181+
// Generate a BIP32 root key from the mnemonic
180182

181183
// //bool root_set = false;
182184
HDNode *root = malloc(sizeof(HDNode));

0 commit comments

Comments
 (0)