1import { useCallback, useState } from 'react';
2import Maybe from 'folktale/maybe';
3import * as azimuth from 'azimuth-js';
5import { useNetwork } from '../network';
7export default function useBirthdayStore() {
8 const { contracts, web3 } = useNetwork();
9 const [birthdayCache, _setBirthdayCache] = useState({});
11 const addToBirthdayCache = useCallback(
13 _setBirthdayCache(cache => ({
20 const getBirthday = useCallback(
21 point => birthdayCache[point] || Maybe.Nothing(),
25 const syncBirthday = useCallback(
27 const _contracts = contracts.getOrElse(null);
28 const _web3 = web3.getOrElse(null);
29 if (!_contracts || !web3) {
33 // fetch birthday if not already known—will not change after being set
34 if (Maybe.Nothing.hasInstance(getBirthday(point))) {
35 const birthBlock = await azimuth.azimuth.getActivationBlock(
41 const block = await _web3.eth.getBlock(birthBlock);
43 [point]: Maybe.Just(new Date(block.timestamp * 1000)),
48 [contracts, web3, addToBirthdayCache, getBirthday]
51 return { getBirthday, syncBirthday };
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