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
This commit is contained in:
lynn 2023-02-08 13:34:21 -05:00 committed by GitHub
parent 18cd5ec9d9
commit 527270e33f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -22,6 +22,21 @@ export function swapErrorToUserReadableMessage(error: any): string {
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)
switch (reason) {