Skip to content

Commit

Permalink
feat: batch revoke add alert for simulation failed (#2690)
Browse files Browse the repository at this point in the history
* feat: batch revoke add alert for simulation failed

* feat: add debug code
  • Loading branch information
heisenberg-2077 authored Dec 19, 2024
1 parent 46764de commit ef71379
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion _raw/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion _raw/locales/zh-CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,8 @@
"ledgerSigned": "签署。创建交易({{current}}/{{total}})",
"ledgerSending": "正在发送签名请求({{current}}/{{total}})",
"confirmRevokeLedger": "使用账本地址,您可以一键批量撤销 {{count}} 个批准。",
"confirmRevokePrivateKey": "使用助记词或私钥地址,您可以一键批量撤销 {{count}} 个批准。"
"confirmRevokePrivateKey": "使用助记词或私钥地址,您可以一键批量撤销 {{count}} 个批准。",
"simulationFailed": "交易模拟失败"
}
},
"connect": {
Expand Down
13 changes: 12 additions & 1 deletion src/ui/utils/sendTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export enum FailedCode {
GasNotEnough = 'GasNotEnough',
GasTooHigh = 'GasTooHigh',
SubmitTxFailed = 'SubmitTxFailed',
SimulationFailed = 'SimulationFailed',
DefaultFailed = 'DefaultFailed',
}

Expand Down Expand Up @@ -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 = {
Expand All @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 & {
Expand Down

0 comments on commit ef71379

Please sign in to comment.