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';
9import { isL2 } from 'lib/utils/roller';
11const onlyUnique = (value, index, self) => self.indexOf(value) === index;
13export default function useControlledPointsStore() {
14 const { contracts } = useNetwork();
15 const { wallet } = useWallet();
16 const { api, getPoints } = useRoller();
18 const [controlledPoints, _setControlledPoints] = useState(Nothing());
20 const syncControlledPoints = useCallback(async () => {
21 const _contracts = contracts.getOrElse(null);
22 const _wallet = wallet.getOrElse(null);
23 if (!_contracts || !_wallet) {
27 _setControlledPoints(Nothing());
29 const address = _wallet.address;
43 ] = await Promise.all([
44 getPoints('own', address),
45 getPoints('transfer', address),
46 getPoints('manage', address),
47 getPoints('vote', address),
48 getPoints('spawn', address),
49 azimuth.azimuth.getOwnedPoints(_contracts, address),
50 azimuth.azimuth.getTransferringFor(_contracts, address),
51 azimuth.azimuth.getManagerFor(_contracts, address),
52 azimuth.azimuth.getVotingFor(_contracts, address),
53 azimuth.azimuth.getSpawningFor(_contracts, address),
56 // const pointsWithLayers = await Promise.all(
57 // ownedPoints.map(async ship => {
59 // const pointInfo = await api.getPoint(Number(ship));
61 // point: Number(ship),
62 // layer: isL2(pointInfo?.dominion) ? 1 : 2,
65 // console.warn(error);
66 // return { point: ship, layer: 1 };
70 const pointsWithLayers = ownedPoints.map(point => ({
76 ownedPoints === null &&
77 incomingPoints === null &&
78 managingPoints === null &&
79 votingPoints === null &&
80 spawningPoints === null
83 Just(Result.Error('Failed to read the blockchain.'))
89 ownedPoints: ownedPoints
90 .concat(ownedPointsL1)
93 incomingPoints: incomingPoints
94 .concat(incomingPointsL1)
97 managingPoints: managingPoints
98 .concat(managingPointsL1)
101 votingPoints: votingPoints
102 .concat(votingPointsL1)
105 spawningPoints: spawningPoints
106 .concat(spawningPointsL1)
115 console.error('failed to fetch controlled points', error);
116 _setControlledPoints(Just(Result.Error(error)));
118 }, [contracts, wallet, getPoints, api]);
120 // sync controlled points whenever wallet or contracts changes
122 syncControlledPoints();
123 }, [syncControlledPoints]);
127 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