Skip to content

Commit

Permalink
fix(core): Updated factory reset wallet checks condition
Browse files Browse the repository at this point in the history
  • Loading branch information
amanCypherock committed Dec 6, 2023
1 parent 9c51e90 commit 7218538
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/card_flows/card_flow_delete_wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ card_error_type_e card_flow_delete_wallet(Wallet *selected_wallet) {
if (CARD_OPERATION_SUCCESS != error_code) {
if (CARD_OPERATION_ABORT_OPERATION == error_code &&
SW_RECORD_NOT_FOUND == response.card_info.status) {
// In case wallet is not found on card, consider it as a success case as
// wallet is already deleted or not created on the card.
clear_core_error_screen();
} else {
break;
Expand Down
4 changes: 2 additions & 2 deletions src/settings/factory_reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ static bool safe_to_delete_wallet_share(wallet_list_t *wallets_in_vault) {
*****************************************************************************/
void factory_reset(void) {
wallet_list_t wallets_in_vault = {0};
uint8_t valid_wallets = get_valid_wallet_meta_data_list(&wallets_in_vault);
uint8_t valid_wallets = get_filled_wallet_meta_data_list(&wallets_in_vault);

if (0 < valid_wallets &&
!core_scroll_page(NULL, ui_text_factory_reset_instruction, NULL)) {
Expand Down Expand Up @@ -329,7 +329,7 @@ void factory_reset(void) {

void clear_device_data(void) {
wallet_list_t wallets_in_vault = {0};
uint8_t valid_wallets = get_valid_wallet_meta_data_list(&wallets_in_vault);
uint8_t valid_wallets = get_filled_wallet_meta_data_list(&wallets_in_vault);

if (0 < valid_wallets &&
!core_scroll_page(NULL, ui_text_clear_device_data_instruction, NULL)) {
Expand Down
5 changes: 3 additions & 2 deletions src/wallet/wallet_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,16 @@ uint8_t get_wallet_list(const char *wallet_list[]) {
return num_wallets;
}

uint8_t get_valid_wallet_meta_data_list(wallet_list_t *list) {
uint8_t get_filled_wallet_meta_data_list(wallet_list_t *list) {
uint8_t count = 0;
if (NULL == list) {
return count;
}

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 != state) {
if (!wallet_is_filled(wallet_idx, &state) ||
VALID_WALLET_WITHOUT_DEVICE_SHARE == state) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions src/wallet/wallet_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ uint8_t get_wallet_list(const char *wallet_list[]);

/**
* @brief This API fills metadata for all the wallets present on X1 vault and
* are in VALID_WALLET state.
* are not in VALID_WALLET_WITHOUT_DEVICE_SHARE state.
*
* @param wallet_list Refernce to buffer which will be filled by this function
* @return uint8_t The number of wallets returned
*/
uint8_t get_valid_wallet_meta_data_list(wallet_list_t *wallet_list);
uint8_t get_filled_wallet_meta_data_list(wallet_list_t *wallet_list);

/**
* @brief This API searches for wallet on the flash using wallet_id as key and
Expand Down

0 comments on commit 7218538

Please sign in to comment.