Skip to content

Commit

Permalink
fix(wallet-core): do not show first normal account by default in suit…
Browse files Browse the repository at this point in the history
…e-native
  • Loading branch information
matejkriz committed May 31, 2024
1 parent c51bad1 commit 3caaef4
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ export const createCoinjoinAccount =
descriptor: publicKey.payload.xpubSegwit || publicKey.payload.xpub,
legacyXpub: publicKey.payload.xpub,
},
visible: true,
}),
);

Expand Down
17 changes: 12 additions & 5 deletions suite-common/wallet-core/src/accounts/accountsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type CreateAccountActionProps = {
accountInfo: AccountInfo;
imported?: boolean;
accountLabel?: string;
visible: boolean;
};

type CreateIndexLabeledAccountActionProps = Omit<
Expand All @@ -48,6 +49,7 @@ const composeCreateAccountActionPayload = ({
accountInfo,
imported,
accountLabel,
visible,
}: CreateAccountActionProps): Account => ({
deviceState,
accountLabel,
Expand All @@ -69,10 +71,7 @@ const composeCreateAccountActionPayload = ({
: {
backendType: discoveryItem.backendType,
}),
visible:
!accountInfo.empty ||
discoveryItem.accountType === 'coinjoin' ||
(discoveryItem.accountType === 'normal' && discoveryItem.index === 0),
visible,
balance: accountInfo.balance,
availableBalance: accountInfo.availableBalance,
formattedBalance: formatNetworkAmount(
Expand All @@ -96,8 +95,14 @@ const createIndexLabeledAccount = createAction(
deviceState,
discoveryItem,
accountInfo,
visible,
}: CreateIndexLabeledAccountActionProps): { payload: Account } => ({
payload: composeCreateAccountActionPayload({ deviceState, discoveryItem, accountInfo }),
payload: composeCreateAccountActionPayload({
deviceState,
discoveryItem,
accountInfo,
visible,
}),
}),
);

Expand All @@ -109,13 +114,15 @@ const createAccount = createAction(
accountInfo,
imported,
accountLabel,
visible,
}: CreateAccountActionProps): { payload: Account } => ({
payload: composeCreateAccountActionPayload({
deviceState,
discoveryItem,
accountInfo,
imported,
accountLabel,
visible,
}),
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('Account Reducer', () => {
unconfirmed: 0,
},
},
visible: true,
}),
);
expect(store.getState().wallet.accounts.length).toEqual(1);
Expand Down
2 changes: 2 additions & 0 deletions suite-common/wallet-core/src/discovery/discoveryThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ const handleProgressThunk = createThunk(
deviceState,
discoveryItem: item,
accountInfo: response,
// first normal account is always visible on web & desktop (but not in suite-native)
visible: (item.accountType === 'normal' && item.index === 0) || !response.empty,
}),
);
}
Expand Down
4 changes: 2 additions & 2 deletions suite-native/assets/src/assetsSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
AccountsRootState,
DeviceRootState,
FiatRatesRootState,
selectDeviceAccounts,
selectVisibleDeviceAccounts,
selectFiatRatesByFiatRateKey,
} from '@suite-common/wallet-core';
import { getFiatRateKey, toFiatCurrency } from '@suite-common/wallet-utils';
Expand All @@ -29,7 +29,7 @@ const sumBalance = (balances: string[]): BigNumber =>

export const selectDeviceBalancesPerNetwork = memoize(
(state: AssetsRootState & DeviceRootState): FormattedAssets => {
const accounts = selectDeviceAccounts(state);
const accounts = selectVisibleDeviceAccounts(state);

const assets: Assets = {};
accounts.forEach(account => {
Expand Down
2 changes: 2 additions & 0 deletions suite-native/discovery/src/discoveryThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ const addAccountByDescriptorThunk = createThunk(
discoveryItem: bundleItem,
deviceState,
accountInfo,
visible: true,
}),
);

Expand Down Expand Up @@ -262,6 +263,7 @@ const discoverAccountsByDescriptorThunk = createThunk(
discoveryItem: bundleItem,
deviceState,
accountInfo,
visible: !accountInfo.empty,
}),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const importAccountThunk = createThunk(
accountInfo,
imported,
accountLabel,
visible: true,
}),
);
}
Expand Down

0 comments on commit 3caaef4

Please sign in to comment.