fix: handle user rejection (#5576)

This commit is contained in:
Zach Pomerantz 2022-12-07 21:40:40 -08:00 committed by GitHub
parent 78e438294f
commit dbdd3a8e16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

@ -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