Skip to content

Commit 83fdbb0

Browse files
committed
[FIX] avoid error if all accounts are hidden
1 parent 8b41732 commit 83fdbb0

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

src/navigation/wallet/screens/AccountDetails.tsx

+20-20
Original file line numberDiff line numberDiff line change
@@ -378,22 +378,22 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
378378
const memorizedAccountList = useMemo(() => {
379379
return buildAccountList(key, defaultAltCurrency.isoCode, rates, dispatch, {
380380
filterByHideWallet: true,
381-
}).filter(({chains}) => IsEVMChain(chains[0]));
381+
}).filter(({chains}) => IsEVMChain(chains[0])) || {};
382382
}, [dispatch, key, defaultAltCurrency.isoCode, rates]);
383383

384384
const accountItem = memorizedAccountList.find(
385385
a => a.receiveAddress === selectedAccountAddress,
386386
)!;
387-
const totalBalance = accountItem.fiatBalanceFormat;
387+
const totalBalance = accountItem?.fiatBalanceFormat;
388388
const hasMultipleAccounts = memorizedAccountList.length > 1;
389389

390390
const accounts = useAppSelector(
391-
({SHOP}) => SHOP.billPayAccounts[accountItem.wallets[0].network],
391+
({SHOP}) => SHOP.billPayAccounts[accountItem?.wallets[0]?.network],
392392
);
393393

394394
const keyOptions: Array<Option> = [];
395395
const hasAllChains =
396-
accountItem.chains.length === Object.keys(BitpaySupportedEvmCoins).length;
396+
accountItem?.chains?.length === Object.keys(BitpaySupportedEvmCoins).length;
397397
if (!hasAllChains) {
398398
keyOptions.push({
399399
img: <Icons.Wallet width="15" height="15" />,
@@ -415,7 +415,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
415415
options: {
416416
network,
417417
password,
418-
account: accountItem.accountNumber,
418+
account: accountItem?.accountNumber,
419419
customAccount: true,
420420
},
421421
}),
@@ -438,7 +438,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
438438
await sleep(500);
439439
navigation.navigate('AccountSettings', {
440440
key,
441-
selectedAccountAddress: accountItem.receiveAddress,
441+
selectedAccountAddress: accountItem?.receiveAddress,
442442
context: 'accountDetails',
443443
});
444444
},
@@ -546,7 +546,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
546546
const updateWalletStatusAndProfileBalance = async () => {
547547
await startUpdateAllWalletStatusForKey({
548548
key,
549-
accountAddress: accountItem.receiveAddress,
549+
accountAddress: accountItem?.receiveAddress,
550550
force: true,
551551
});
552552
dispatch(updatePortfolioBalance);
@@ -615,7 +615,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
615615
if (memorizedAssetsByChainList?.[0].chains?.[0]) {
616616
navigation.navigate('AddCustomToken', {
617617
key,
618-
selectedAccountAddress: accountItem.receiveAddress,
618+
selectedAccountAddress: accountItem?.receiveAddress,
619619
selectedChain: memorizedAssetsByChainList[0].chains[0],
620620
});
621621
}
@@ -691,7 +691,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
691691
onPress={() =>
692692
navigation.navigate('AccountSettings', {
693693
key,
694-
selectedAccountAddress: accountItem.receiveAddress,
694+
selectedAccountAddress: accountItem?.receiveAddress,
695695
context: 'accountDetails',
696696
})
697697
}>
@@ -1039,7 +1039,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
10391039
? await debouncedLoadHistory(true)
10401040
: await startUpdateAllWalletStatusForKey({
10411041
key,
1042-
accountAddress: accountItem.receiveAddress,
1042+
accountAddress: accountItem?.receiveAddress,
10431043
force: true,
10441044
createTokenWalletWithFunds: true,
10451045
});
@@ -1080,7 +1080,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
10801080
const copyToClipboard = () => {
10811081
haptic('impactLight');
10821082
if (!copied) {
1083-
Clipboard.setString(accountItem.receiveAddress);
1083+
Clipboard.setString(accountItem?.receiveAddress);
10841084
setCopied(true);
10851085
}
10861086
};
@@ -1120,7 +1120,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
11201120
activeOpacity={ActiveOpacity}
11211121
style={{alignSelf: 'center', width: 'auto', height: 25}}>
11221122
<Badge style={{marginTop: 3}}>
1123-
{formatCryptoAddress(accountItem.receiveAddress)}
1123+
{formatCryptoAddress(accountItem?.receiveAddress)}
11241124
</Badge>
11251125
<CopyToClipboardContainer>
11261126
{!copied ? <CopySvg width={10} /> : <CopiedSvg width={10} />}
@@ -1182,12 +1182,12 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
11821182
cta: () => {
11831183
navigation.navigate('GlobalSelect', {
11841184
context: 'send',
1185-
selectedAccountAddress: accountItem.receiveAddress,
1185+
selectedAccountAddress: accountItem?.receiveAddress,
11861186
});
11871187
},
11881188
}}
11891189
/>
1190-
{Number(accountItem.fiatLockedBalanceFormat) > 0 ? (
1190+
{Number(accountItem?.fiatLockedBalanceFormat) > 0 ? (
11911191
<LockedBalanceContainer onPress={() => {}}>
11921192
<View>
11931193
<Description numberOfLines={1} ellipsizeMode={'tail'}>
@@ -1197,7 +1197,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
11971197

11981198
<TailContainer>
11991199
<Value>
1200-
{accountItem.fiatLockedBalanceFormat}{' '}
1200+
{accountItem?.fiatLockedBalanceFormat}{' '}
12011201
{formatCurrencyAbbreviation(
12021202
key.wallets[1].currencyAbbreviation,
12031203
)}
@@ -1325,11 +1325,11 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
13251325
<AccountDropdownOptionsContainer>
13261326
{Object.values(memorizedAccountList).map(_accountItem => (
13271327
<DropdownOption
1328-
key={_accountItem.id}
1329-
optionId={_accountItem.id}
1330-
optionName={_accountItem.accountName}
1331-
wallets={_accountItem.wallets}
1332-
totalBalance={_accountItem.fiatBalance}
1328+
key={_accountItem?.id}
1329+
optionId={_accountItem?.id}
1330+
optionName={_accountItem?.accountName}
1331+
wallets={_accountItem?.wallets}
1332+
totalBalance={_accountItem?.fiatBalance}
13331333
onPress={(accountId: string) => {
13341334
setShowAccountDropdown(false);
13351335
const selectedAccountItem = memorizedAccountList.find(

src/navigation/wallet/screens/AccountSettings.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ const AccountSettings = () => {
249249
accountToggleSelected: !hideAccount,
250250
}),
251251
);
252+
await sleep(1000);
252253
dispatch(
253254
startUpdateAllWalletStatusForKey({
254255
key,

src/store/wallet/utils/wallet.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ export const buildAssetsByChainList = (
13491349
) => {
13501350
const assetsByChainMap: {[key: string]: Partial<AssetsByChainListProps>} = {};
13511351

1352-
accountItem.wallets.forEach(coin => {
1352+
accountItem?.wallets?.forEach(coin => {
13531353
buildUIFormattedAssetsList(
13541354
assetsByChainMap,
13551355
coin,
@@ -1463,7 +1463,7 @@ export const buildAssetsByChain = (
14631463
) => {
14641464
const assetsByChainList: {[key: string]: AssetsByChainData} = {};
14651465

1466-
accountItem.wallets.forEach(coin => {
1466+
accountItem?.wallets?.forEach(coin => {
14671467
buildUIFormattedAssets(
14681468
assetsByChainList,
14691469
coin,

0 commit comments

Comments
 (0)