Skip to content

Commit

Permalink
fix: fetch all list balance
Browse files Browse the repository at this point in the history
  • Loading branch information
heisenberg-2077 committed Nov 28, 2024
1 parent 7c71a8f commit f60729a
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions apps/mobile/src/hooks/useAccountsBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export default function useAccountsBalance(opts?: {
const formatList = list
.filter(
a =>
a.type !== KEYRING_CLASS.WATCH && a.type !== KEYRING_CLASS.GNOSIS,
a.type !== KEYRING_CLASS.WATCH &&
a.type !== KEYRING_CLASS.GNOSIS &&
a.type !== KEYRING_CLASS.WALLETCONNECT,
)
.map(a => a.address.toLowerCase());

Expand All @@ -59,13 +61,25 @@ export default function useAccountsBalance(opts?: {
)
: formatList;

const accountPromises = uniqueList.map(async account => {
let allList = list
.filter(a => a.type !== KEYRING_CLASS.WALLETCONNECT)
.map(a => a.address.toLowerCase());

if (accountsNoUnique) {
allList = allList.filter(
(value, index, self) => self.indexOf(value) === index,
);
}

const accountPromises = allList.map(async account => {
if (fetchType === 'from_cache') {
const cacheData = preferenceService.getAddressBalance(account);
balancesArr.push({
address: account,
balance: cacheData?.total_usd_value || 0,
});
if (uniqueList.includes(account)) {
balancesArr.push({
address: account,
balance: cacheData?.total_usd_value || 0,
});
}
return;
}

Expand All @@ -74,18 +88,22 @@ export default function useAccountsBalance(opts?: {
const resData = await apiBalance.getAddressBalance(account, {
force: true,
});
balancesArr.push({
address: account,
balance: resData?.total_usd_value || 0,
});
if (uniqueList.includes(account)) {
balancesArr.push({
address: account,
balance: resData?.total_usd_value || 0,
});
}
} catch (e) {
console.log('accountPromises error', e);
// api fetch error fallback get from cache store
const cacheData = preferenceService.getAddressBalance(account);
balancesArr.push({
address: account,
balance: cacheData?.total_usd_value || 0,
});
if (uniqueList.includes(account)) {
balancesArr.push({
address: account,
balance: cacheData?.total_usd_value || 0,
});
}
}
});

Expand Down

0 comments on commit f60729a

Please sign in to comment.