@@ -314,22 +314,24 @@ static int flipbip_scene_1_model_init(
314314 if (overwrite || (!flipbip_has_settings (true) && !flipbip_has_settings (false))) {
315315 // Generate a random mnemonic using trezor-crypto
316316 const char * mnemonic_gen = mnemonic_generate (strength );
317+ // Check if the mnemonic is valid
318+ if (mnemonic_check (mnemonic_gen ) == 0 ) return FlipBipStatusMnemonicCheckError ; // 13 = mnemonic check error
317319 // Save the mnemonic to persistent storage
318- if (!flipbip_save_settings_secure (mnemonic_gen )) return 1 ; // 1 = save error
320+ else if (!flipbip_save_settings_secure (mnemonic_gen )) return FlipBipStatusSaveError ; // 12 = save error
319321 // Clear the generated mnemonic from memory
320322 mnemonic_clear ();
321323 model -> mnemonic_only = true;
322324 }
323325
324326 // Load the mnemonic from persistent storage
325- if (!flipbip_load_settings_secure (mnemonic )) return 2 ; // 2 = load error
327+ if (!flipbip_load_settings_secure (mnemonic )) return FlipBipStatusLoadError ; // 11 = load error
326328 model -> mnemonic = mnemonic ;
327329 // Check if the mnemonic is valid
328- if (mnemonic_check (model -> mnemonic ) == 0 ) return 3 ; // 3 = mnemonic check error
330+ if (mnemonic_check (model -> mnemonic ) == 0 ) return FlipBipStatusMnemonicCheckError ; // 13 = mnemonic check error
329331
330332 // if we are only generating the mnemonic, return
331333 if (model -> mnemonic_only ) {
332- return -1 ; // -1 = mnemonic only, return from parent
334+ return FlipBipStatusReturn ; // 10 = mnemonic only, return from parent
333335 }
334336
335337 // test mnemonic
@@ -408,7 +410,7 @@ static int flipbip_scene_1_model_init(
408410#endif
409411
410412 // 0 = success
411- return 0 ;
413+ return FlipBipStatusSuccess ;
412414}
413415
414416bool flipbip_scene_1_input (InputEvent * event , void * context ) {
@@ -524,7 +526,7 @@ void flipbip_scene_1_enter(void* context) {
524526 }
525527
526528 // BIP44 Coin setting
527- uint32_t coin = app -> bip44_coin ;
529+ const uint32_t coin = app -> bip44_coin ;
528530 // coin_name, derivation_path
529531 s_derivation_text = COIN_TEXT_ARRAY [coin ][1 ];
530532
@@ -543,31 +545,38 @@ void flipbip_scene_1_enter(void* context) {
543545 {
544546 // s_busy = true;
545547
546- const int status =
547- flipbip_scene_1_model_init (model , strength , coin , overwrite , passphrase_text );
548+ const int status = flipbip_scene_1_model_init (
549+ model ,
550+ strength ,
551+ coin ,
552+ overwrite ,
553+ passphrase_text );
548554
549555 // nonzero status, free the mnemonic
550- if (status != 0 ) {
556+ if (status != FlipBipStatusSuccess ) {
551557 memzero ((void * )model -> mnemonic , strlen (model -> mnemonic ));
552558 free ((void * )model -> mnemonic );
553559 }
554560
555561 // if error, set the error message
556- if (status == 1 ) {
562+ if (status == FlipBipStatusSaveError ) {
557563 model -> mnemonic = "ERROR:,Save error" ;
558564 model -> page = 2 ;
559- } else if (status == 2 ) {
565+ flipbip_play_long_bump (app );
566+ } else if (status == FlipBipStatusLoadError ) {
560567 model -> mnemonic = "ERROR:,Load error" ;
561568 model -> page = 2 ;
562- } else if (status == 3 ) {
569+ flipbip_play_long_bump (app );
570+ } else if (status == FlipBipStatusMnemonicCheckError ) {
563571 model -> mnemonic = "ERROR:,Mnemonic check failed" ;
564572 model -> page = 2 ;
573+ flipbip_play_long_bump (app );
565574 }
566575
567576 // s_busy = false;
568577
569578 // if overwrite is set and mnemonic generated, return from scene immediately
570- if (status == -1 ) {
579+ if (status == FlipBipStatusReturn ) {
571580 instance -> callback (FlipBipCustomEventScene1Back , instance -> context );
572581 }
573582 },
0 commit comments