Commit ffc20155 authored by Noah Zinsmeister's avatar Noah Zinsmeister

invalidate stale requests in useV3PositionFees

parent 5e30a4b4
...@@ -16,16 +16,18 @@ export function useV3PositionFees( ...@@ -16,16 +16,18 @@ export function useV3PositionFees(
asWETH = false asWETH = false
): [CurrencyAmount<Currency>, CurrencyAmount<Currency>] | [undefined, undefined] { ): [CurrencyAmount<Currency>, CurrencyAmount<Currency>] | [undefined, undefined] {
const positionManager = useV3NFTPositionManagerContract(false) 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 tokenIdHexString = tokenId?.toHexString()
const latestBlockNumber = useBlockNumber() const latestBlockNumber = useBlockNumber()
// TODO find a way to get this into multicall // 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 // latestBlockNumber is included to ensure data stays up-to-date every block
const [amounts, setAmounts] = useState<[BigNumber, BigNumber]>() const [amounts, setAmounts] = useState<[BigNumber, BigNumber]>()
useEffect(() => { useEffect(() => {
let stale = false
if (positionManager && tokenIdHexString && owner && typeof latestBlockNumber === 'number') { if (positionManager && tokenIdHexString && owner && typeof latestBlockNumber === 'number') {
positionManager.callStatic positionManager.callStatic
.collect( .collect(
...@@ -38,9 +40,13 @@ export function useV3PositionFees( ...@@ -38,9 +40,13 @@ export function useV3PositionFees(
{ from: owner } // need to simulate the call as the owner { from: owner } // need to simulate the call as the owner
) )
.then((results) => { .then((results) => {
setAmounts([results.amount0, results.amount1]) if (!stale) setAmounts([results.amount0, results.amount1])
}) })
} }
return () => {
stale = true
}
}, [positionManager, tokenIdHexString, owner, latestBlockNumber]) }, [positionManager, tokenIdHexString, owner, latestBlockNumber])
if (pool && amounts) { if (pool && amounts) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment