Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
e589c751
Unverified
Commit
e589c751
authored
Aug 10, 2020
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improvement(swap errors): show more information about the swap error
parent
0f91af1d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
useSwapCallback.ts
src/hooks/useSwapCallback.ts
+6
-6
No files found.
src/hooks/useSwapCallback.ts
View file @
e589c751
...
@@ -104,8 +104,6 @@ function useSwapCallArguments(
...
@@ -104,8 +104,6 @@ function useSwapCallArguments(
},
[
account
,
allowedSlippage
,
chainId
,
deadline
,
library
,
recipient
,
trade
,
v1Exchange
])
},
[
account
,
allowedSlippage
,
chainId
,
deadline
,
library
,
recipient
,
trade
,
v1Exchange
])
}
}
const
DEFAULT_FAILED_SWAP_ERROR
=
'
Unexpected error. Please try again or contact support.
'
// returns a function that will execute a swap, if the parameters are all valid
// returns a function that will execute a swap, if the parameters are all valid
// and the user has approved the slippage adjusted input amount for the trade
// and the user has approved the slippage adjusted input amount for the trade
export
function
useSwapCallback
(
export
function
useSwapCallback
(
...
@@ -161,17 +159,19 @@ export function useSwapCallback(
...
@@ -161,17 +159,19 @@ export function useSwapCallback(
return
contract
.
callStatic
[
methodName
](...
args
,
options
)
return
contract
.
callStatic
[
methodName
](...
args
,
options
)
.
then
(
result
=>
{
.
then
(
result
=>
{
console
.
debug
(
'
Unexpected successful call after failed estimate gas
'
,
call
,
gasError
,
result
)
console
.
debug
(
'
Unexpected successful call after failed estimate gas
'
,
call
,
gasError
,
result
)
return
{
call
,
error
:
new
Error
(
DEFAULT_FAILED_SWAP_ERROR
)
}
return
{
call
,
error
:
new
Error
(
'
Unexpected issue with estimating the gas. Please try again.
'
)
}
})
})
.
catch
(
callError
=>
{
.
catch
(
callError
=>
{
console
.
debug
(
'
Call threw error
'
,
call
,
callError
)
console
.
debug
(
'
Call threw error
'
,
call
,
callError
)
let
errorMessage
:
string
=
DEFAULT_FAILED_SWAP_ERROR
let
errorMessage
:
string
switch
(
callError
.
reason
)
{
switch
(
callError
.
reason
)
{
case
'
UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT
'
:
case
'
UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT
'
:
case
'
UniswapV2Router: EXCESSIVE_INPUT_AMOUNT
'
:
case
'
UniswapV2Router: EXCESSIVE_INPUT_AMOUNT
'
:
errorMessage
=
errorMessage
=
'
This transaction will not succeed either due to price movement or fee on transfer. Try increasing your slippage tolerance.
'
'
This transaction will not succeed either due to price movement or fee on transfer. Try increasing your slippage tolerance.
'
break
break
default
:
errorMessage
=
`The transaction cannot succeed due to error:
${
callError
.
reason
}
. This is probably an issue with one of the tokens you are swapping.`
}
}
return
{
call
,
error
:
new
Error
(
errorMessage
)
}
return
{
call
,
error
:
new
Error
(
errorMessage
)
}
})
})
...
@@ -188,7 +188,7 @@ export function useSwapCallback(
...
@@ -188,7 +188,7 @@ export function useSwapCallback(
if
(
!
successfulEstimation
)
{
if
(
!
successfulEstimation
)
{
const
errorCalls
=
estimatedCalls
.
filter
((
call
):
call
is
FailedCall
=>
'
error
'
in
call
)
const
errorCalls
=
estimatedCalls
.
filter
((
call
):
call
is
FailedCall
=>
'
error
'
in
call
)
if
(
errorCalls
.
length
>
0
)
throw
errorCalls
[
errorCalls
.
length
-
1
].
error
if
(
errorCalls
.
length
>
0
)
throw
errorCalls
[
errorCalls
.
length
-
1
].
error
throw
new
Error
(
DEFAULT_FAILED_SWAP_ERROR
)
throw
new
Error
(
'
Unexpected error. Please contact support: none of the calls threw an error
'
)
}
}
const
{
const
{
...
@@ -235,7 +235,7 @@ export function useSwapCallback(
...
@@ -235,7 +235,7 @@ export function useSwapCallback(
}
else
{
}
else
{
// otherwise, the error was unexpected and we need to convey that
// otherwise, the error was unexpected and we need to convey that
console
.
error
(
`Swap failed`
,
error
,
methodName
,
args
,
value
)
console
.
error
(
`Swap failed`
,
error
,
methodName
,
args
,
value
)
throw
new
Error
(
DEFAULT_FAILED_SWAP_ERROR
)
throw
new
Error
(
`Swap failed:
${
error
.
message
}
`
)
}
}
})
})
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment