Commit 3acbcbc6 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

fix: err and warn if user modifies tx (#5210)

* fix: err and warn if user modifies tx

* fix: update message

* fix: clarify swap error name
parent 7b086848
......@@ -29,6 +29,8 @@ interface FailedCall extends SwapCallEstimate {
error: Error
}
class InvalidSwapError extends Error {}
// returns a function that will execute a swap, if the parameters are all valid
export default function useSendSwapTransaction(
account: string | null | undefined,
......@@ -114,6 +116,11 @@ export default function useSendSwapTransaction(
...(value && !isZero(value) ? { value } : {}),
})
.then((response) => {
if (calldata !== response.data) {
throw new InvalidSwapError(
t`Your swap was modified through your wallet. If this was a mistake, please cancel immediately or risk losing your funds.`
)
}
return response
})
.catch((error) => {
......@@ -124,8 +131,12 @@ export default function useSendSwapTransaction(
// otherwise, the error was unexpected and we need to convey that
console.error(`Swap failed`, error, address, calldata, value)
if (error instanceof InvalidSwapError) {
throw error
} else {
throw new Error(t`Swap failed: ${swapErrorToUserReadableMessage(error)}`)
}
}
})
},
}
......
......@@ -59,7 +59,6 @@ export function swapErrorToUserReadableMessage(error: any): ReactNode {
)
default:
if (reason?.indexOf('undefined is not an object') !== -1) {
console.error(error, reason)
return (
<Trans>
An error occurred when trying to execute this swap. You may need to increase your slippage tolerance. If
......
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