1import { useState, useEffect, useCallback } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import Result from 'folktale/result';
4import * as azimuth from 'azimuth-js';
6import { useNetwork } from '../network';
7import { useWallet } from 'store/wallet';
8import useRoller from 'lib/useRoller';
10const onlyUnique = (value, index, self) => self.indexOf(value) === index;
12export default function useControlledPointsStore() {
13 const { contracts } = useNetwork();
14 const { wallet } = useWallet();
15 const { getPoints, getPointDetails } = useRoller();
17 const [controlledPoints, _setControlledPoints] = useState(Nothing());
19 const syncControlledPoints = useCallback(async () => {
20 const _contracts = contracts.getOrElse(null);
21 const _wallet = wallet.getOrElse(null);
22 if (!_contracts || !_wallet) {
26 _setControlledPoints(Nothing());
28 const address = _wallet.address;
42 ] = await Promise.all([
43 azimuth.azimuth.getOwnedPoints(_contracts, address),
44 azimuth.azimuth.getTransferringFor(_contracts, address),
45 azimuth.azimuth.getManagerFor(_contracts, address),
46 azimuth.azimuth.getVotingFor(_contracts, address),
47 azimuth.azimuth.getSpawningFor(_contracts, address),
48 getPoints('own', address),
49 getPoints('transfer', address),
50 getPoints('manage', address),
51 getPoints('vote', address),
52 getPoints('spawn', address),
56 ownedPointsL1 === null &&
57 incomingPointsL1 === null &&
58 managingPointsL1 === null &&
59 votingPointsL1 === null &&
60 spawningPointsL1 === null &&
61 ownedPointsL2 === null &&
62 incomingPointsL2 === null &&
63 managingPointsL2 === null &&
64 votingPointsL2 === null &&
65 spawningPointsL2 === null
68 Just(Result.Error('Failed to read the blockchain.'))
72 (ownedPointsL1 || []).concat(ownedPointsL2 || []),
73 (incomingPointsL1 || []).concat(incomingPointsL2 || []),
74 (managingPointsL1 || []).concat(managingPointsL2 || []),
75 (votingPointsL1 || []).concat(votingPointsL2 || []),
76 (spawningPointsL1 || []).concat(spawningPointsL2 || [])
82 ownedPoints: ownedPointsL2
83 .concat(ownedPointsL1)
86 incomingPoints: incomingPointsL2
87 .concat(incomingPointsL1)
90 managingPoints: managingPointsL2
91 .concat(managingPointsL1)
94 votingPoints: votingPointsL2
95 .concat(votingPointsL1)
98 spawningPoints: spawningPointsL2
99 .concat(spawningPointsL1)
107 console.error('failed to fetch controlled points', error);
108 _setControlledPoints(Just(Result.Error(error)));
110 }, [contracts, wallet, getPoints, getPointDetails]);
112 // sync controlled points whenever wallet or contracts changes
114 syncControlledPoints();
115 }, [syncControlledPoints]);
119 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