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 } = 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;
37 ] = await Promise.all([
38 getPoints('own', address),
39 getPoints('transfer', address),
40 getPoints('manage', address),
41 getPoints('vote', address),
42 getPoints('spawn', address),
51 ] = await Promise.all([
52 azimuth.azimuth.getOwnedPoints(_contracts, address),
53 azimuth.azimuth.getTransferringFor(_contracts, address),
54 azimuth.azimuth.getManagerFor(_contracts, address),
55 azimuth.azimuth.getVotingFor(_contracts, address),
56 azimuth.azimuth.getSpawningFor(_contracts, address),
60 ownedPoints === null &&
61 incomingPoints === null &&
62 managingPoints === null &&
63 votingPoints === null &&
64 spawningPoints === null
67 Just(Result.Error('Failed to read the blockchain.'))
73 ownedPoints: ownedPoints
74 .concat(ownedPointsL1)
77 incomingPoints: incomingPoints
78 .concat(incomingPointsL1)
81 managingPoints: managingPoints
82 .concat(managingPointsL1)
85 votingPoints: votingPoints
86 .concat(votingPointsL1)
89 spawningPoints: spawningPoints
90 .concat(spawningPointsL1)
98 console.error('failed to fetch controlled points', error);
99 _setControlledPoints(Just(Result.Error(error)));
101 }, [contracts, wallet, getPoints]);
103 // sync controlled points whenever wallet or contracts changes
105 syncControlledPoints();
106 }, [syncControlledPoints]);
110 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