From 63d2eb2e49b014ae7f5ca00f01bf259f0d9e3574 Mon Sep 17 00:00:00 2001 From: heisenberg Date: Wed, 18 Dec 2024 12:25:39 +0800 Subject: [PATCH] feat: batch revoke add alert for simulation failed --- _raw/locales/en/messages.json | 3 ++- _raw/locales/zh-CN/messages.json | 3 ++- src/ui/utils/sendTransaction.ts | 6 +++++- .../components/BatchRevoke/useBatchRevokeTask.ts | 3 +++ 4 files changed, 12 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..f4b80a03e10 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', } @@ -269,7 +270,10 @@ export const sendTransaction = async ({ let failedCode; let canUseGasAccount: boolean = false; - if (isGasNotEnough) { + + 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 & {