Skip to content

Commit

Permalink
fix: crab available (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
JayJay1024 authored Jun 7, 2022
1 parent 241217d commit 1632175
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/components/staking/AssetOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { QuestionCircleFilled } from '@ant-design/icons';
import { Skeleton, Tooltip } from 'antd';
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useStaking } from '../../hooks';
import { BN } from '@polkadot/util';
import { useStaking, useApi } from '../../hooks';
import { AssetOverviewProps } from '../../model';
import { fromWei, isRing, prettyNumber, getLedger } from '../../utils';
import { PrettyAmount } from '../widget/PrettyAmount';
Expand All @@ -19,6 +20,7 @@ function Description({ title, value }: { title: string; value: string }) {
}

export function AssetOverview({ asset }: AssetOverviewProps) {
const { network } = useApi();
const { t } = useTranslation();
const { stakingDerive, isStakingLedgerEmpty, isStakingDeriveLoading } = useStaking();
const tokenIconSrc = useMemo(
Expand All @@ -31,6 +33,12 @@ export function AssetOverview({ asset }: AssetOverviewProps) {
[asset, isStakingLedgerEmpty, stakingDerive]
);

// TODO: revert after upgrade darwinia runtime
const available = useMemo(
() => (network.name === 'darwinia' ? new BN(asset.max).sub(new BN(ledger.unbonding || 0)) : asset.max),
[network.name, asset.max, ledger.unbonding]
);

if (isStakingDeriveLoading) {
return <Skeleton active />;
}
Expand All @@ -44,7 +52,7 @@ export function AssetOverview({ asset }: AssetOverviewProps) {
</div>

<div className="flex flex-col col-span-2 justify-between">
<Description title={t('Available')} value={fromWei({ value: asset.max }, prettyNumber)} />
<Description title={t('Available')} value={fromWei({ value: available }, prettyNumber)} />
<Description title={t('Bonded')} value={fromWei({ value: ledger.bonded }, prettyNumber)} />
<Description title={t('Unbonded')} value={fromWei({ value: ledger.unbonded }, prettyNumber)} />
{isRing(asset.asset) && (
Expand Down

0 comments on commit 1632175

Please sign in to comment.