1import { useState, useEffect, useCallback } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import Result from 'folktale/result';
5import { useNetwork } from '../network';
6import { useWallet } from 'store/wallet';
7import useRoller from 'lib/useRoller';
9export default function useControlledPointsStore() {
10 const { contracts } = useNetwork();
11 const { wallet } = useWallet();
12 const { getPoints } = useRoller();
14 const [controlledPoints, _setControlledPoints] = useState(Nothing());
16 const syncControlledPoints = useCallback(async () => {
17 const _contracts = contracts.getOrElse(null);
18 const _wallet = wallet.getOrElse(null);
19 if (!_contracts || !_wallet) {
23 _setControlledPoints(Nothing());
25 const address = _wallet.address;
34 ] = await Promise.all([
35 getPoints('own', address),
36 getPoints('transfer', address),
37 getPoints('manage', address),
38 getPoints('vote', address),
39 getPoints('spawn', address),
42 console.log(ownedPoints)
45 ownedPoints === null &&
46 incomingPoints === null &&
47 managingPoints === null &&
48 votingPoints === null &&
49 spawningPoints === null
52 Just(Result.Error('Failed to read the blockchain.'))
68 console.error('failed to fetch controlled points', error);
69 _setControlledPoints(Just(Result.Error(error)));
71 }, [contracts, wallet, getPoints]);
73 // sync controlled points whenever wallet or contracts changes
75 syncControlledPoints();
76 }, [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