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
28bf9512
Unverified
Commit
28bf9512
authored
Jul 12, 2021
by
Justin Domingue
Committed by
GitHub
Jul 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
load pool data for each tier to determine state (#2026)
parent
b1d88317
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
19 deletions
+36
-19
index.tsx
src/components/FeeSelector/index.tsx
+7
-7
useFeeTierDistribution.ts
src/hooks/useFeeTierDistribution.ts
+27
-10
index.tsx
src/pages/AddLiquidity/index.tsx
+2
-2
No files found.
src/components/FeeSelector/index.tsx
View file @
28bf9512
import
React
,
{
useCallback
,
useEffect
,
useRef
,
useState
}
from
'
react
'
import
React
,
{
useCallback
,
useEffect
,
useRef
,
useState
}
from
'
react
'
import
{
FeeAmount
}
from
'
@uniswap/v3-sdk
'
import
{
FeeAmount
}
from
'
@uniswap/v3-sdk
'
import
{
Token
}
from
'
@uniswap/sdk-core
'
import
{
Currency
}
from
'
@uniswap/sdk-core
'
import
{
Trans
}
from
'
@lingui/macro
'
import
{
Trans
}
from
'
@lingui/macro
'
import
{
AutoColumn
}
from
'
components/Column
'
import
{
AutoColumn
}
from
'
components/Column
'
import
{
DynamicSection
}
from
'
pages/AddLiquidity/styled
'
import
{
DynamicSection
}
from
'
pages/AddLiquidity/styled
'
...
@@ -62,7 +62,7 @@ const FeeTierPercentageBadge = ({ percentage }: { percentage: number | undefined
...
@@ -62,7 +62,7 @@ const FeeTierPercentageBadge = ({ percentage }: { percentage: number | undefined
return
(
return
(
<
Badge
>
<
Badge
>
<
TYPE
.
label
fontSize=
{
12
}
>
<
TYPE
.
label
fontSize=
{
12
}
>
{
Boolean
(
percentage
)
?
<
Trans
>
{
percentage
?.
toFixed
(
0
)
}
% select
</
Trans
>
:
<
Trans
>
Not created
</
Trans
>
}
{
percentage
!==
undefined
?
<
Trans
>
{
percentage
?.
toFixed
(
0
)
}
% select
</
Trans
>
:
<
Trans
>
Not created
</
Trans
>
}
</
TYPE
.
label
>
</
TYPE
.
label
>
</
Badge
>
</
Badge
>
)
)
...
@@ -72,16 +72,16 @@ export default function FeeSelector({
...
@@ -72,16 +72,16 @@ export default function FeeSelector({
disabled
=
false
,
disabled
=
false
,
feeAmount
,
feeAmount
,
handleFeePoolSelect
,
handleFeePoolSelect
,
token0
,
currencyA
,
token1
,
currencyB
,
}:
{
}:
{
disabled
?:
boolean
disabled
?:
boolean
feeAmount
?:
FeeAmount
feeAmount
?:
FeeAmount
handleFeePoolSelect
:
(
feeAmount
:
FeeAmount
)
=>
void
handleFeePoolSelect
:
(
feeAmount
:
FeeAmount
)
=>
void
token0
?:
Token
|
undefined
currencyA
?:
Currency
|
undefined
token1
?:
Token
|
undefined
currencyB
?:
Currency
|
undefined
})
{
})
{
const
{
isLoading
,
isError
,
largestUsageFeeTier
,
distributions
}
=
useFeeTierDistribution
(
token0
,
token1
)
const
{
isLoading
,
isError
,
largestUsageFeeTier
,
distributions
}
=
useFeeTierDistribution
(
currencyA
,
currencyB
)
const
[
showOptions
,
setShowOptions
]
=
useState
(
false
)
const
[
showOptions
,
setShowOptions
]
=
useState
(
false
)
const
[
pulsing
,
setPulsing
]
=
useState
(
false
)
const
[
pulsing
,
setPulsing
]
=
useState
(
false
)
...
...
src/hooks/useFeeTierDistribution.ts
View file @
28bf9512
import
{
FeeAmount
}
from
'
@uniswap/v3-sdk
'
import
{
FeeAmount
}
from
'
@uniswap/v3-sdk
'
import
{
Token
}
from
'
@uniswap/sdk-core
'
import
{
Token
,
Currency
}
from
'
@uniswap/sdk-core
'
import
{
useFeeTierDistributionQuery
}
from
'
state/data/enhanced
'
import
{
useFeeTierDistributionQuery
}
from
'
state/data/enhanced
'
import
{
skipToken
}
from
'
@reduxjs/toolkit/query/react
'
import
{
skipToken
}
from
'
@reduxjs/toolkit/query/react
'
import
{
reduce
}
from
'
lodash
'
import
{
reduce
}
from
'
lodash
'
...
@@ -8,6 +8,7 @@ import ReactGA from 'react-ga'
...
@@ -8,6 +8,7 @@ import ReactGA from 'react-ga'
import
{
useMemo
}
from
'
react
'
import
{
useMemo
}
from
'
react
'
import
{
FeeTierDistributionQuery
}
from
'
state/data/generated
'
import
{
FeeTierDistributionQuery
}
from
'
state/data/generated
'
import
ms
from
'
ms.macro
'
import
ms
from
'
ms.macro
'
import
{
PoolState
,
usePool
}
from
'
./usePools
'
// maximum number of blocks past which we consider the data stale
// maximum number of blocks past which we consider the data stale
const
MAX_DATA_BLOCK_AGE
=
10
const
MAX_DATA_BLOCK_AGE
=
10
...
@@ -25,8 +26,19 @@ interface FeeTierDistribution {
...
@@ -25,8 +26,19 @@ interface FeeTierDistribution {
}
}
}
}
export
function
useFeeTierDistribution
(
token0
:
Token
|
undefined
,
token1
:
Token
|
undefined
):
FeeTierDistribution
{
export
function
useFeeTierDistribution
(
const
{
isFetching
,
isLoading
,
isUninitialized
,
isError
,
distributions
}
=
usePoolTVL
(
token0
,
token1
)
currencyA
:
Currency
|
undefined
,
currencyB
:
Currency
|
undefined
):
FeeTierDistribution
{
const
{
isFetching
,
isLoading
,
isUninitialized
,
isError
,
distributions
}
=
usePoolTVL
(
currencyA
?.
wrapped
,
currencyB
?.
wrapped
)
// fetch all pool states to determine pool state
const
[
poolStateLow
]
=
usePool
(
currencyA
,
currencyB
,
FeeAmount
.
LOW
)
const
[
poolStateMedium
]
=
usePool
(
currencyA
,
currencyB
,
FeeAmount
.
MEDIUM
)
const
[
poolStateHigh
]
=
usePool
(
currencyA
,
currencyB
,
FeeAmount
.
HIGH
)
return
useMemo
(()
=>
{
return
useMemo
(()
=>
{
if
(
isLoading
||
isFetching
||
isUninitialized
||
isError
||
!
distributions
)
{
if
(
isLoading
||
isFetching
||
isUninitialized
||
isError
||
!
distributions
)
{
...
@@ -43,13 +55,18 @@ export function useFeeTierDistribution(token0: Token | undefined, token1: Token
...
@@ -43,13 +55,18 @@ export function useFeeTierDistribution(token0: Token | undefined, token1: Token
.
reduce
((
a
:
FeeAmount
,
b
:
FeeAmount
)
=>
((
distributions
[
a
]
??
0
)
>
(
distributions
[
b
]
??
0
)
?
a
:
b
),
-
1
)
.
reduce
((
a
:
FeeAmount
,
b
:
FeeAmount
)
=>
((
distributions
[
a
]
??
0
)
>
(
distributions
[
b
]
??
0
)
?
a
:
b
),
-
1
)
const
percentages
=
const
percentages
=
!
isLoading
&&
!
isError
&&
distributions
!
isLoading
&&
!
isError
&&
distributions
&&
poolStateLow
!==
PoolState
.
LOADING
&&
poolStateMedium
!==
PoolState
.
LOADING
&&
poolStateHigh
!==
PoolState
.
LOADING
?
{
?
{
[
FeeAmount
.
LOW
]:
distributions
[
FeeAmount
.
LOW
]
?
(
distributions
[
FeeAmount
.
LOW
]
??
0
)
*
100
:
undefined
,
[
FeeAmount
.
LOW
]:
poolStateLow
===
PoolState
.
EXISTS
?
(
distributions
[
FeeAmount
.
LOW
]
??
0
)
*
100
:
undefined
,
[
FeeAmount
.
MEDIUM
]:
distributions
[
FeeAmount
.
MEDIUM
]
[
FeeAmount
.
MEDIUM
]:
?
(
distributions
[
FeeAmount
.
MEDIUM
]
??
0
)
*
100
poolStateMedium
===
PoolState
.
EXISTS
?
(
distributions
[
FeeAmount
.
MEDIUM
]
??
0
)
*
100
:
undefined
,
:
undefined
,
[
FeeAmount
.
HIGH
]:
[
FeeAmount
.
HIGH
]:
distributions
[
FeeAmount
.
HIGH
]
?
(
distributions
[
FeeAmount
.
HIGH
]
??
0
)
*
100
:
undefined
,
poolStateHigh
===
PoolState
.
EXISTS
?
(
distributions
[
FeeAmount
.
HIGH
]
??
0
)
*
100
:
undefined
,
}
}
:
undefined
:
undefined
...
@@ -59,7 +76,7 @@ export function useFeeTierDistribution(token0: Token | undefined, token1: Token
...
@@ -59,7 +76,7 @@ export function useFeeTierDistribution(token0: Token | undefined, token1: Token
distributions
:
percentages
,
distributions
:
percentages
,
largestUsageFeeTier
:
largestUsageFeeTier
===
-
1
?
undefined
:
largestUsageFeeTier
,
largestUsageFeeTier
:
largestUsageFeeTier
===
-
1
?
undefined
:
largestUsageFeeTier
,
}
}
},
[
isLoading
,
isFetching
,
isUninitialized
,
isError
,
distributions
])
},
[
isLoading
,
isFetching
,
isUninitialized
,
isError
,
distributions
,
poolStateLow
,
poolStateMedium
,
poolStateHigh
])
}
}
function
usePoolTVL
(
token0
:
Token
|
undefined
,
token1
:
Token
|
undefined
)
{
function
usePoolTVL
(
token0
:
Token
|
undefined
,
token1
:
Token
|
undefined
)
{
...
...
src/pages/AddLiquidity/index.tsx
View file @
28bf9512
...
@@ -652,8 +652,8 @@ export default function AddLiquidity({
...
@@ -652,8 +652,8 @@ export default function AddLiquidity({
disabled=
{
!
currencyB
||
!
currencyA
}
disabled=
{
!
currencyB
||
!
currencyA
}
feeAmount=
{
feeAmount
}
feeAmount=
{
feeAmount
}
handleFeePoolSelect=
{
handleFeePoolSelect
}
handleFeePoolSelect=
{
handleFeePoolSelect
}
token0=
{
currencyA
?.
wrapp
ed
}
currencyA=
{
currencyA
??
undefin
ed
}
token1=
{
currencyB
?.
wrapp
ed
}
currencyB=
{
currencyB
??
undefin
ed
}
/>
/>
</
AutoColumn
>
{
'
'
}
</
AutoColumn
>
{
'
'
}
</>
</>
...
...
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