Skip to content

Commit

Permalink
fix: add balanceTxFees
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Bulat committed Nov 6, 2023
1 parent 491e178 commit 05056fa
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/contexts/TransferOptions/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const defaultBondedContext: TransferOptionsContextInterface = {
export const transferOptions: TransferOptions = {
freeBalance: new BigNumber(0),
transferrableBalance: new BigNumber(0),
balanceTxFees: new BigNumber(0),
edReserved: new BigNumber(0),
nominate: {
active: new BigNumber(0),
Expand Down
6 changes: 6 additions & 0 deletions src/contexts/TransferOptions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ export const TransferOptionsProvider = ({

// free balance after `total` ledger amount.
const freeBalance = BigNumber.max(freeMinusReserve.minus(total), 0);

// free balance to pay for tsx fees.
const balanceTxFees = BigNumber.max(freeMinusReserve.minus(frozen), 0);

// free balance that can be transferred.
const transferrableBalance = BigNumber.max(
freeBalance.minus(feeReserve).minus(frozen),
0
Expand Down Expand Up @@ -164,6 +169,7 @@ export const TransferOptionsProvider = ({
return {
freeBalance,
transferrableBalance,
balanceTxFees,
edReserved,
nominate: nominateOptions(),
pool: poolOptions(),
Expand Down
1 change: 1 addition & 0 deletions src/contexts/TransferOptions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface TransferOptionsContextInterface {
export interface TransferOptions {
freeBalance: BigNumber;
transferrableBalance: BigNumber;
balanceTxFees: BigNumber;
edReserved: BigNumber;
nominate: {
active: BigNumber;
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/TxMeta/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export const TxMetaProvider = ({ children }: { children: React.ReactNode }) => {
const txSignatureRef = React.useRef(txSignature);

useEffectIgnoreInitial(() => {
const { transferrableBalance } = getTransferOptions(sender);
setNotEnoughFunds(transferrableBalance.minus(txFees).isLessThan(0));
const { balanceTxFees } = getTransferOptions(sender);
setNotEnoughFunds(balanceTxFees.minus(txFees).isLessThan(0));
}, [txFees, sender]);

const resetTxFees = () => {
Expand Down

0 comments on commit 05056fa

Please sign in to comment.