Skip to content

Commit

Permalink
fix: stop deducting fees twice in available amount (#1225)
Browse files Browse the repository at this point in the history
Fixes the second of two bugs causing the TransferModule to incorrectly
detect that there is not enough balance.

Also display 0 if available amount minus fees is less than 0.
  • Loading branch information
emccorson committed Nov 1, 2024
1 parent b7367f7 commit f4c1ee3
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions apps/namadillo/src/App/Transfer/TransferModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const TransferModule = ({
const [sourceIbcChannel, setSourceIbcChannel] = useState("");
const [destinationIbcChannel, setDestinationIbcChannel] = useState("");

const availableAmount = useMemo(() => {
const availableAmountMinusFees = useMemo(() => {
const { selectedAsset, availableAmount } = source;

if (
Expand All @@ -107,9 +107,12 @@ export const TransferModule = ({
return undefined;
}

return transactionFee && selectedAsset.base === transactionFee.token.base ?
const minusFees =
transactionFee && selectedAsset.base === transactionFee.token.base ?
availableAmount.minus(transactionFee.amount)
: availableAmount;

return BigNumber.max(minusFees, 0);
}, [source.selectedAsset, source.availableAmount, transactionFee]);

const validationResult = useMemo((): ValidationResult => {
Expand All @@ -126,16 +129,16 @@ export const TransferModule = ({
} else if (!transactionFee) {
return "NoTransactionFee";
} else if (
!availableAmount ||
availableAmount.lt(amount.plus(transactionFee.amount))
!availableAmountMinusFees ||
amount.gt(availableAmountMinusFees)
) {
return "NotEnoughBalance";
} else if (!destination.wallet) {
return "NoDestinationWallet";
} else {
return "Ok";
}
}, [amount, source, destination, transactionFee, availableAmount]);
}, [amount, source, destination, transactionFee, availableAmountMinusFees]);

const onSubmit = (e: React.FormEvent): void => {
e.preventDefault();
Expand Down Expand Up @@ -229,7 +232,7 @@ export const TransferModule = ({
return "Define an amount to transfer";
}

if (!availableAmount) {
if (!availableAmountMinusFees) {
return "Wallet amount not available";
}

Expand All @@ -255,7 +258,7 @@ export const TransferModule = ({
asset={source.selectedAsset}
isLoadingAssets={source.isLoadingAssets}
chain={parseChainInfo(source.chain, source.isShielded)}
availableAmount={availableAmount}
availableAmount={availableAmountMinusFees}
amount={amount}
openProviderSelector={onChangeWallet(source)}
openChainSelector={
Expand Down

1 comment on commit f4c1ee3

@github-actions
Copy link

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.