From 28f2dbcbb7d7439effdc25ed8d00dc802dca7ff8 Mon Sep 17 00:00:00 2001 From: J M Rossy Date: Tue, 14 Nov 2023 11:32:33 -0500 Subject: [PATCH] IGP payment validation clarification (#82) * Check user's IGP payment token * Use gas token symbol in toast --------- Co-authored-by: Trevor Porter --- src/features/transfer/TransferTokenForm.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/features/transfer/TransferTokenForm.tsx b/src/features/transfer/TransferTokenForm.tsx index b4fc83c3..a678768f 100644 --- a/src/features/transfer/TransferTokenForm.tsx +++ b/src/features/transfer/TransferTokenForm.tsx @@ -543,7 +543,13 @@ 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; @@ -551,13 +557,12 @@ function validateFormValues( 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 {