Skip to content

Commit

Permalink
Merge branch 'feat/swap-slide' into tmp/20241218
Browse files Browse the repository at this point in the history
  • Loading branch information
dmy147 committed Dec 19, 2024
2 parents ee597f4 + 0298001 commit cf7ee90
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/ui/views/Approval/components/MiniSignTx/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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!);
}
Expand Down
9 changes: 7 additions & 2 deletions src/ui/views/Approval/components/SignTestnetTx/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export const SignTestnetTx = ({ params, origin }: SignTxProps) => {
isCancel,
isSend,
isSwap,
isBridge,
swapPreferMEVGuarded,
isViewGnosisSafe,
reqId,
Expand Down Expand Up @@ -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!);
}
Expand All @@ -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'
Expand Down
9 changes: 7 additions & 2 deletions src/ui/views/Approval/components/SignTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ const SignTx = ({ params, origin }: SignTxProps) => {
isCancel,
isSend,
isSwap,
isBridge,
swapPreferMEVGuarded,
isViewGnosisSafe,
reqId,
Expand Down Expand Up @@ -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!);
}
Expand All @@ -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'
Expand Down
8 changes: 8 additions & 0 deletions src/ui/views/Bridge/Component/BridgeContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export const BridgeContent = () => {

const refresh = useSetRefreshId();

const [maxNativeTokenGasPrice, setMaxNativeTokenGasPrice] = useState<
number | undefined
>(undefined);

const { t } = useTranslation();

const btnText = useMemo(() => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -196,6 +201,7 @@ export const BridgeContent = () => {
amount,
rbiSource,
slippageState,
maxNativeTokenGasPrice,
]);

const buildTxs = useMemoizedFn(async () => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -375,6 +382,7 @@ export const BridgeContent = () => {
onInputChange={handleAmountChange}
excludeChains={toChain ? [toChain] : undefined}
inSufficient={inSufficient}
handleSetGasPrice={setMaxNativeTokenGasPrice}
/>
<BridgeToken
type="to"
Expand Down
6 changes: 6 additions & 0 deletions src/ui/views/Bridge/Component/BridgeToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const BridgeToken = ({
fromTokenId,
noQuote,
inSufficient,
handleSetGasPrice,
}: {
type?: 'from' | 'to';
token?: TokenItem;
Expand All @@ -82,6 +83,7 @@ export const BridgeToken = ({
value?: string | number;
onInputChange?: (v: string) => void;
inSufficient?: boolean;
handleSetGasPrice?: (gasPrice?: number) => void;

valueLoading?: boolean;
fromChainId?: string;
Expand Down Expand Up @@ -175,6 +177,7 @@ export const BridgeToken = ({
const inputChange = React.useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
onInputChange?.(e.target.value);
handleSetGasPrice?.();
},
[onInputChange]
);
Expand All @@ -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,
Expand Down

0 comments on commit cf7ee90

Please sign in to comment.