From 9bc970908b68659cc1074e88e8094e3d1b2a9169 Mon Sep 17 00:00:00 2001 From: wenty22 Date: Wed, 4 Dec 2024 11:34:55 +0800 Subject: [PATCH] fix: Solve solana native token fee issue --- .../deBridge/hooks/useGetDeBridgeFees.ts | 30 ++++--------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/deBridge/hooks/useGetDeBridgeFees.ts b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/deBridge/hooks/useGetDeBridgeFees.ts index 705ba422..6b389a7b 100644 --- a/packages/canonical-bridge-widget/src/modules/aggregator/adapters/deBridge/hooks/useGetDeBridgeFees.ts +++ b/packages/canonical-bridge-widget/src/modules/aggregator/adapters/deBridge/hooks/useGetDeBridgeFees.ts @@ -74,10 +74,12 @@ export const useGetDeBridgeFees = () => { value: `${formatNumber(Number(protocolFee), 8)} ${nativeToken}`, }); // Make sure native token can cover the protocol fee - const totalNativeAmount = - selectedToken?.deBridge?.raw?.address === '0x0000000000000000000000000000000000000000' - ? BigInt(fees?.fixFee) + parseUnits(sendValue, 18) - : BigInt(fees?.fixFee); + const totalNativeAmount = isNativeToken( + selectedToken?.deBridge?.raw?.address, + fromChain?.chainType, + ) + ? BigInt(fees?.fixFee) + parseUnits(sendValue, nativeDecimals) + : BigInt(fees?.fixFee); if (nativeTokenBalance && nativeTokenBalance?.value < totalNativeAmount) { dispatch( setRouteError({ @@ -222,26 +224,6 @@ export const useGetDeBridgeFees = () => { acc[symbol] += value; return acc; }, {} as { [key: string]: number }); - - if ( - fromChain?.chainType === 'solana' && - isNativeToken(selectedToken?.deBridge?.raw?.address, fromChain?.chainType) && - nativeToken && - nativeTokenBalance - ) { - const totalNativeTokenCost = Number(result[nativeToken]) + Number(sendValue); - const userNativeTokenBalance = Number(nativeTokenBalance.formatted); - - if (userNativeTokenBalance < totalNativeTokenCost) { - dispatch( - setRouteError({ - deBridge: `Insufficient ${nativeToken} to cover protocol fee and market maker gas costs`, - }), - ); - isDisplayError = true; - } - } - const resultString = Object.keys(result) .map((symbol) => { return `${formatFeeAmount(result[symbol])} ${symbol}`;