fix: handle user rejection (#5576)
This commit is contained in:
parent
78e438294f
commit
dbdd3a8e16
@ -64,7 +64,7 @@ export function useUniversalRouterSwapCallback(
|
||||
return response
|
||||
} catch (swapError: unknown) {
|
||||
const message = swapErrorToUserReadableMessage(swapError)
|
||||
throw new Error(`Trade failed: ${message}`)
|
||||
throw new Error(message)
|
||||
}
|
||||
}, [
|
||||
account,
|
||||
|
@ -7,6 +7,14 @@ import { t } from '@lingui/macro'
|
||||
*/
|
||||
export function swapErrorToUserReadableMessage(error: any): string {
|
||||
let reason: string | undefined
|
||||
|
||||
if (error.code) {
|
||||
switch (error.code) {
|
||||
case 4001:
|
||||
return t`Transaction rejected`
|
||||
}
|
||||
}
|
||||
|
||||
while (Boolean(error)) {
|
||||
reason = error.reason ?? error.message ?? reason
|
||||
error = error.error ?? error.data?.originalError
|
||||
|
Loading…
Reference in New Issue
Block a user