Skip to content

Commit

Permalink
fix(wallet-core): missing cardano active coins button
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasklim committed Aug 14, 2024
1 parent 4d39c4c commit 650598e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion suite-common/wallet-config/src/networksConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
33 changes: 23 additions & 10 deletions suite-common/wallet-core/src/discovery/discoveryThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 650598e

Please sign in to comment.