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

This commit is contained in:
Zach Pomerantz 2023-01-18 20:53:20 -08:00 committed by GitHub
parent a534ba41ed
commit 43218d5655
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

@ -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.`
}
}