From 4f1eff62bc5129b91cb001f6169d81c743fe47b3 Mon Sep 17 00:00:00 2001 From: JellyWang <38491708+ezailWang@users.noreply.github.com> Date: Tue, 24 Dec 2024 16:33:28 +0800 Subject: [PATCH 1/2] fix: swap EnableRecipientAddress switch fix (#6405) --- .../SwapHeaderRightActionContainer.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/kit/src/views/Swap/pages/components/SwapHeaderRightActionContainer.tsx b/packages/kit/src/views/Swap/pages/components/SwapHeaderRightActionContainer.tsx index a7826a16c20..08af3bd2315 100644 --- a/packages/kit/src/views/Swap/pages/components/SwapHeaderRightActionContainer.tsx +++ b/packages/kit/src/views/Swap/pages/components/SwapHeaderRightActionContainer.tsx @@ -225,10 +225,10 @@ const SwapSlippageCustomContent = ({ const SwapSettingsDialogContent = () => { const intl = useIntl(); const { slippageItem } = useSwapSlippagePercentageModeInfo(); - const [{ swapEnableRecipientAddress }, setSettings] = useSettingsAtom(); + const [{ swapEnableRecipientAddress }, setNoPersistSettings] = + useSettingsAtom(); const [{ swapBatchApproveAndSwap }, setPersistSettings] = useSettingsPersistAtom(); - const [, setNoPersistSettings] = useSettingsAtom(); const rightTrigger = useMemo( () => ( { })} value={swapEnableRecipientAddress} onChange={(v) => { - setSettings((s) => ({ - ...s, - swapEnableRecipientAddress: v, - })); - if (!v) { + if (v) { + setNoPersistSettings((s) => ({ + ...s, + swapEnableRecipientAddress: v, + })); + } else { setNoPersistSettings((s) => ({ ...s, - swapToAnotherAccountSwitchOn: false, + swapEnableRecipientAddress: v, + swapToAnotherAccountSwitchOn: v, })); } }} From 2bfc8fa890660e0599682106ea732969734cee8d Mon Sep 17 00:00:00 2001 From: weatherstar Date: Wed, 25 Dec 2024 11:24:21 +0800 Subject: [PATCH 2/2] fix: verify evm txid return by custom rpc (#6408) * fix: verify evm txid which return by custom rpc * fix: call oncancel error * fix: lint --- packages/kit-bg/src/services/ServiceSend.ts | 13 +++++++++++++ packages/kit-bg/src/vaults/base/VaultBase.ts | 7 +++++++ packages/kit-bg/src/vaults/impls/evm/Vault.ts | 16 ++++++++++++++++ .../SendConfirmFromSwap/SendConfirmFromSwap.tsx | 8 +++----- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/packages/kit-bg/src/services/ServiceSend.ts b/packages/kit-bg/src/services/ServiceSend.ts index e16ed57eed4..b55d19df0f4 100644 --- a/packages/kit-bg/src/services/ServiceSend.ts +++ b/packages/kit-bg/src/services/ServiceSend.ts @@ -158,6 +158,19 @@ class ServiceSend extends ServiceBase { ...params, customRpcInfo, }); + + try { + const verified = await vault.verifyTxId({ + txid: result.txid, + signedTx: result, + }); + if (!verified) { + throw new Error('Invalid txid'); + } + } catch (error) { + throw new Error('Invalid txid'); + } + txid = result.txid; } diff --git a/packages/kit-bg/src/vaults/base/VaultBase.ts b/packages/kit-bg/src/vaults/base/VaultBase.ts index 3f4a74038a8..d0a53f97d99 100644 --- a/packages/kit-bg/src/vaults/base/VaultBase.ts +++ b/packages/kit-bg/src/vaults/base/VaultBase.ts @@ -1419,4 +1419,11 @@ export abstract class VaultBase extends VaultBaseChainOnly { ): Promise { throw new NotImplemented(); } + + async verifyTxId(params: { + txid: string; + signedTx: ISignedTxPro; + }): Promise { + return Promise.resolve(true); + } } diff --git a/packages/kit-bg/src/vaults/impls/evm/Vault.ts b/packages/kit-bg/src/vaults/impls/evm/Vault.ts index 70f5c30ef31..7d6feb7e892 100644 --- a/packages/kit-bg/src/vaults/impls/evm/Vault.ts +++ b/packages/kit-bg/src/vaults/impls/evm/Vault.ts @@ -1232,6 +1232,7 @@ export default class Vault extends VaultBase { } const client = new ClientEvm(rpcUrl); const txid = await client.broadcastTransaction(signedTx.rawTx); + return { ...signedTx, txid, @@ -1239,6 +1240,21 @@ export default class Vault extends VaultBase { }; } + override async verifyTxId(params: { + txid: string; + signedTx: ISignedTxPro; + }): Promise { + const { signedTx, txid } = params; + + if (typeof txid !== 'string') { + return false; + } + + const recoveredTxid = ethers.utils.keccak256(signedTx.rawTx); + + return recoveredTxid.toLowerCase() === txid.toLowerCase(); + } + // RPC Client async getRpcClient() { const rpcInfo = diff --git a/packages/kit/src/views/Send/pages/SendConfirmFromSwap/SendConfirmFromSwap.tsx b/packages/kit/src/views/Send/pages/SendConfirmFromSwap/SendConfirmFromSwap.tsx index 38888670608..b1fc0a0d283 100644 --- a/packages/kit/src/views/Send/pages/SendConfirmFromSwap/SendConfirmFromSwap.tsx +++ b/packages/kit/src/views/Send/pages/SendConfirmFromSwap/SendConfirmFromSwap.tsx @@ -70,13 +70,11 @@ function SendConfirmFromSwap() { const isLastTx = i === len - 1; const result: ISendTxOnSuccessData[] = await new Promise((resolve) => { - navigationToNext.current = true; appNavigation.push(EModalSendRoutes.SendConfirm, { ...route.params, popStack: false, unsignedTxs: [unsignedTx], onSuccess: (data: ISendTxOnSuccessData[]) => { - navigationToNext.current = false; if (isLastTx) { appNavigation.pop(); onSuccess?.(data); @@ -84,12 +82,10 @@ function SendConfirmFromSwap() { resolve(data); }, onFail: (error: Error) => { - navigationToNext.current = false; appNavigation.pop(); onFail?.(error); }, onCancel: () => { - navigationToNext.current = false; appNavigation.pop(); onCancel?.(); }, @@ -127,6 +123,7 @@ function SendConfirmFromSwap() { networkId, encodedTxs: encodedTxList, }); + navigationToNext.current = true; if (multiTxsFeeResult.txFees.length === unsignedTxs.length) { await handleConfirmMultiTxsOnHwOrExternal(multiTxsFeeResult); } else { @@ -140,8 +137,9 @@ function SendConfirmFromSwap() { } } + navigationToNext.current = true; + if (!batchEstimateButSingleConfirm) { - navigationToNext.current = true; action = StackActions.replace(EModalSendRoutes.SendConfirm, { ...route.params, // @ts-ignore