Commit 43218d56 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

feat: retry gas estimate and log to console (#5856)

parent a534ba41
......@@ -51,7 +51,8 @@ export function useUniversalRouterSwapCallback(
gasEstimate = await provider.estimateGas(tx)
} catch (gasError) {
await provider.call(tx) // this should throw the actual error
throw new Error('unexpected issue with gas estimation; please try again')
// If the actual error is not thrown, just try again:
gasEstimate = await provider.estimateGas(tx)
}
const gasLimit = calculateGasMargin(gasEstimate)
const response = await provider.getSigner().sendTransaction({ ...tx, gasLimit })
......
......@@ -15,6 +15,8 @@ export function swapErrorToUserReadableMessage(error: any): string {
}
}
console.warn('Swap error:', error)
while (error) {
reason = error.reason ?? error.message ?? reason
error = error.error ?? error.data?.originalError
......@@ -44,8 +46,7 @@ export function swapErrorToUserReadableMessage(error: any): string {
if (reason?.indexOf('undefined is not an object') !== -1) {
return t`An error occurred when trying to execute this swap. You may need to increase your slippage tolerance. If that does not work, there may be an incompatibility with the token you are trading. Note: fee on transfer and rebase tokens are incompatible with Uniswap V3.`
}
return t`Unknown error${
reason ? `: "${reason}"` : ''
}. Try increasing your slippage tolerance. Note: fee on transfer and rebase tokens are incompatible with Uniswap V3.`
return t`Unknown error${reason ? `: "${reason}"` : ''}. Try increasing your slippage tolerance.
Note: fee on transfer and rebase tokens are incompatible with Uniswap V3.`
}
}
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