Skip to content

Commit

Permalink
break out mnemo draw
Browse files Browse the repository at this point in the history
  • Loading branch information
xtruan committed Mar 3, 2023
1 parent 602c987 commit 7bb88e9
Showing 1 changed file with 43 additions and 41 deletions.
84 changes: 43 additions & 41 deletions views/flipbip_scene_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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];
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 7bb88e9

Please sign in to comment.