1import { useState, useEffect, useCallback } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import Result from 'folktale/result';
4import * as azimuth from 'azimuth-js';
6import { useWallet } from 'store/wallet';
7import useRoller from 'lib/useRoller';
8import { onlyUnique } from 'lib/utils/array';
9import { useNetwork } from '../network';
11export default function useControlledPointsStore() {
12 const { contracts } = useNetwork();
13 const { wallet } = useWallet();
14 const { getPoints, getPointDetails } = useRoller();
16 const [controlledPoints, _setControlledPoints] = useState(Nothing());
18 const syncControlledPoints = useCallback(async () => {
19 const _contracts = contracts.getOrElse(null);
20 const _wallet = wallet.getOrElse(null);
21 if (!_contracts || !_wallet) {
25 _setControlledPoints(Nothing());
27 const address = _wallet.address;
41 ] = await Promise.all([
42 azimuth.azimuth.getOwnedPoints(_contracts, address),
43 azimuth.azimuth.getTransferringFor(_contracts, address),
44 azimuth.azimuth.getManagerFor(_contracts, address),
45 azimuth.azimuth.getVotingFor(_contracts, address),
46 azimuth.azimuth.getSpawningFor(_contracts, address),
47 getPoints('own', address),
48 getPoints('transfer', address),
49 getPoints('manage', address),
50 getPoints('vote', address),
51 getPoints('spawn', address),
55 ownedPointsL1 === null &&
56 incomingPointsL1 === null &&
57 managingPointsL1 === null &&
58 votingPointsL1 === null &&
59 spawningPointsL1 === null &&
60 ownedPointsL2 === null &&
61 incomingPointsL2 === null &&
62 managingPointsL2 === null &&
63 votingPointsL2 === null &&
64 spawningPointsL2 === null
67 Just(Result.Error('Failed to read the blockchain.'))
71 (ownedPointsL1 || []).concat(ownedPointsL2 || []).filter(onlyUnique),
72 (incomingPointsL1 || [])
73 .concat(incomingPointsL2 || [])
75 (managingPointsL1 || [])
76 .concat(managingPointsL2 || [])
78 (votingPointsL1 || [])
79 .concat(votingPointsL2 || [])
81 (spawningPointsL1 || [])
82 .concat(spawningPointsL2 || [])
89 ownedPoints: ownedPointsL2
90 .concat(ownedPointsL1)
93 incomingPoints: incomingPointsL2
94 .concat(incomingPointsL1)
97 managingPoints: managingPointsL2
98 .concat(managingPointsL1)
101 votingPoints: votingPointsL2
102 .concat(votingPointsL1)
105 spawningPoints: spawningPointsL2
106 .concat(spawningPointsL1)
114 console.error('failed to fetch controlled points', error);
115 _setControlledPoints(Just(Result.Error(error)));
117 }, [contracts, wallet, getPoints, getPointDetails]);
119 // sync controlled points whenever wallet or contracts changes
121 syncControlledPoints();
122 }, [syncControlledPoints]);
126 syncControlledPoints,
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