Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix free balances (Overview & Nominate) #2075

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indeed looks like the correct calculation. fundsReserved should have also been in plank format, but is removed now.

units
);

Expand Down
Loading