From ef71379f26a8fa379e76e0a0d72bd997408c453a Mon Sep 17 00:00:00 2001 From: heisenberg <110591045+heisenberg-2077@users.noreply.github.com> Date: Thu, 19 Dec 2024 20:01:52 +0800 Subject: [PATCH] feat: batch revoke add alert for simulation failed (#2690) * feat: batch revoke add alert for simulation failed * feat: add debug code --- _raw/locales/en/messages.json | 3 ++- _raw/locales/zh-CN/messages.json | 3 ++- src/ui/utils/sendTransaction.ts | 13 ++++++++++++- .../components/BatchRevoke/useBatchRevokeTask.ts | 3 +++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/_raw/locales/en/messages.json b/_raw/locales/en/messages.json index 0179ae6130b..caef583b1a2 100644 --- a/_raw/locales/en/messages.json +++ b/_raw/locales/en/messages.json @@ -829,7 +829,8 @@ "ledgerSended": "Please sign the request on Ledger ({{current}}/{{total}})", "ledgerSending": "Sending signing request ({{current}}/{{total}})", "ledgerAlert": "Please open Ethereum App on your Ledger device", - "ledgerSigned": "Signed. Creating transaction ({{current}}/{{total}})" + "ledgerSigned": "Signed. Creating transaction ({{current}}/{{total}})", + "simulationFailed": "Simulation Failed" } }, "gasTopUp": { diff --git a/_raw/locales/zh-CN/messages.json b/_raw/locales/zh-CN/messages.json index 9bff6d24a19..404349bd001 100644 --- a/_raw/locales/zh-CN/messages.json +++ b/_raw/locales/zh-CN/messages.json @@ -910,7 +910,8 @@ "ledgerSigned": "签署。创建交易({{current}}/{{total}})", "ledgerSending": "正在发送签名请求({{current}}/{{total}})", "confirmRevokeLedger": "使用账本地址,您可以一键批量撤销 {{count}} 个批准。", - "confirmRevokePrivateKey": "使用助记词或私钥地址,您可以一键批量撤销 {{count}} 个批准。" + "confirmRevokePrivateKey": "使用助记词或私钥地址,您可以一键批量撤销 {{count}} 个批准。", + "simulationFailed": "交易模拟失败" } }, "connect": { diff --git a/src/ui/utils/sendTransaction.ts b/src/ui/utils/sendTransaction.ts index 3d0f26745a4..f56b08086a7 100644 --- a/src/ui/utils/sendTransaction.ts +++ b/src/ui/utils/sendTransaction.ts @@ -32,6 +32,7 @@ export enum FailedCode { GasNotEnough = 'GasNotEnough', GasTooHigh = 'GasTooHigh', SubmitTxFailed = 'SubmitTxFailed', + SimulationFailed = 'SimulationFailed', DefaultFailed = 'DefaultFailed', } @@ -255,6 +256,10 @@ export const sendTransaction = async ({ ? (await Browser.storage.local.get('DEBUG_OTHER_CHAIN_GAS_USD_LIMIT')) .DEBUG_OTHER_CHAIN_GAS_USD_LIMIT || 5 : 5; + const DEBUG_SIMULATION_FAILED = process.env.DEBUG + ? (await Browser.storage.local.get('DEBUG_SIMULATION_FAILED')) + .DEBUG_SIMULATION_FAILED + : false; // generate tx with gas const transaction: Tx = { @@ -269,7 +274,13 @@ export const sendTransaction = async ({ let failedCode; let canUseGasAccount: boolean = false; - if (isGasNotEnough) { + + // random simulation failed for test + if (DEBUG_SIMULATION_FAILED && Math.random() > 0.5) { + failedCode = FailedCode.SimulationFailed; + } else if (!preExecResult?.balance_change?.success) { + failedCode = FailedCode.SimulationFailed; + } else if (isGasNotEnough) { // native gas not enough check gasAccount if (autoUseGasAccount && gasAccount?.sig && gasAccount?.accountId) { const gasAccountCanPay = await checkEnoughUseGasAccount({ diff --git a/src/ui/views/ApprovalManagePage/components/BatchRevoke/useBatchRevokeTask.ts b/src/ui/views/ApprovalManagePage/components/BatchRevoke/useBatchRevokeTask.ts index fca8c215943..cb7a588aea0 100644 --- a/src/ui/views/ApprovalManagePage/components/BatchRevoke/useBatchRevokeTask.ts +++ b/src/ui/views/ApprovalManagePage/components/BatchRevoke/useBatchRevokeTask.ts @@ -66,6 +66,9 @@ export const FailReason = { [FailedCode.DefaultFailed]: i18n.t( 'page.approvals.revokeModal.defaultFailed' ), + [FailedCode.SimulationFailed]: i18n.t( + 'page.approvals.revokeModal.simulationFailed' + ), }; export type AssetApprovalSpenderWithStatus = AssetApprovalSpender & {