1import { useCallback, useState } from 'react';
2import { Just, Nothing } 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(point => birthdayCache[point] || Nothing(), [
24 const syncBirthday = useCallback(
26 const _contracts = contracts.getOrElse(null);
27 const _web3 = web3.getOrElse(null);
28 if (!_contracts || !_web3) {
32 // birthday will not change after being set, so bail if we already know
33 if (Just.hasInstance(getBirthday(point))) {
37 const birthBlock = await azimuth.azimuth.getActivationBlock(
43 const block = await _web3.eth.getBlock(birthBlock);
45 [point]: Just(new Date(block.timestamp * 1000)),
48 // TODO: better encoding for "no birthday" state using Result.Ok/Error
49 // if there's no birthday, just use today
51 [point]: Just(new Date()),
55 [contracts, web3, addToBirthdayCache, getBirthday]
58 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