Commit 527270e3 authored by lynn's avatar lynn Committed by GitHub

fix: handle wallets that don't send default 4001 error code for user rejected txns (#5941)

* init

* add more to comment

* zzmp comments

* regex

* oops

* fix
parent 18cd5ec9
...@@ -22,6 +22,21 @@ export function swapErrorToUserReadableMessage(error: any): string { ...@@ -22,6 +22,21 @@ export function swapErrorToUserReadableMessage(error: any): string {
error = error.error ?? error.data?.originalError error = error.error ?? error.data?.originalError
} }
// The 4001 error code doesn't capture the case where users reject a transaction for all wallets,
// so we need to parse the reason for these special cases:
if (
// For Rainbow :
(reason?.match(/request/i) && reason?.match(/reject/i)) ||
// For Frame:
reason?.match(/declined/i) ||
// For SafePal:
reason?.match(/cancelled by user/i) ||
// For Coinbase:
reason?.match(/user denied/i)
) {
return t`Transaction rejected`
}
if (reason?.indexOf('execution reverted: ') === 0) reason = reason.substr('execution reverted: '.length) if (reason?.indexOf('execution reverted: ') === 0) reason = reason.substr('execution reverted: '.length)
switch (reason) { switch (reason) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment