Skip to content

Commit

Permalink
overwrite boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
xtruan committed Mar 7, 2023
1 parent 5d626b8 commit 1a7b0db
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions flipbip.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ FlipBip* flipbip_app_alloc() {
app->led = 1;
app->bip39_strength = 2; // 256 bits (24 words)
app->bip44_coin = 0; // 0 (BTC)
app->overwrite_saved_seed = 0;

view_dispatcher_add_view(app->view_dispatcher, FlipBipViewIdMenu, submenu_get_view(app->submenu));
app->flipbip_startscreen = flipbip_startscreen_alloc();
Expand Down
1 change: 1 addition & 0 deletions flipbip.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ typedef struct {
int led;
int bip39_strength;
int bip44_coin;
int overwrite_saved_seed;
} FlipBip;

typedef enum {
Expand Down
11 changes: 7 additions & 4 deletions views/flipbip_scene_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void flipbip_scene_1_draw(Canvas* canvas, FlipBipScene1Model* model) {

}

static void flipbip_scene_1_model_init(FlipBipScene1Model* const model, const int strength, const uint32_t coin) {
static void flipbip_scene_1_model_init(FlipBipScene1Model* const model, const int strength, const uint32_t coin, const bool overwrite) {

model->page = 0;
model->coin = coin;
Expand All @@ -273,8 +273,8 @@ static void flipbip_scene_1_model_init(FlipBipScene1Model* const model, const in
char* mnemonic = malloc(256);
memzero(mnemonic, 256);

// Check if the mnemonic key & data is already saved in persistent storage
if (!flipbip_has_settings(true) && !flipbip_has_settings(false)) {
// Check if the mnemonic key & data is already saved in persistent storage, or overwrite is true
if (overwrite || (!flipbip_has_settings(true) && !flipbip_has_settings(false))) {
// Generate a random mnemonic using trezor-crypto
const char* mnemonic_gen = mnemonic_generate(strength);
// Save the mnemonic to persistent storage
Expand Down Expand Up @@ -476,14 +476,17 @@ void flipbip_scene_1_enter(void* context) {
uint32_t coin = 0; //FlipBipCoinBTC0 // BTC (0)
if (coin_setting == FlipBipCoinETH60) coin = 60; // ETH (60)

// Overwrite the saved seed with a new one setting
bool overwrite = app->overwrite_saved_seed != 0;

flipbip_play_happy_bump(app);
flipbip_led_set_rgb(app, 255, 0, 0);

with_view_model(
instance->view,
FlipBipScene1Model * model,
{
flipbip_scene_1_model_init(model, strength, coin);
flipbip_scene_1_model_init(model, strength, coin, overwrite);
},
true
);
Expand Down

0 comments on commit 1a7b0db

Please sign in to comment.