Skip to content

Commit

Permalink
fix: fee affecting action amount calculation (#1472)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsimao authored Jul 19, 2023
1 parent 30e7d70 commit ae37c64
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/utils/hooks/transaction/utils/params.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CurrencyExt } from '@interlay/interbtc-api';
import { CurrencyExt, newMonetaryAmount } from '@interlay/interbtc-api';
import { MonetaryAmount } from '@interlay/monetary-js';

import { Actions, Transaction } from '../types';
Expand Down Expand Up @@ -27,6 +27,23 @@ const getAmountWithFeeDeducted = (
feeAmount: MonetaryAmount<CurrencyExt>,
balance: MonetaryAmount<CurrencyExt>
): MonetaryAmount<CurrencyExt> => {
const isFeeGreaterThanActionAmount = feeAmount.gte(actionAmount);

// since our fees are low, this would mean that the user
// is trying to deal with very small action amount
if (isFeeGreaterThanActionAmount) {
return newMonetaryAmount(0, actionAmount.currency);
}

const isActionAmountGreaterThanBalance = actionAmount.gt(balance);

// if the action amount is greater than the balance, the user
// should not able to conduct the transaction but amount affected by the fee should
// be return anyway (specially relevant for swap)
if (isActionAmountGreaterThanBalance) {
return actionAmount.sub(feeAmount);
}

const isMaxAmount = balance.eq(actionAmount);

// when the action amount is the max balance, the fee
Expand Down

2 comments on commit ae37c64

@vercel
Copy link

@vercel vercel bot commented on ae37c64 Jul 19, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on ae37c64 Jul 19, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.