1import { useState, useCallback } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import * as azimuth from 'azimuth-js';
5import { isDevelopment } from 'lib/flags';
6import { toL1Details } from 'lib/utils/point';
7import useRoller from 'lib/useRoller';
8import { useNetwork } from '../network';
9import { L1Point } from 'lib/types/L1Point';
11export default function useDetailsStore() {
12 const { contracts }: any = useNetwork();
13 const { api } = useRoller();
14 const [detailsCache, _setDetailsCache] = useState<Record<number, L1Point>>(
18 const addToDetails = useCallback(
20 _setDetailsCache(cache => ({
27 // TODO: refactor detailsCache access to use accessor like bithday
29 const getDetails = useCallback(
30 point => (point in detailsCache ? Just(detailsCache[point]) : Nothing()),
34 const syncDetails = useCallback(
36 const _contracts = contracts.getOrElse(null);
41 // fetch point details
43 const l2Point = await api.getPoint(point);
45 l2Point && (l2Point.dominion === 'l2' || l2Point.dominion === 'spawn')
46 ? toL1Details(l2Point)
47 : await azimuth.azimuth.getPoint(_contracts, point);
57 const details = await azimuth.azimuth.getPoint(_contracts, point);
66 [api, contracts, addToDetails]
70 // TODO: refactor accessors to use getDetails instead of
71 // touching the cache directly
72 pointCache: detailsCache,
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