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
cf5c67ec
Unverified
Commit
cf5c67ec
authored
Mar 26, 2020
by
Ian Lapham
Committed by
GitHub
Mar 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix rerender bugs (#666)
parent
eaf8d5a3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
15 additions
and
26 deletions
+15
-26
index.js
src/components/PositionCard/index.js
+1
-1
Balances.tsx
src/contexts/Balances.tsx
+1
-7
Pairs.tsx
src/contexts/Pairs.tsx
+10
-9
Routes.tsx
src/contexts/Routes.tsx
+1
-7
AddLiquidity.tsx
src/pages/Supply/AddLiquidity.tsx
+1
-1
RemoveLiquidity.tsx
src/pages/Supply/RemoveLiquidity.tsx
+1
-1
No files found.
src/components/PositionCard/index.js
View file @
cf5c67ec
...
@@ -30,7 +30,7 @@ function PositionCard({ pairAddress, token0, token1, history, minimal = false, .
...
@@ -30,7 +30,7 @@ function PositionCard({ pairAddress, token0, token1, history, minimal = false, .
const
pair
=
tokenAmount0
&&
tokenAmount1
&&
new
Pair
(
tokenAmount0
,
tokenAmount1
)
const
pair
=
tokenAmount0
&&
tokenAmount1
&&
new
Pair
(
tokenAmount0
,
tokenAmount1
)
const
userPoolBalance
=
allBalances
?.[
account
]?.[
pairAddress
]
const
userPoolBalance
=
allBalances
?.[
account
]?.[
pairAddress
]
const
totalPoolTokens
=
useTotalSupply
(
pair
)
const
totalPoolTokens
=
useTotalSupply
(
token0
,
token1
)
const
poolTokenPercentage
=
const
poolTokenPercentage
=
!!
userPoolBalance
&&
!!
totalPoolTokens
?
new
Percent
(
userPoolBalance
.
raw
,
totalPoolTokens
.
raw
)
:
undefined
!!
userPoolBalance
&&
!!
totalPoolTokens
?
new
Percent
(
userPoolBalance
.
raw
,
totalPoolTokens
.
raw
)
:
undefined
...
...
src/contexts/Balances.tsx
View file @
cf5c67ec
...
@@ -450,11 +450,6 @@ export function useAddressBalance(address: string, token: Token): TokenAmount |
...
@@ -450,11 +450,6 @@ export function useAddressBalance(address: string, token: Token): TokenAmount |
const
value
=
typeof
chainId
===
'
number
'
?
state
?.[
chainId
]?.[
address
]?.[
token
?.
address
]?.
value
:
undefined
const
value
=
typeof
chainId
===
'
number
'
?
state
?.[
chainId
]?.[
address
]?.[
token
?.
address
]?.
value
:
undefined
const
formattedValue
=
value
&&
token
&&
new
TokenAmount
(
token
,
value
)
const
formattedValue
=
value
&&
token
&&
new
TokenAmount
(
token
,
value
)
/**
* @todo
* when catching for token, causes infinite rerender
* when the token is an exchange liquidity token
*/
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
typeof
chainId
===
'
number
'
&&
isAddress
(
address
)
&&
token
&&
token
.
address
&&
isAddress
(
token
.
address
))
{
if
(
typeof
chainId
===
'
number
'
&&
isAddress
(
address
)
&&
token
&&
token
.
address
&&
isAddress
(
token
.
address
))
{
startListening
(
chainId
,
address
,
token
.
address
)
startListening
(
chainId
,
address
,
token
.
address
)
...
@@ -462,8 +457,7 @@ export function useAddressBalance(address: string, token: Token): TokenAmount |
...
@@ -462,8 +457,7 @@ export function useAddressBalance(address: string, token: Token): TokenAmount |
stopListening
(
chainId
,
address
,
token
.
address
)
stopListening
(
chainId
,
address
,
token
.
address
)
}
}
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
},
[
chainId
,
address
,
startListening
,
stopListening
,
token
])
},
[
chainId
,
address
,
startListening
,
stopListening
])
return
useMemo
(()
=>
formattedValue
,
[
formattedValue
])
return
useMemo
(()
=>
formattedValue
,
[
formattedValue
])
}
}
...
...
src/contexts/Pairs.tsx
View file @
cf5c67ec
...
@@ -100,9 +100,13 @@ export function usePair(tokenA?: Token, tokenB?: Token): Pair | undefined {
...
@@ -100,9 +100,13 @@ export function usePair(tokenA?: Token, tokenB?: Token): Pair | undefined {
const
address
=
usePairAddress
(
tokenA
,
tokenB
)
const
address
=
usePairAddress
(
tokenA
,
tokenB
)
const
tokenAmountA
=
useAddressBalance
(
address
,
tokenA
)
const
tokenAmountA
=
useAddressBalance
(
address
,
tokenA
)
const
tokenAmountB
=
useAddressBalance
(
address
,
tokenB
)
const
tokenAmountB
=
useAddressBalance
(
address
,
tokenB
)
const
pair
=
tokenAmountA
&&
tokenAmountB
&&
new
Pair
(
tokenAmountA
,
tokenAmountB
)
const
[
pair
,
setPair
]
=
useState
<
Pair
>
(
)
// return pair
useEffect
(()
=>
{
if
(
!
pair
&&
tokenAmountA
&&
tokenAmountB
)
{
setPair
(
new
Pair
(
tokenAmountA
,
tokenAmountB
))
}
},
[
pair
,
tokenAmountA
,
tokenAmountB
])
return
useMemo
(()
=>
{
return
useMemo
(()
=>
{
return
pair
return
pair
...
@@ -146,9 +150,11 @@ export function useAllPairs() {
...
@@ -146,9 +150,11 @@ export function useAllPairs() {
},
[
allPairs
])
},
[
allPairs
])
}
}
export
function
useTotalSupply
(
pair
:
Pair
)
{
export
function
useTotalSupply
(
tokenA
?:
Token
,
tokenB
?:
Token
)
{
const
{
library
}
=
useWeb3React
()
const
{
library
}
=
useWeb3React
()
const
pair
=
usePair
(
tokenA
,
tokenB
)
const
[
totalPoolTokens
,
setTotalPoolTokens
]
=
useState
<
TokenAmount
>
()
const
[
totalPoolTokens
,
setTotalPoolTokens
]
=
useState
<
TokenAmount
>
()
const
pairContract
=
usePairContract
(
pair
?.
liquidityToken
.
address
)
const
pairContract
=
usePairContract
(
pair
?.
liquidityToken
.
address
)
...
@@ -169,12 +175,7 @@ export function useTotalSupply(pair: Pair) {
...
@@ -169,12 +175,7 @@ export function useTotalSupply(pair: Pair) {
}
}
})
})
.
catch
(()
=>
{})
.
catch
(()
=>
{})
/**
},
[
pairContract
,
pair
])
* @todo
* fix this
*/
// eslint-disable-next-line react-hooks/exhaustive-deps
},
[
pairContract
])
// on the block make sure we're updated
// on the block make sure we're updated
useEffect
(()
=>
{
useEffect
(()
=>
{
...
...
src/contexts/Routes.tsx
View file @
cf5c67ec
...
@@ -103,13 +103,7 @@ export function useRoute(tokenA: Token, tokenB: Token) {
...
@@ -103,13 +103,7 @@ export function useRoute(tokenA: Token, tokenB: Token) {
update
([
tokenA
.
address
,
tokenB
.
address
],
routeThroughETH
,
chainId
)
update
([
tokenA
.
address
,
tokenB
.
address
],
routeThroughETH
,
chainId
)
}
}
}
}
/**
},
[
route
,
requiresHop
,
update
,
chainId
,
tokenA
,
tokenB
,
defaultPair
,
aToETH
,
bToETH
])
* @todo
* same infinite render bug here when including
* any token or pair instance as dependency (bug also in exchanegs and balances)
*/
// eslint-disable-next-line react-hooks/exhaustive-deps
},
[
route
,
requiresHop
,
update
,
chainId
])
return
useMemo
(()
=>
route
,
[
route
])
return
useMemo
(()
=>
route
,
[
route
])
}
}
src/pages/Supply/AddLiquidity.tsx
View file @
cf5c67ec
...
@@ -161,7 +161,7 @@ export default function AddLiquidity({ token0, token1 }) {
...
@@ -161,7 +161,7 @@ export default function AddLiquidity({ token0, token1 }) {
// exhchange data
// exhchange data
const
pair
:
Pair
=
usePair
(
tokens
[
Field
.
INPUT
],
tokens
[
Field
.
OUTPUT
])
const
pair
:
Pair
=
usePair
(
tokens
[
Field
.
INPUT
],
tokens
[
Field
.
OUTPUT
])
const
route
:
Route
=
pair
?
new
Route
([
pair
],
tokens
[
independentField
])
:
undefined
const
route
:
Route
=
pair
?
new
Route
([
pair
],
tokens
[
independentField
])
:
undefined
const
totalSupply
:
TokenAmount
=
useTotalSupply
(
pair
)
const
totalSupply
:
TokenAmount
=
useTotalSupply
(
tokens
[
Field
.
INPUT
],
tokens
[
Field
.
OUTPUT
]
)
const
[
noLiquidity
,
setNoLiquidity
]
=
useState
<
boolean
>
(
false
)
// used to detect new exchange
const
[
noLiquidity
,
setNoLiquidity
]
=
useState
<
boolean
>
(
false
)
// used to detect new exchange
// state for amount approvals
// state for amount approvals
...
...
src/pages/Supply/RemoveLiquidity.tsx
View file @
cf5c67ec
...
@@ -164,7 +164,7 @@ export default function RemoveLiquidity({ token0, token1 }) {
...
@@ -164,7 +164,7 @@ export default function RemoveLiquidity({ token0, token1 }) {
const
pairContract
:
ethers
.
Contract
=
usePairContract
(
pair
?.
liquidityToken
.
address
)
const
pairContract
:
ethers
.
Contract
=
usePairContract
(
pair
?.
liquidityToken
.
address
)
// pool token data
// pool token data
const
totalPoolTokens
:
TokenAmount
=
useTotalSupply
(
pair
)
const
totalPoolTokens
:
TokenAmount
=
useTotalSupply
(
tokens
[
Field
.
TOKEN0
],
tokens
[
Field
.
TOKEN1
]
)
const
allBalances
:
TokenAmount
[]
=
useAllBalances
()
const
allBalances
:
TokenAmount
[]
=
useAllBalances
()
const
userLiquidity
:
TokenAmount
=
allBalances
?.[
account
]?.[
pair
?.
liquidityToken
?.
address
]
const
userLiquidity
:
TokenAmount
=
allBalances
?.[
account
]?.[
pair
?.
liquidityToken
?.
address
]
...
...
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