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
ffc20155
Unverified
Commit
ffc20155
authored
May 20, 2021
by
Noah Zinsmeister
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
invalidate stale requests in useV3PositionFees
parent
5e30a4b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
3 deletions
+9
-3
useV3PositionFees.ts
src/hooks/useV3PositionFees.ts
+9
-3
No files found.
src/hooks/useV3PositionFees.ts
View file @
ffc20155
...
...
@@ -16,16 +16,18 @@ export function useV3PositionFees(
asWETH
=
false
):
[
CurrencyAmount
<
Currency
>
,
CurrencyAmount
<
Currency
>
]
|
[
undefined
,
undefined
]
{
const
positionManager
=
useV3NFTPositionManagerContract
(
false
)
const
owner
=
useSingleCallResult
(
tokenId
?
positionManager
:
null
,
'
ownerOf
'
,
[
tokenId
]).
result
?.[
0
]
const
owner
:
string
|
undefined
=
useSingleCallResult
(
tokenId
?
positionManager
:
null
,
'
ownerOf
'
,
[
tokenId
])
.
result
?.[
0
]
const
tokenIdHexString
=
tokenId
?.
toHexString
()
const
latestBlockNumber
=
useBlockNumber
()
// TODO find a way to get this into multicall
// because these amounts don't ever go down, we don't actually need to clear this state
// latestBlockNumber is included to ensure data stays up-to-date every block
const
[
amounts
,
setAmounts
]
=
useState
<
[
BigNumber
,
BigNumber
]
>
()
useEffect
(()
=>
{
let
stale
=
false
if
(
positionManager
&&
tokenIdHexString
&&
owner
&&
typeof
latestBlockNumber
===
'
number
'
)
{
positionManager
.
callStatic
.
collect
(
...
...
@@ -38,9 +40,13 @@ export function useV3PositionFees(
{
from
:
owner
}
// need to simulate the call as the owner
)
.
then
((
results
)
=>
{
setAmounts
([
results
.
amount0
,
results
.
amount1
])
if
(
!
stale
)
setAmounts
([
results
.
amount0
,
results
.
amount1
])
})
}
return
()
=>
{
stale
=
true
}
},
[
positionManager
,
tokenIdHexString
,
owner
,
latestBlockNumber
])
if
(
pool
&&
amounts
)
{
...
...
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