Transactions Updater

The Updater hook will automatically check the status of each pending transaction based on the logic provided in shouldCheck. It will use the provided callbacks to inform the rest of the app about the status of each transaction, allowing the state to be accurately updated.

export function shouldCheck(lastBlockNumber: number, tx: Transaction): boolean {
  if (tx.receipt) return false;
  if (!tx.lastCheckedBlockNumber) return true;
  const blocksSinceCheck = lastBlockNumber - tx.lastCheckedBlockNumber;
  if (blocksSinceCheck < 1) return false;
  const minutesPending = (new Date().getTime() - tx.addedTime) / 60_000;
  if (minutesPending > 60) {
    // every 10 blocks if pending longer than an hour
    return blocksSinceCheck > 9;
  } else if (minutesPending > 5) {
    // every 3 blocks if pending longer than 5 minutes
    return blocksSinceCheck > 2;
  } else {
    // otherwise every block
    return true;
  }
}

Updater Hook

export default function Updater({
  pendingTransactions,
  onCheck,
  onReceipt,
}: UpdaterProps): null {
...
}

Props

  • pendingTransactions: An object mapping transaction hashes to their metadata, including added time and last checked block number.

  • onCheck: A callback function invoked for transactions that have been checked but not yet confirmed. It receives an object with the transaction's chainId, hash, and the blockNumber it was last checked against. Dispatches the checkedTransaction action when a transaction check is triggered

  • onReceipt: A callback function invoked for transactions once they're confirmed. It receives an object with the transaction's chainId, hash, and its receipt. Dispatches the finalizeTransaction action to store the final state of the transaction in the Redux store.

Last updated