Commit dbdd3a8e authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

fix: handle user rejection (#5576)

parent 78e43829
...@@ -64,7 +64,7 @@ export function useUniversalRouterSwapCallback( ...@@ -64,7 +64,7 @@ export function useUniversalRouterSwapCallback(
return response return response
} catch (swapError: unknown) { } catch (swapError: unknown) {
const message = swapErrorToUserReadableMessage(swapError) const message = swapErrorToUserReadableMessage(swapError)
throw new Error(`Trade failed: ${message}`) throw new Error(message)
} }
}, [ }, [
account, account,
......
...@@ -7,6 +7,14 @@ import { t } from '@lingui/macro' ...@@ -7,6 +7,14 @@ import { t } from '@lingui/macro'
*/ */
export function swapErrorToUserReadableMessage(error: any): string { export function swapErrorToUserReadableMessage(error: any): string {
let reason: string | undefined let reason: string | undefined
if (error.code) {
switch (error.code) {
case 4001:
return t`Transaction rejected`
}
}
while (Boolean(error)) { while (Boolean(error)) {
reason = error.reason ?? error.message ?? reason reason = error.reason ?? error.message ?? reason
error = error.error ?? error.data?.originalError error = error.error ?? error.data?.originalError
......
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