Skip to content

Commit

Permalink
handle fronzenBalance from storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-1979 committed Aug 16, 2024
1 parent 25ed4ee commit 9df8f16
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default function AccountDetails (): React.ReactElement {
: { ...(balances || {}), ...(selectedAsset || {}) };
}, [assetId, balances, chainName, selectedAsset]);

const transferableBalance = useMemo(() => getValue('transferable', balancesToShow as BalancesInfo), [balancesToShow]);
const isDualStaking = useMemo(() =>
balancesToShow?.soloTotal && balancesToShow?.pooledBalance && !balancesToShow.soloTotal.isZero() && !balancesToShow.pooledBalance.isZero()
, [balancesToShow?.pooledBalance, balancesToShow?.soloTotal]);
Expand Down Expand Up @@ -224,9 +225,9 @@ export default function AccountDetails (): React.ReactElement {
/>
}
<DisplayBalance
amount={getValue('Transferable', balancesToShow as BalancesInfo)}
amount={transferableBalance}
decimal={balancesToShow?.decimal}
disabled={!balancesToShow?.availableBalance || balancesToShow?.availableBalance.isZero()}
disabled={!transferableBalance || transferableBalance.isZero()}
onClick={goToSend}
price={currentPrice}
title={t('Transferable')}
Expand Down
3 changes: 2 additions & 1 deletion packages/extension-polkagate/src/hooks/useBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export default function useBalances(address: string | undefined, refresh?: boole
date: savedBalances[chainName].date,
decimal: savedBalances[chainName].decimal,
freeBalance: new BN(sb['freeBalance']),
frozenBalance: new BN(sb['frozenBalance'] || '0'),
genesisHash: sb['genesisHash'],
lockedBalance: new BN(sb['lockedBalance']),
pooledBalance: new BN(sb['pooledBalance']),
Expand All @@ -245,7 +246,7 @@ export default function useBalances(address: string | undefined, refresh?: boole
vestedBalance: new BN(sb['vestedBalance']),
vestedClaimable: new BN(sb['vestedClaimable']),
votingBalance: new BN(sb['votingBalance'])
} as any;
} as BalancesInfo;

setBalances({
...lastBalances,
Expand Down
10 changes: 7 additions & 3 deletions packages/extension-polkagate/src/popup/account/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import type { BalancesInfo } from '../../util/types';

import { BN, BN_ZERO } from '@polkadot/util';

function isEmptyObject (obj: object): boolean {
return Object.keys(obj).length === 0;
}

export const getValue = (type: string, balances: BalancesInfo | null | undefined): BN | undefined => {
if (!balances) {
if (!balances || isEmptyObject(balances)) {
return;
}

Expand All @@ -32,9 +36,9 @@ export const getValue = (type: string, balances: BalancesInfo | null | undefined
case ('available balance'):
return balances.availableBalance;
case ('transferable'):
return balances.reservedBalance && balances.reservedBalance.gte(balances.frozenBalance || BN_ZERO)
return balances.reservedBalance.gte(balances.frozenBalance || BN_ZERO)
? balances.freeBalance
: balances.freeBalance?.sub(balances.frozenBalance.sub(balances.reservedBalance));
: balances.freeBalance.sub(balances.frozenBalance.sub(balances.reservedBalance));
case ('reserved'):
return balances.reservedBalance;
case ('others'):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async function getBalances (chainName, addresses) {
}
}

async function getAssetOnRelayChain(addresses, chainName) {
async function getAssetOnRelayChain (addresses, chainName) {
const results = {};

await getBalances(chainName, addresses)
Expand Down

0 comments on commit 9df8f16

Please sign in to comment.