Skip to content

Commit

Permalink
fix: Fix free balances (Overview & Nominate) (#2075)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankli-dev authored Apr 11, 2024
1 parent a5bc9e9 commit 44c6bcd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
12 changes: 4 additions & 8 deletions src/pages/Nominate/Active/ManageBond.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { faLockOpen } from '@fortawesome/free-solid-svg-icons';
import { Odometer } from '@w3ux/react-odometer';
import { minDecimalPlaces, planckToUnit } from '@w3ux/utils';
import BigNumber from 'bignumber.js';
import type BigNumber from 'bignumber.js';
import { useTranslation } from 'react-i18next';
import { useBalances } from 'contexts/Balances';
import { useHelp } from 'contexts/Help';
Expand Down Expand Up @@ -37,19 +37,15 @@ export const ManageBond = () => {
const { openModal } = useOverlay().modal;
const { isFastUnstaking } = useUnstaking();
const { isReadOnlyAccount } = useImportedAccounts();
const { getTransferOptions, feeReserve } = useTransferOptions();
const { getTransferOptions } = useTransferOptions();
const { activeAccount } = useActiveAccounts();
const ledger = getLedger({ stash: activeAccount });
const { active }: { active: BigNumber } = ledger;
const allTransferOptions = getTransferOptions(activeAccount);

const { freeBalance, edReserved } = allTransferOptions;
const { freeBalance } = allTransferOptions;
const { totalUnlocking, totalUnlocked, totalUnlockChunks } =
allTransferOptions.nominate;
const totalFree = BigNumber.max(
0,
freeBalance.minus(edReserved.plus(feeReserve))
);

return (
<>
Expand Down Expand Up @@ -123,7 +119,7 @@ export const ManageBond = () => {
active={planckToUnit(active, units)}
unlocking={planckToUnit(totalUnlocking, units)}
unlocked={planckToUnit(totalUnlocked, units)}
free={planckToUnit(totalFree, units)}
free={planckToUnit(freeBalance, units)}
inactive={active.isZero()}
/>
</>
Expand Down
7 changes: 1 addition & 6 deletions src/pages/Overview/BalanceChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,7 @@ export const BalanceChart = () => {
let fundsReserved = planckToUnit(edReserved.plus(feeReserve), units);

const fundsFree = planckToUnit(
BigNumber.max(
allTransferOptions.freeBalance
.minus(fundsReserved)
.minus(fundsLockedPlank),
0
),
BigNumber.max(allTransferOptions.freeBalance.minus(fundsLockedPlank), 0),
units
);

Expand Down

0 comments on commit 44c6bcd

Please sign in to comment.