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
442879cc
Unverified
Commit
442879cc
authored
Oct 13, 2021
by
Justin Domingue
Committed by
GitHub
Oct 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve fee tier selector (#2609)
parent
50386f65
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
27 deletions
+90
-27
index.tsx
src/components/FeeSelector/index.tsx
+73
-7
useFeeTierDistribution.ts
src/hooks/useFeeTierDistribution.ts
+17
-20
No files found.
src/components/FeeSelector/index.tsx
View file @
442879cc
...
@@ -7,9 +7,10 @@ import Card from 'components/Card'
...
@@ -7,9 +7,10 @@ import Card from 'components/Card'
import
{
AutoColumn
}
from
'
components/Column
'
import
{
AutoColumn
}
from
'
components/Column
'
import
{
RowBetween
}
from
'
components/Row
'
import
{
RowBetween
}
from
'
components/Row
'
import
{
useFeeTierDistribution
}
from
'
hooks/useFeeTierDistribution
'
import
{
useFeeTierDistribution
}
from
'
hooks/useFeeTierDistribution
'
import
{
PoolState
,
usePools
}
from
'
hooks/usePools
'
import
usePrevious
from
'
hooks/usePrevious
'
import
usePrevious
from
'
hooks/usePrevious
'
import
{
DynamicSection
}
from
'
pages/AddLiquidity/styled
'
import
{
DynamicSection
}
from
'
pages/AddLiquidity/styled
'
import
React
,
{
useCallback
,
useEffect
,
useRef
,
useState
}
from
'
react
'
import
React
,
{
useCallback
,
useEffect
,
use
Memo
,
use
Ref
,
useState
}
from
'
react
'
import
ReactGA
from
'
react-ga
'
import
ReactGA
from
'
react-ga
'
import
{
Box
}
from
'
rebass
'
import
{
Box
}
from
'
rebass
'
import
styled
,
{
keyframes
}
from
'
styled-components/macro
'
import
styled
,
{
keyframes
}
from
'
styled-components/macro
'
...
@@ -58,11 +59,25 @@ const FeeAmountLabel = {
...
@@ -58,11 +59,25 @@ const FeeAmountLabel = {
},
},
}
}
const
FeeTierPercentageBadge
=
({
percentage
}:
{
percentage
:
number
|
undefined
})
=>
{
function
FeeTierPercentageBadge
({
feeAmount
,
distributions
,
poolState
,
}:
{
feeAmount
:
FeeAmount
distributions
:
ReturnType
<
typeof
useFeeTierDistribution
>
[
'
distributions
'
]
poolState
:
PoolState
})
{
return
(
return
(
<
Badge
>
<
Badge
>
<
TYPE
.
label
fontSize=
{
12
}
>
<
TYPE
.
label
fontSize=
{
12
}
>
{
percentage
!==
undefined
?
<
Trans
>
{
percentage
?.
toFixed
(
0
)
}
% select
</
Trans
>
:
<
Trans
>
Not created
</
Trans
>
}
{
!
distributions
||
poolState
===
PoolState
.
NOT_EXISTS
||
poolState
===
PoolState
.
INVALID
?
(
<
Trans
>
Not created
</
Trans
>
)
:
distributions
[
feeAmount
]
!==
undefined
?
(
<
Trans
>
{
distributions
[
feeAmount
]?.
toFixed
(
0
)
}
% select
</
Trans
>
)
:
(
<
Trans
>
No data
</
Trans
>
)
}
</
TYPE
.
label
>
</
TYPE
.
label
>
</
Badge
>
</
Badge
>
)
)
...
@@ -83,6 +98,33 @@ export default function FeeSelector({
...
@@ -83,6 +98,33 @@ export default function FeeSelector({
})
{
})
{
const
{
isLoading
,
isError
,
largestUsageFeeTier
,
distributions
}
=
useFeeTierDistribution
(
currencyA
,
currencyB
)
const
{
isLoading
,
isError
,
largestUsageFeeTier
,
distributions
}
=
useFeeTierDistribution
(
currencyA
,
currencyB
)
// get pool data on-chain for latest states
const
pools
=
usePools
([
[
currencyA
,
currencyB
,
FeeAmount
.
LOW
],
[
currencyA
,
currencyB
,
FeeAmount
.
MEDIUM
],
[
currencyA
,
currencyB
,
FeeAmount
.
HIGH
],
])
const
poolsByFeeTier
=
useMemo
(
()
=>
pools
.
reduce
(
(
acc
,
[
curPoolState
,
curPool
])
=>
{
acc
=
{
...
acc
,
...{
[
curPool
?.
fee
as
FeeAmount
]:
curPoolState
},
}
return
acc
},
{
// default all states to NOT_EXISTS
[
FeeAmount
.
LOW
]:
PoolState
.
NOT_EXISTS
,
[
FeeAmount
.
MEDIUM
]:
PoolState
.
NOT_EXISTS
,
[
FeeAmount
.
HIGH
]:
PoolState
.
NOT_EXISTS
,
}
),
[
pools
]
)
const
[
showOptions
,
setShowOptions
]
=
useState
(
false
)
const
[
showOptions
,
setShowOptions
]
=
useState
(
false
)
const
[
pulsing
,
setPulsing
]
=
useState
(
false
)
const
[
pulsing
,
setPulsing
]
=
useState
(
false
)
...
@@ -153,7 +195,13 @@ export default function FeeSelector({
...
@@ -153,7 +195,13 @@ export default function FeeSelector({
<
Trans
>
{
FeeAmountLabel
[
feeAmount
].
label
}
% fee tier
</
Trans
>
<
Trans
>
{
FeeAmountLabel
[
feeAmount
].
label
}
% fee tier
</
Trans
>
</
TYPE
.
label
>
</
TYPE
.
label
>
<
Box
style=
{
{
width
:
'
fit-content
'
,
marginTop
:
'
8px
'
}
}
className=
"selected-fee-percentage"
>
<
Box
style=
{
{
width
:
'
fit-content
'
,
marginTop
:
'
8px
'
}
}
className=
"selected-fee-percentage"
>
{
distributions
&&
feeAmount
&&
<
FeeTierPercentageBadge
percentage=
{
distributions
[
feeAmount
]
}
/>
}
{
distributions
&&
(
<
FeeTierPercentageBadge
distributions=
{
distributions
}
feeAmount=
{
feeAmount
}
poolState=
{
poolsByFeeTier
[
feeAmount
]
}
/>
)
}
</
Box
>
</
Box
>
</>
</>
)
}
)
}
...
@@ -182,7 +230,13 @@ export default function FeeSelector({
...
@@ -182,7 +230,13 @@ export default function FeeSelector({
</
TYPE
.
main
>
</
TYPE
.
main
>
</
AutoColumn
>
</
AutoColumn
>
{
distributions
&&
<
FeeTierPercentageBadge
percentage=
{
distributions
[
FeeAmount
.
LOW
]
}
/>
}
{
distributions
&&
(
<
FeeTierPercentageBadge
distributions=
{
distributions
}
feeAmount=
{
FeeAmount
.
LOW
}
poolState=
{
poolsByFeeTier
[
FeeAmount
.
LOW
]
}
/>
)
}
</
AutoColumn
>
</
AutoColumn
>
</
ButtonRadioChecked
>
</
ButtonRadioChecked
>
<
ButtonRadioChecked
<
ButtonRadioChecked
...
@@ -200,7 +254,13 @@ export default function FeeSelector({
...
@@ -200,7 +254,13 @@ export default function FeeSelector({
</
TYPE
.
main
>
</
TYPE
.
main
>
</
AutoColumn
>
</
AutoColumn
>
{
distributions
&&
<
FeeTierPercentageBadge
percentage=
{
distributions
[
FeeAmount
.
MEDIUM
]
}
/>
}
{
distributions
&&
(
<
FeeTierPercentageBadge
distributions=
{
distributions
}
feeAmount=
{
FeeAmount
.
MEDIUM
}
poolState=
{
poolsByFeeTier
[
FeeAmount
.
MEDIUM
]
}
/>
)
}
</
AutoColumn
>
</
AutoColumn
>
</
ButtonRadioChecked
>
</
ButtonRadioChecked
>
<
ButtonRadioChecked
<
ButtonRadioChecked
...
@@ -218,7 +278,13 @@ export default function FeeSelector({
...
@@ -218,7 +278,13 @@ export default function FeeSelector({
</
TYPE
.
main
>
</
TYPE
.
main
>
</
AutoColumn
>
</
AutoColumn
>
{
distributions
&&
<
FeeTierPercentageBadge
percentage=
{
distributions
[
FeeAmount
.
HIGH
]
}
/>
}
{
distributions
&&
(
<
FeeTierPercentageBadge
distributions=
{
distributions
}
feeAmount=
{
FeeAmount
.
HIGH
}
poolState=
{
poolsByFeeTier
[
FeeAmount
.
HIGH
]
}
/>
)
}
</
AutoColumn
>
</
AutoColumn
>
</
ButtonRadioChecked
>
</
ButtonRadioChecked
>
</
RowBetween
>
</
RowBetween
>
...
...
src/hooks/useFeeTierDistribution.ts
View file @
442879cc
...
@@ -144,18 +144,8 @@ function usePoolTVL(token0: Token | undefined, token1: Token | undefined) {
...
@@ -144,18 +144,8 @@ function usePoolTVL(token0: Token | undefined, token1: Token | undefined) {
const
mean
=
(
tvl0
:
number
|
undefined
,
sumTvl0
:
number
,
tvl1
:
number
|
undefined
,
sumTvl1
:
number
)
=>
const
mean
=
(
tvl0
:
number
|
undefined
,
sumTvl0
:
number
,
tvl1
:
number
|
undefined
,
sumTvl1
:
number
)
=>
tvl0
===
undefined
&&
tvl1
===
undefined
?
undefined
:
((
tvl0
??
0
)
+
(
tvl1
??
0
))
/
(
sumTvl0
+
sumTvl1
)
||
0
tvl0
===
undefined
&&
tvl1
===
undefined
?
undefined
:
((
tvl0
??
0
)
+
(
tvl1
??
0
))
/
(
sumTvl0
+
sumTvl1
)
||
0
return
{
const
distributions
=
{
isLoading
,
[
FeeAmount
.
LOW
]:
mean
(
tvlByFeeTier
[
FeeAmount
.
LOW
][
0
],
sumToken0Tvl
,
tvlByFeeTier
[
FeeAmount
.
LOW
][
1
],
sumToken1Tvl
),
isFetching
,
isUninitialized
,
isError
,
distributions
:
{
[
FeeAmount
.
LOW
]:
mean
(
tvlByFeeTier
[
FeeAmount
.
LOW
][
0
],
sumToken0Tvl
,
tvlByFeeTier
[
FeeAmount
.
LOW
][
1
],
sumToken1Tvl
),
[
FeeAmount
.
MEDIUM
]:
mean
(
[
FeeAmount
.
MEDIUM
]:
mean
(
tvlByFeeTier
[
FeeAmount
.
MEDIUM
][
0
],
tvlByFeeTier
[
FeeAmount
.
MEDIUM
][
0
],
sumToken0Tvl
,
sumToken0Tvl
,
...
@@ -168,7 +158,14 @@ function usePoolTVL(token0: Token | undefined, token1: Token | undefined) {
...
@@ -168,7 +158,14 @@ function usePoolTVL(token0: Token | undefined, token1: Token | undefined) {
tvlByFeeTier
[
FeeAmount
.
HIGH
][
1
],
tvlByFeeTier
[
FeeAmount
.
HIGH
][
1
],
sumToken1Tvl
sumToken1Tvl
),
),
},
}
return
{
isLoading
,
isFetching
,
isUninitialized
,
isError
,
distributions
,
}
}
},
[
_meta
,
asToken0
,
asToken1
,
isLoading
,
isError
,
isFetching
,
isUninitialized
,
latestBlock
])
},
[
_meta
,
asToken0
,
asToken1
,
isLoading
,
isError
,
isFetching
,
isUninitialized
,
latestBlock
])
}
}
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