Skip to content

Commit

Permalink
[FIX] avoid error if all accounts are hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbazan7 committed Jan 20, 2025
1 parent 8b41732 commit 83fdbb0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
40 changes: 20 additions & 20 deletions src/navigation/wallet/screens/AccountDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -378,22 +378,22 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
const memorizedAccountList = useMemo(() => {
return buildAccountList(key, defaultAltCurrency.isoCode, rates, dispatch, {
filterByHideWallet: true,
}).filter(({chains}) => IsEVMChain(chains[0]));
}).filter(({chains}) => IsEVMChain(chains[0])) || {};
}, [dispatch, key, defaultAltCurrency.isoCode, rates]);

const accountItem = memorizedAccountList.find(
a => a.receiveAddress === selectedAccountAddress,
)!;
const totalBalance = accountItem.fiatBalanceFormat;
const totalBalance = accountItem?.fiatBalanceFormat;
const hasMultipleAccounts = memorizedAccountList.length > 1;

const accounts = useAppSelector(
({SHOP}) => SHOP.billPayAccounts[accountItem.wallets[0].network],
({SHOP}) => SHOP.billPayAccounts[accountItem?.wallets[0]?.network],
);

const keyOptions: Array<Option> = [];
const hasAllChains =
accountItem.chains.length === Object.keys(BitpaySupportedEvmCoins).length;
accountItem?.chains?.length === Object.keys(BitpaySupportedEvmCoins).length;
if (!hasAllChains) {
keyOptions.push({
img: <Icons.Wallet width="15" height="15" />,
Expand All @@ -415,7 +415,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
options: {
network,
password,
account: accountItem.accountNumber,
account: accountItem?.accountNumber,
customAccount: true,
},
}),
Expand All @@ -438,7 +438,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
await sleep(500);
navigation.navigate('AccountSettings', {
key,
selectedAccountAddress: accountItem.receiveAddress,
selectedAccountAddress: accountItem?.receiveAddress,
context: 'accountDetails',
});
},
Expand Down Expand Up @@ -546,7 +546,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
const updateWalletStatusAndProfileBalance = async () => {
await startUpdateAllWalletStatusForKey({
key,
accountAddress: accountItem.receiveAddress,
accountAddress: accountItem?.receiveAddress,
force: true,
});
dispatch(updatePortfolioBalance);
Expand Down Expand Up @@ -615,7 +615,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
if (memorizedAssetsByChainList?.[0].chains?.[0]) {
navigation.navigate('AddCustomToken', {
key,
selectedAccountAddress: accountItem.receiveAddress,
selectedAccountAddress: accountItem?.receiveAddress,
selectedChain: memorizedAssetsByChainList[0].chains[0],
});
}
Expand Down Expand Up @@ -691,7 +691,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
onPress={() =>
navigation.navigate('AccountSettings', {
key,
selectedAccountAddress: accountItem.receiveAddress,
selectedAccountAddress: accountItem?.receiveAddress,
context: 'accountDetails',
})
}>
Expand Down Expand Up @@ -1039,7 +1039,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
? await debouncedLoadHistory(true)
: await startUpdateAllWalletStatusForKey({
key,
accountAddress: accountItem.receiveAddress,
accountAddress: accountItem?.receiveAddress,
force: true,
createTokenWalletWithFunds: true,
});
Expand Down Expand Up @@ -1080,7 +1080,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
const copyToClipboard = () => {
haptic('impactLight');
if (!copied) {
Clipboard.setString(accountItem.receiveAddress);
Clipboard.setString(accountItem?.receiveAddress);
setCopied(true);
}
};
Expand Down Expand Up @@ -1120,7 +1120,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
activeOpacity={ActiveOpacity}
style={{alignSelf: 'center', width: 'auto', height: 25}}>
<Badge style={{marginTop: 3}}>
{formatCryptoAddress(accountItem.receiveAddress)}
{formatCryptoAddress(accountItem?.receiveAddress)}
</Badge>
<CopyToClipboardContainer>
{!copied ? <CopySvg width={10} /> : <CopiedSvg width={10} />}
Expand Down Expand Up @@ -1182,12 +1182,12 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
cta: () => {
navigation.navigate('GlobalSelect', {
context: 'send',
selectedAccountAddress: accountItem.receiveAddress,
selectedAccountAddress: accountItem?.receiveAddress,
});
},
}}
/>
{Number(accountItem.fiatLockedBalanceFormat) > 0 ? (
{Number(accountItem?.fiatLockedBalanceFormat) > 0 ? (
<LockedBalanceContainer onPress={() => {}}>
<View>
<Description numberOfLines={1} ellipsizeMode={'tail'}>
Expand All @@ -1197,7 +1197,7 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {

<TailContainer>
<Value>
{accountItem.fiatLockedBalanceFormat}{' '}
{accountItem?.fiatLockedBalanceFormat}{' '}
{formatCurrencyAbbreviation(
key.wallets[1].currencyAbbreviation,
)}
Expand Down Expand Up @@ -1325,11 +1325,11 @@ const AccountDetails: React.FC<AccountDetailsScreenProps> = ({route}) => {
<AccountDropdownOptionsContainer>
{Object.values(memorizedAccountList).map(_accountItem => (
<DropdownOption
key={_accountItem.id}
optionId={_accountItem.id}
optionName={_accountItem.accountName}
wallets={_accountItem.wallets}
totalBalance={_accountItem.fiatBalance}
key={_accountItem?.id}
optionId={_accountItem?.id}
optionName={_accountItem?.accountName}
wallets={_accountItem?.wallets}
totalBalance={_accountItem?.fiatBalance}
onPress={(accountId: string) => {
setShowAccountDropdown(false);
const selectedAccountItem = memorizedAccountList.find(
Expand Down
1 change: 1 addition & 0 deletions src/navigation/wallet/screens/AccountSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ const AccountSettings = () => {
accountToggleSelected: !hideAccount,
}),
);
await sleep(1000);
dispatch(
startUpdateAllWalletStatusForKey({
key,
Expand Down
4 changes: 2 additions & 2 deletions src/store/wallet/utils/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ export const buildAssetsByChainList = (
) => {
const assetsByChainMap: {[key: string]: Partial<AssetsByChainListProps>} = {};

accountItem.wallets.forEach(coin => {
accountItem?.wallets?.forEach(coin => {
buildUIFormattedAssetsList(
assetsByChainMap,
coin,
Expand Down Expand Up @@ -1463,7 +1463,7 @@ export const buildAssetsByChain = (
) => {
const assetsByChainList: {[key: string]: AssetsByChainData} = {};

accountItem.wallets.forEach(coin => {
accountItem?.wallets?.forEach(coin => {
buildUIFormattedAssets(
assetsByChainList,
coin,
Expand Down

0 comments on commit 83fdbb0

Please sign in to comment.