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
852e8f74
Unverified
Commit
852e8f74
authored
Jun 26, 2020
by
Moody Salem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(swap routing): max hops back to 3
parent
6694e5e3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
14 deletions
+8
-14
Trades.ts
src/hooks/Trades.ts
+8
-14
No files found.
src/hooks/Trades.ts
View file @
852e8f74
import
{
useMemo
}
from
'
react
'
import
{
Token
,
TokenAmount
,
Trade
,
Pair
}
from
'
@uniswap/sdk
'
import
{
Pair
,
Token
,
TokenAmount
,
Trade
}
from
'
@uniswap/sdk
'
import
flatMap
from
'
lodash.flatmap
'
import
{
useMemo
}
from
'
react
'
import
{
useActiveWeb3React
}
from
'
./index
'
import
{
BASES_TO_CHECK_TRADES_AGAINST
}
from
'
../constants
'
import
{
usePairs
}
from
'
../data/Reserves
'
import
{
BASES_TO_CHECK_TRADES_AGAINST
}
from
'
../constants
'
import
{
useActiveWeb3React
}
from
'
./index
'
function
useAllCommonPairs
(
tokenA
?:
Token
,
tokenB
?:
Token
):
Pair
[]
{
const
{
chainId
}
=
useActiveWeb3React
()
...
...
@@ -49,14 +49,11 @@ function useAllCommonPairs(tokenA?: Token, tokenB?: Token): Pair[] {
* Returns the best trade for the exact amount of tokens in to the given token out
*/
export
function
useTradeExactIn
(
amountIn
?:
TokenAmount
,
tokenOut
?:
Token
):
Trade
|
null
{
const
inputToken
=
amountIn
?.
token
const
outputToken
=
tokenOut
const
allowedPairs
=
useAllCommonPairs
(
inputToken
,
outputToken
)
const
allowedPairs
=
useAllCommonPairs
(
amountIn
?.
token
,
tokenOut
)
return
useMemo
(()
=>
{
if
(
amountIn
&&
tokenOut
&&
allowedPairs
.
length
>
0
)
{
return
Trade
.
bestTradeExactIn
(
allowedPairs
,
amountIn
,
tokenOut
,
{
maxHops
:
2
,
maxNumResults
:
1
})[
0
]
??
null
return
Trade
.
bestTradeExactIn
(
allowedPairs
,
amountIn
,
tokenOut
,
{
maxHops
:
3
,
maxNumResults
:
1
})[
0
]
??
null
}
return
null
},
[
allowedPairs
,
amountIn
,
tokenOut
])
...
...
@@ -66,14 +63,11 @@ export function useTradeExactIn(amountIn?: TokenAmount, tokenOut?: Token): Trade
* Returns the best trade for the token in to the exact amount of token out
*/
export
function
useTradeExactOut
(
tokenIn
?:
Token
,
amountOut
?:
TokenAmount
):
Trade
|
null
{
const
inputToken
=
tokenIn
const
outputToken
=
amountOut
?.
token
const
allowedPairs
=
useAllCommonPairs
(
inputToken
,
outputToken
)
const
allowedPairs
=
useAllCommonPairs
(
tokenIn
,
amountOut
?.
token
)
return
useMemo
(()
=>
{
if
(
tokenIn
&&
amountOut
&&
allowedPairs
.
length
>
0
)
{
return
Trade
.
bestTradeExactOut
(
allowedPairs
,
tokenIn
,
amountOut
,
{
maxHops
:
2
,
maxNumResults
:
1
})[
0
]
??
null
return
Trade
.
bestTradeExactOut
(
allowedPairs
,
tokenIn
,
amountOut
,
{
maxHops
:
3
,
maxNumResults
:
1
})[
0
]
??
null
}
return
null
},
[
allowedPairs
,
tokenIn
,
amountOut
])
...
...
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