1import { useCallback, useState } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import Result from 'folktale/result';
5import { useNetwork } from '../network';
7export default function useRekeyDateStore() {
8 const { web3, contracts } = useNetwork();
9 const [rekeyDateCache, _setRekeyDateCache] = useState({});
11 const addToRekeyDateCache = useCallback(
13 _setRekeyDateCache(cache => ({
21 * @param {number} point
22 * @return {Maybe<Result<Date, String>>}
24 const getRekeyDate = useCallback(
25 point => rekeyDateCache[point] || Nothing(),
29 const syncRekeyDate = useCallback(
31 const _web3 = web3.getOrElse(null);
32 const _contracts = contracts.getOrElse(null);
33 if (!_web3 || !_contracts) {
37 //TODO tighter search?
38 //TODO maybe move into azimuth-js?
39 const logs = await _contracts.azimuth.getPastEvents('ChangedKeys', {
47 // NB(shrugs) using try-catch here to simplify our error handling
49 if (logs.length === 0) {
50 throw new Error('No logs available.');
53 // last log is most recent
54 const blockNumber = logs[logs.length - 1].blockNumber;
55 if (blockNumber === null) {
56 // the "latest" parameter includes pending blocks,
57 // which won't have a blockNumber just yet
58 throw new Error('Latest rekey is still pending');
61 const block = await _web3.eth.getBlock(blockNumber);
63 [point]: Just(Result.Ok(new Date(block.timestamp * 1000))),
66 //TODO: better encoding for "no rekeyDate" state?
68 [point]: Just(Result.Error('No rekey date available.')),
72 [web3, contracts, addToRekeyDateCache]
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list