1import React, { useCallback, useEffect, useMemo, useState } from 'react';
2import { Nothing, Just } from 'folktale/maybe';
3import cn from 'classnames';
4import { Grid, Text, Input } from 'indigo-react';
5import * as azimuth from 'azimuth-js';
6import * as ob from 'urbit-ob';
8import { useNetwork } from 'store/network';
9import { useHistory } from 'store/history';
10import { usePointCache } from 'store/pointCache';
12import * as need from 'lib/need';
13import { useAddressInput, usePointInput } from 'lib/useInputs';
14import useEthereumTransaction from 'lib/useEthereumTransaction';
15import { GAS_LIMITS } from 'lib/constants';
16import patp2dec from 'lib/patp2dec';
18import ViewHeader from 'components/ViewHeader';
19import MiniBackButton from 'components/MiniBackButton';
20import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
21import View from 'components/View';
22import useLifecycle from 'lib/useLifecycle';
23import { usePointCursor } from 'store/pointCursor';
24import { validateInSet } from 'lib/validators';
25import { getSpawnCandidate } from 'lib/child';
27function useIssueChild() {
28 const { contracts } = useNetwork();
29 const { syncKnownPoint } = usePointCache();
31 const _contracts = need.contracts(contracts);
33 const [spawnedPoint, setSpawnedPoint] = useState();
35 return useEthereumTransaction(
37 (spawnedPoint, owner) => {
38 setSpawnedPoint(spawnedPoint);
39 return azimuth.ecliptic.spawn(_contracts, spawnedPoint, owner);
43 useCallback(() => syncKnownPoint(spawnedPoint), [
51export default function IssueChild() {
52 const { pop } = useHistory();
53 const { contracts } = useNetwork();
54 const { pointCursor } = usePointCursor();
56 const _contracts = need.contracts(contracts);
57 const _point = need.point(pointCursor);
59 const [availablePointNames, setAvailablePointNames] = useState(Nothing());
61 const candidates = useMemo(() => {
62 const getCandidate = () => ob.patp(getSpawnCandidate(_point));
64 return [getCandidate(), getCandidate(), getCandidate(), getCandidate()];
76 const validators = useMemo(
79 availablePointNames.getOrElse(new Set()),
80 'This point cannot be spawned.'
87 { pass: validPointName, value: pointName },
88 // ^ we use value: here so our effect runs onChange
91 disabled: inputsLocked,
94 error: availablePointNames.matchWith({
95 Nothing: () => 'Loading availability...',
96 Just: () => undefined,
100 const [ownerInput, { pass: validOwner, data: owner }] = useAddressInput({
102 label: `Ethereum Address`,
103 disabled: inputsLocked,
107 if (validPointName && validOwner) {
108 construct(patp2dec(pointName), owner);
112 }, [owner, construct, unconstruct, validPointName, validOwner, pointName]);
118 const availablePoints = await azimuth.azimuth.getUnspawnedChildren(
127 setAvailablePointNames(Just(new Set(availablePoints.map(ob.patp))));
130 return () => (mounted = false);
136 <Grid.Item full as={MiniBackButton} onClick={() => pop()} />
138 <Grid.Item full as={ViewHeader}>
143 <Grid.Item full as={Text}>
144 Perhaps one of {candidates.slice(0, 3).join(', ')}, or{' '}
145 {candidates[candidates.length - 1]}?
153 className={cn('f5', {
156 {pointName} has been spawned and can be claimed by {owner}.
162 <Grid.Item full as={Input} {...pointNameInput} className="mt4" />
163 <Grid.Item full as={Input} {...ownerInput} className="mb4" />
169 as={InlineEthereumTransaction}
171 onReturn={() => pop()}
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