1import { useCallback, useState } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
4import { useNetwork } from '../network';
6export default function useRekeyDateStore() {
7 const { web3, contracts } = useNetwork();
8 const [rekeyDateCache, _setRekeyDateCache] = useState({});
10 const addToRekeyDateCache = useCallback(
12 _setRekeyDateCache(cache => ({
19 const getRekeyDate = useCallback(
20 point => rekeyDateCache[point] || Nothing(),
24 const syncRekeyDate = useCallback(
26 const _web3 = web3.getOrElse(null);
30 const _contracts = contracts.getOrElse(null);
35 //TODO tighter search?
36 //TODO maybe move into azimuth-js?
37 const logs = await _contracts.azimuth.getPastEvents('ChangedKeys', {
40 filter: { point: [point] },
43 if (logs.length === 0) {
44 //TODO: better encoding for "no rekeyDate" state?
46 [point]: Just('unknown'),
49 // last log is most recent
50 const blockNumber = logs[logs.length - 1].blockNumber;
51 const block = await _web3.eth.getBlock(blockNumber);
54 [point]: Just(new Date(block.timestamp * 1000).toString()),
58 [web3, contracts, addToRekeyDateCache]
61 return { getRekeyDate, syncRekeyDate };
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