Skip to content

Commit

Permalink
improvement: use the block number in receipts to update the app state (
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem authored May 22, 2021
1 parent 02269e9 commit 6e46f25
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/state/transactions/updater.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useMemo } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useActiveWeb3React } from '../../hooks/web3'
import { updateBlockNumber } from '../application/actions'
import { useAddPopup, useBlockNumber } from '../application/hooks'
import { AppDispatch, AppState } from '../index'
import { checkedTransaction, finalizeTransaction } from './actions'
Expand Down Expand Up @@ -79,6 +80,11 @@ export default function Updater(): null {
},
hash
)

// the receipt was fetched before the block, fast forward to that block to trigger balance updates
if (receipt.blockNumber > lastBlockNumber) {
dispatch(updateBlockNumber({ chainId, blockNumber: receipt.blockNumber }))
}
} else {
dispatch(checkedTransaction({ chainId, hash, blockNumber: lastBlockNumber }))
}
Expand Down

0 comments on commit 6e46f25

Please sign in to comment.