diff --git a/common/interfaces/flash_interface/flash_api.c b/common/interfaces/flash_interface/flash_api.c index 072103f64..9018237ea 100644 --- a/common/interfaces/flash_interface/flash_api.c +++ b/common/interfaces/flash_interface/flash_api.c @@ -117,6 +117,29 @@ bool wallet_is_filled(uint8_t index, wallet_state *state_output) { return false; } +bool wallet_is_filled_with_share(uint8_t index) { + if (MAX_WALLETS_ALLOWED <= index) { + return false; + } + + /* Make sure that we always work on the latest RAM instance */ + get_flash_ram_instance(); + + wallet_state state = flash_ram_instance.wallets[index].state; + // Read card states without write attempt state + uint8_t cards_states = flash_ram_instance.wallets[index].cards_states & 0x0F; + + // If wallet state state is where share is present on device and card state is + // not zero, then wallet is filled + if (((UNVERIFIED_VALID_WALLET == state) || (VALID_WALLET == state) || + (INVALID_WALLET == state)) && + (0x00 != cards_states)) { + return true; + } + + return false; +} + /** * @brief Save a new wallet on the flash * diff --git a/common/interfaces/flash_interface/flash_api.h b/common/interfaces/flash_interface/flash_api.h index 79487d663..ab135dc71 100644 --- a/common/interfaces/flash_interface/flash_api.h +++ b/common/interfaces/flash_interface/flash_api.h @@ -36,6 +36,17 @@ */ bool wallet_is_filled(uint8_t index, wallet_state *state_output); +/** + * @brief The function checks if a wallet is filled with a share based on its + * index. + * + * @param index The index required to be checked for wallet existance + * + * @return a boolean value. It returns true if the wallet at the given index is + * filled with a share, and false otherwise. + */ +bool wallet_is_filled_with_share(uint8_t index); + /** * Update auth state and first_boot_on_update variables in firewall */ diff --git a/src/card_flows/card_flow_delete_wallet.c b/src/card_flows/card_flow_delete_wallet.c index 1082fb7c6..a2c502432 100644 --- a/src/card_flows/card_flow_delete_wallet.c +++ b/src/card_flows/card_flow_delete_wallet.c @@ -239,7 +239,6 @@ card_error_type_e card_flow_delete_wallet(Wallet *selected_wallet) { // If wallet is deleted on all cards, delete from flash as well check_card_state_and_delete_wallet( (const char *)delete_cfg.wallet->wallet_name); - clear_wallet_data(); return error_code; } \ No newline at end of file diff --git a/src/wallet/wallet_list.c b/src/wallet/wallet_list.c index 09936552f..0a7237637 100644 --- a/src/wallet/wallet_list.c +++ b/src/wallet/wallet_list.c @@ -125,9 +125,7 @@ uint8_t get_filled_wallet_meta_data_list(wallet_list_t *list) { } for (uint8_t wallet_idx = 0; wallet_idx < MAX_WALLETS_ALLOWED; wallet_idx++) { - wallet_state state = INVALID_WALLET; - if (!wallet_is_filled(wallet_idx, &state) || - VALID_WALLET_WITHOUT_DEVICE_SHARE == state) { + if (!wallet_is_filled_with_share(wallet_idx)) { continue; }