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 { usePointCache } from 'store/pointCache';
10import { usePointCursor } from 'store/pointCursor';
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';
17import useLifecycle from 'lib/useLifecycle';
18import { validateNameInNumberSet } from 'lib/validators';
19import { getSpawnCandidate } from 'lib/child';
20import { useLocalRouter } from 'lib/LocalRouter';
22import ViewHeader from 'components/ViewHeader';
23import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
24import View from 'components/View';
26function useIssueChild() {
27 const { contracts } = useNetwork();
28 const { syncKnownPoint } = usePointCache();
30 const _contracts = need.contracts(contracts);
32 const [spawnedPoint, setSpawnedPoint] = useState();
34 return useEthereumTransaction(
36 (spawnedPoint, owner) => {
37 setSpawnedPoint(spawnedPoint);
38 return azimuth.ecliptic.spawn(_contracts, spawnedPoint, owner);
42 useCallback(() => syncKnownPoint(spawnedPoint), [
50export default function IssueChild() {
51 const { pop } = useLocalRouter();
52 const { contracts } = useNetwork();
53 const { pointCursor } = usePointCursor();
55 const _contracts = need.contracts(contracts);
56 const _point = parseInt(need.point(pointCursor), 10);
58 const [availablePoints, setAvailablePoints] = useState(Nothing());
60 const candidates = useMemo(() => {
61 const getCandidate = () => ob.patp(getSpawnCandidate(_point));
63 return [getCandidate(), getCandidate(), getCandidate(), getCandidate()];
75 const validators = useMemo(
77 validateNameInNumberSet(
78 availablePoints.getOrElse(new Set()),
79 'This point cannot be spawned.'
86 { pass: validPointName, value: pointName },
87 // ^ we use value: here so our effect runs onChange
90 disabled: inputsLocked,
93 error: availablePoints.matchWith({
94 Nothing: () => 'Loading availability...',
95 Just: () => undefined,
99 const [ownerInput, { pass: validOwner, data: owner }] = useAddressInput({
101 label: `Ethereum Address`,
102 disabled: inputsLocked,
106 if (validPointName && validOwner) {
107 construct(patp2dec(pointName), owner);
111 }, [owner, construct, unconstruct, validPointName, validOwner, pointName]);
117 const availablePoints = await azimuth.azimuth.getUnspawnedChildren(
126 setAvailablePoints(Just(new Set(availablePoints)));
129 return () => (mounted = false);
133 <View pop={pop} inset>
135 <Grid.Item full as={ViewHeader}>
140 <Grid.Item full as={Text}>
141 Perhaps one of {candidates.slice(0, 3).join(', ')}, or{' '}
142 {candidates[candidates.length - 1]}?
150 className={cn('f5', {
153 {pointName} has been spawned and can be claimed by {owner}.
159 <Grid.Item full as={Input} {...pointNameInput} className="mt4" />
160 <Grid.Item full as={Input} {...ownerInput} className="mb4" />
166 as={InlineEthereumTransaction}
168 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