From 02980018ad783458cbfb8405d1da941237b5fa53 Mon Sep 17 00:00:00 2001 From: DMY <147dmy@gmail.com> Date: Thu, 19 Dec 2024 16:27:23 +0800 Subject: [PATCH] fix: bridge pass custom gasprice --- src/ui/views/Approval/components/MiniSignTx/index.tsx | 4 ++-- src/ui/views/Approval/components/SignTestnetTx/index.tsx | 9 +++++++-- src/ui/views/Approval/components/SignTx.tsx | 9 +++++++-- src/ui/views/Bridge/Component/BridgeContent.tsx | 8 ++++++++ src/ui/views/Bridge/Component/BridgeToken.tsx | 6 ++++++ 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/ui/views/Approval/components/MiniSignTx/index.tsx b/src/ui/views/Approval/components/MiniSignTx/index.tsx index 811778fa212..1862bedf73b 100644 --- a/src/ui/views/Approval/components/MiniSignTx/index.tsx +++ b/src/ui/views/Approval/components/MiniSignTx/index.tsx @@ -259,7 +259,7 @@ export const MiniSignTx = ({ }); }; - const { swapPreferMEVGuarded, isSwap } = normalizeTxParams(txs[0]); + const { swapPreferMEVGuarded, isSwap, isBridge } = normalizeTxParams(txs[0]); const [pushInfo, setPushInfo] = useState<{ type: TxPushType; @@ -573,7 +573,7 @@ export const MiniSignTx = ({ customGasPrice = lastTimeGas.gasPrice; } const gasPrice = txs[0].gasPrice || txs[0].maxFeePerGas; - if (isSwap && gasPrice) { + if ((isSwap || isBridge) && gasPrice) { // use gasPrice set by dapp when it's a speedup or cancel tx customGasPrice = parseInt(gasPrice!); } diff --git a/src/ui/views/Approval/components/SignTestnetTx/index.tsx b/src/ui/views/Approval/components/SignTestnetTx/index.tsx index 35b90e78b42..e6660f883a4 100644 --- a/src/ui/views/Approval/components/SignTestnetTx/index.tsx +++ b/src/ui/views/Approval/components/SignTestnetTx/index.tsx @@ -208,6 +208,7 @@ export const SignTestnetTx = ({ params, origin }: SignTxProps) => { isCancel, isSend, isSwap, + isBridge, swapPreferMEVGuarded, isViewGnosisSafe, reqId, @@ -381,7 +382,11 @@ export const SignTestnetTx = ({ params, origin }: SignTxProps) => { // use cached gasPrice if exist customGasPrice = lastTimeGas.gasPrice; } - if (isSpeedUp || isCancel || ((isSend || isSwap) && tx.gasPrice)) { + if ( + isSpeedUp || + isCancel || + ((isSend || isSwap || isBridge) && tx.gasPrice) + ) { // use gasPrice set by dapp when it's a speedup or cancel tx customGasPrice = parseInt(tx.gasPrice!); } @@ -395,7 +400,7 @@ export const SignTestnetTx = ({ params, origin }: SignTxProps) => { let gas: GasLevel | null = null; if ( - ((isSend || isSwap) && customGasPrice) || + ((isSend || isSwap || isBridge) && customGasPrice) || isSpeedUp || isCancel || lastTimeGas?.lastTimeSelect === 'gasPrice' diff --git a/src/ui/views/Approval/components/SignTx.tsx b/src/ui/views/Approval/components/SignTx.tsx index 44a4fb3c289..931e4ee9350 100644 --- a/src/ui/views/Approval/components/SignTx.tsx +++ b/src/ui/views/Approval/components/SignTx.tsx @@ -564,6 +564,7 @@ const SignTx = ({ params, origin }: SignTxProps) => { isCancel, isSend, isSwap, + isBridge, swapPreferMEVGuarded, isViewGnosisSafe, reqId, @@ -1623,7 +1624,11 @@ const SignTx = ({ params, origin }: SignTxProps) => { // use cached gasPrice if exist customGasPrice = lastTimeGas.gasPrice; } - if (isSpeedUp || isCancel || ((isSend || isSwap) && tx.gasPrice)) { + if ( + isSpeedUp || + isCancel || + ((isSend || isSwap || isBridge) && tx.gasPrice) + ) { // use gasPrice set by dapp when it's a speedup or cancel tx customGasPrice = parseInt(tx.gasPrice!); } @@ -1632,7 +1637,7 @@ const SignTx = ({ params, origin }: SignTxProps) => { let gas: GasLevel | null = null; if ( - ((isSend || isSwap) && customGasPrice) || + ((isSend || isSwap || isBridge) && customGasPrice) || isSpeedUp || isCancel || lastTimeGas?.lastTimeSelect === 'gasPrice' diff --git a/src/ui/views/Bridge/Component/BridgeContent.tsx b/src/ui/views/Bridge/Component/BridgeContent.tsx index 61827833841..6f360ca66e7 100644 --- a/src/ui/views/Bridge/Component/BridgeContent.tsx +++ b/src/ui/views/Bridge/Component/BridgeContent.tsx @@ -79,6 +79,10 @@ export const BridgeContent = () => { const refresh = useSetRefreshId(); + const [maxNativeTokenGasPrice, setMaxNativeTokenGasPrice] = useState< + number | undefined + >(undefined); + const { t } = useTranslation(); const btnText = useMemo(() => { @@ -144,6 +148,7 @@ export const BridgeContent = () => { shouldTwoStepApprove: !!selectedBridgeQuote.shouldTwoStepApprove, payTokenId: fromToken.id, payTokenChainServerId: fromToken.chain, + gasPrice: maxNativeTokenGasPrice, info: { aggregator_id: selectedBridgeQuote.aggregator.id, bridge_id: selectedBridgeQuote.bridge_id, @@ -196,6 +201,7 @@ export const BridgeContent = () => { amount, rbiSource, slippageState, + maxNativeTokenGasPrice, ]); const buildTxs = useMemoizedFn(async () => { @@ -248,6 +254,7 @@ export const BridgeContent = () => { shouldTwoStepApprove: !!selectedBridgeQuote.shouldTwoStepApprove, payTokenId: fromToken.id, payTokenChainServerId: fromToken.chain, + gasPrice: maxNativeTokenGasPrice, info: { aggregator_id: selectedBridgeQuote.aggregator.id, bridge_id: selectedBridgeQuote.bridge_id, @@ -375,6 +382,7 @@ export const BridgeContent = () => { onInputChange={handleAmountChange} excludeChains={toChain ? [toChain] : undefined} inSufficient={inSufficient} + handleSetGasPrice={setMaxNativeTokenGasPrice} /> void; inSufficient?: boolean; + handleSetGasPrice?: (gasPrice?: number) => void; valueLoading?: boolean; fromChainId?: string; @@ -175,6 +177,7 @@ export const BridgeToken = ({ const inputChange = React.useCallback( (e: React.ChangeEvent) => { onInputChange?.(e.target.value); + handleSetGasPrice?.(); }, [onInputChange] ); @@ -198,12 +201,15 @@ export const BridgeToken = ({ .div(10 ** nativeTokenDecimals) ); onInputChange?.(val.toString(10)); + handleSetGasPrice?.(normalPrice); return; } } + handleSetGasPrice?.(); onInputChange?.(tokenAmountBn(token)?.toString(10)); } }, [ + handleSetGasPrice, token?.raw_amount_hex_str, onInputChange, nativeTokenDecimals,