Improve docs
This commit is contained in:
parent
d0f68000be
commit
d13671b75d
|
@ -36,6 +36,11 @@ export const useLatestBlock = (provider?: JsonRpcProvider) => {
|
||||||
return latestBlock;
|
return latestBlock;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the latest block number AND hook an internal listener
|
||||||
|
* that'll update and trigger a component render as a side effect
|
||||||
|
* every time it is notified of a new block by the web3 provider.
|
||||||
|
*/
|
||||||
export const useLatestBlockNumber = (provider?: JsonRpcProvider) => {
|
export const useLatestBlockNumber = (provider?: JsonRpcProvider) => {
|
||||||
const [latestBlock, setLatestBlock] = useState<number>();
|
const [latestBlock, setLatestBlock] = useState<number>();
|
||||||
|
|
||||||
|
@ -44,12 +49,15 @@ export const useLatestBlockNumber = (provider?: JsonRpcProvider) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Immediately read and set the latest block number
|
||||||
const readLatestBlock = async () => {
|
const readLatestBlock = async () => {
|
||||||
const blockNum = await provider.getBlockNumber();
|
const blockNum = await provider.getBlockNumber();
|
||||||
setLatestBlock(blockNum);
|
setLatestBlock(blockNum);
|
||||||
};
|
};
|
||||||
readLatestBlock();
|
readLatestBlock();
|
||||||
|
|
||||||
|
// Hook a listener that'll update the latest block number
|
||||||
|
// every time it is notified of a new block
|
||||||
const listener = async (blockNumber: number) => {
|
const listener = async (blockNumber: number) => {
|
||||||
setLatestBlock(blockNumber);
|
setLatestBlock(blockNumber);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue