From 650598ee2033944e348894444de12e90f714ee1d Mon Sep 17 00:00:00 2001 From: tomasklim Date: Thu, 8 Aug 2024 14:48:04 +0200 Subject: [PATCH] fix(wallet-core): missing cardano active coins button --- .../wallet-config/src/networksConfig.ts | 2 +- .../src/discovery/discoveryThunks.ts | 33 +++++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/suite-common/wallet-config/src/networksConfig.ts b/suite-common/wallet-config/src/networksConfig.ts index 53b604df5ca..b2b7dfe06cd 100644 --- a/suite-common/wallet-config/src/networksConfig.ts +++ b/suite-common/wallet-config/src/networksConfig.ts @@ -296,7 +296,7 @@ export const networks = { customBackends: ['blockfrost'], accountTypes: { legacy: { - // icarus-trezor derivation + // icarus-trezor derivation, differs from default just for 24 words seed bip43Path: "m/1852'/1815'/i'", }, ledger: { diff --git a/suite-common/wallet-core/src/discovery/discoveryThunks.ts b/suite-common/wallet-core/src/discovery/discoveryThunks.ts index 237c18ab756..978c8568793 100644 --- a/suite-common/wallet-core/src/discovery/discoveryThunks.ts +++ b/suite-common/wallet-core/src/discovery/discoveryThunks.ts @@ -63,22 +63,35 @@ export const filterUnavailableNetworks = ( const calculateProgress = (discovery: Discovery) => (_dispatch: any, getState: any): PartialDiscovery => { - const numberOfNonCardano = discovery.networks.filter(s => s !== 'ada').length; + const { numberOfNonCardano, numberOfCardano } = discovery.networks.reduce( + (acc, symbol) => { + if (symbol === 'ada') { + acc.numberOfCardano += 1; + } else { + acc.numberOfNonCardano += 1; + } + + return acc; + }, + { numberOfNonCardano: 0, numberOfCardano: 0 }, + ); - // This is ugly hack, but it works in both scenarios: + // This approach handles both scenarios effectively: // - // 1) We some `discovery.networks` (we added Cardano), but only some are allowed, - // the `availableCardanoDerivations` < discovery.networks(===ada).length` so it works + // 1) Cardano added - When Cardano is included, discovery.availableCardanoDerivations may vary (2 to 3 based on device seed length). + // This object might be undefined if discovery hasn't been completed yet. + // To ensure the "activate coins" button appears, we set it to 1 if Cardano is enabled. // - // 2) When we remove Cardano, the `availableCardanoDerivations` keeps some stuff, - // but because `discovery.networks(===ada).length` becomes 0 it works + // 2) Cardano removed - When Cardano is removed, discovery.availableCardanoDerivations might still hold a value. + // However, due to Math.min, it correctly resolves to 0 since numberOfCardano is 0. // - const numberOfCardano = Math.min( - discovery.availableCardanoDerivations?.length ?? 0, - discovery.networks.filter(s => s === 'ada').length, + + const numberOfCardanoTotal = Math.min( + discovery.availableCardanoDerivations?.length ?? numberOfCardano ? 1 : 0, + numberOfCardano, ); - let total = LIMIT * (numberOfNonCardano + numberOfCardano); + let total = LIMIT * (numberOfNonCardano + numberOfCardanoTotal); let loaded = 0; const accounts = selectAccounts(getState());