Skip to content

Commit

Permalink
IGP payment validation clarification (#82)
Browse files Browse the repository at this point in the history
* Check user's IGP payment token
* Use gas token symbol in toast

---------

Co-authored-by: Trevor Porter <[email protected]>
  • Loading branch information
jmrossy and tkporter authored Nov 14, 2023
1 parent 3c2ca72 commit 28f2dbc
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/features/transfer/TransferTokenForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -543,21 +543,26 @@ function validateFormValues(
if (sendValue.gt(balances.senderTokenBalance)) return { amount: 'Insufficient balance' };
// Ensure balances can cover IGP fees
const igpWeiAmount = new BigNumber(igpQuote?.weiAmount || 0);
const requiredNativeBalance =
// If the route is from a Cosmos chain, we charge fees in the sending token.
// Otherwise, we charge fees in the native token of the sending chain.
const userIgpTokenBalance =
originProtocol === ProtocolType.Cosmos
? balances.senderTokenBalance
: balances.senderNativeBalance;
const requiredIgpTokenBalance =
isRouteFromNative(route) || originProtocol === ProtocolType.Cosmos
? sendValue.plus(igpWeiAmount)
: igpWeiAmount;

const nativeToken = getChainMetadata(originCaip2Id)?.nativeToken;
const nativeDecimals = nativeToken?.decimals || 18;
const gasTokenSymbol =
originProtocol === ProtocolType.Cosmos
? tokenMetadata.symbol
: nativeToken?.symbol || 'native token';
(originProtocol === ProtocolType.Cosmos ? tokenMetadata.symbol : nativeToken?.symbol) ||
'native token';
const igpAmountPretty = fromWei(igpWeiAmount, nativeDecimals);

if (requiredNativeBalance.gt(balances.senderNativeBalance)) {
toastIgpDetails(igpAmountPretty);
if (requiredIgpTokenBalance.gt(userIgpTokenBalance)) {
toastIgpDetails(igpAmountPretty, gasTokenSymbol);
return { amount: `Insufficient ${gasTokenSymbol} for gas` };
}
} else {
Expand Down

1 comment on commit 28f2dbc

@vercel
Copy link

@vercel vercel bot commented on 28f2dbc Nov 14, 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.