Skip to content

Commit

Permalink
address #1071
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-1979 committed Apr 2, 2024
1 parent 32a32be commit f8fca0b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ export default function AccountDetails (): React.ReactElement {
}

const totalBalance = getValue('total', balances);
console.log('balances:',balances && JSON.parse(JSON.stringify(balances)))


return parseFloat(amountToHuman(totalBalance, balances.decimal)) * currentPrice;
}, [balances, currentPrice, pricesInCurrency]);
Expand Down Expand Up @@ -227,7 +229,7 @@ export default function AccountDetails (): React.ReactElement {
/>
}
<DisplayBalance
amount={balancesToShow?.availableBalance}
amount={getValue('Transferable', balancesToShow)}
decimal={balancesToShow?.decimal}
isDarkTheme={isDarkTheme}
onClick={goToSend}
Expand Down
25 changes: 20 additions & 5 deletions packages/extension-polkagate/src/hooks/useBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,24 @@ export default function useBalances (address: string | undefined, refresh?: bool

const ED = api.consts.balances.existentialDeposit as unknown as BN;

formatted && api.derive.balances?.all(formatted).then((b) => {
setNewBalances({ ...b, ED, chainName, date: Date.now(), decimal, genesisHash: api.genesisHash.toString(), token });
setRefresh && setRefresh(false);
isFetching.fetching[String(formatted)].balances = false;
isFetching.set(isFetching.fetching);
formatted && api.derive.balances?.all(formatted).then((allBalances) => {
api.query.system.account(formatted).then(({ data: systemBalance }) => {
const frozenBalance = systemBalance.frozen as BN;

setNewBalances({
ED,
...allBalances,
chainName,
date: Date.now(),
decimal: api.registry.chainDecimals[0],
frozenBalance,
genesisHash: api.genesisHash.toString(),
token: api.registry.chainTokens[0]
});
setRefresh && setRefresh(false);
isFetching.fetching[String(formatted)].balances = false;
isFetching.set(isFetching.fetching);
}).catch(console.error);
}).catch(console.error);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [api, chain?.genesisHash, chainName, formatted, isFetching.fetching[String(formatted)]?.length, setRefresh]);
Expand Down Expand Up @@ -190,6 +203,7 @@ export default function useBalances (address: string | undefined, refresh?: bool
const balances = {
availableBalance: overall.availableBalance.toString(),
freeBalance: overall.freeBalance.toString(),
frozenBalance: overall.frozenBalance.toString(),
lockedBalance: overall.lockedBalance.toString(),
pooledBalance: overall.pooledBalance.toString(),
reservedBalance: overall.reservedBalance.toString(),
Expand Down Expand Up @@ -223,6 +237,7 @@ export default function useBalances (address: string | undefined, refresh?: bool
date: savedBalances[chainName].date,
decimal: savedBalances[chainName].decimal,
freeBalance: new BN(sb.freeBalance),
frozenBalance: new BN(sb.frozenBalance),
lockedBalance: new BN(sb.lockedBalance),
pooledBalance: new BN(sb.pooledBalance),
reservedBalance: new BN(sb.reservedBalance),
Expand Down
10 changes: 4 additions & 6 deletions packages/extension-polkagate/src/popup/account/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ export const getValue = (type: string, balances: BalancesInfo | null | undefined
return balances?.soloTotal ?? BN_ZERO;
case ('balance'):
case ('available'):
case ('transferable'):
case ('available balance'):
return balances.availableBalance;
case ('transferable'):
return balances.reservedBalance.gte(balances.frozenBalance)
? balances.freeBalance
: balances.freeBalance.sub(balances.frozenBalance.sub(balances.reservedBalance));
case ('reserved'):
return balances.reservedBalance;
case ('others'):
Expand All @@ -43,10 +46,6 @@ export const getValue = (type: string, balances: BalancesInfo | null | undefined
return balances.freeBalance;
case ('reserved balance'):
return balances.reservedBalance;
// case ('frozen misc'):
// return balances.frozenMisc;
// case ('frozen fee'):
// return balances.frozenFee;
case ('locked'):
case ('locked balance'):
return balances.lockedBalance;
Expand All @@ -64,4 +63,3 @@ export const getValue = (type: string, balances: BalancesInfo | null | undefined
return undefined;
}
};

1 change: 1 addition & 0 deletions packages/extension-polkagate/src/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ export interface BalancesInfo extends DeriveBalancesAll {
token: string;
date: number;
pooledBalance?: BN;
frozenBalance: BN;
soloTotal?: BN;
genesisHash: string;
ED: BN;
Expand Down

0 comments on commit f8fca0b

Please sign in to comment.