1import React, { useCallback, useMemo, useState } from 'react';
2import cn from 'classnames';
3import { Grid, Text } from 'indigo-react';
4import * as azimuth from 'azimuth-js';
5import * as ob from 'urbit-ob';
7import { useNetwork } from 'store/network';
8import { usePointCache } from 'store/pointCache';
9import { usePointCursor } from 'store/pointCursor';
11import * as need from 'lib/need';
12import useEthereumTransaction from 'lib/useEthereumTransaction';
13import { GAS_LIMITS } from 'lib/constants';
14import patp2dec from 'lib/patp2dec';
15import { getSpawnCandidate } from 'lib/child';
16import { useLocalRouter } from 'lib/LocalRouter';
17import useConstant from 'lib/useConstant';
19import ViewHeader from 'components/ViewHeader';
20import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
21import View from 'components/View';
22import { PointInput, AddressInput } from 'form/Inputs';
26 buildAddressValidator,
28} from 'form/validators';
29import BridgeForm from 'form/BridgeForm';
30import FormError from 'form/FormError';
32function useIssueChild() {
33 const { contracts } = useNetwork();
34 const { syncKnownPoint } = usePointCache();
36 const _contracts = need.contracts(contracts);
38 const [spawnedPoint, setSpawnedPoint] = useState();
40 return useEthereumTransaction(
42 (spawnedPoint, owner) => {
43 setSpawnedPoint(spawnedPoint);
44 return azimuth.ecliptic.spawn(_contracts, spawnedPoint, owner);
48 useCallback(() => syncKnownPoint(spawnedPoint), [
56export default function IssueChild() {
57 const { pop } = useLocalRouter();
58 const { contracts } = useNetwork();
59 const { pointCursor } = usePointCursor();
61 const _contracts = need.contracts(contracts);
62 const _point = parseInt(need.point(pointCursor), 10);
64 const availablePointsPromise = useConstant(() =>
66 .getUnspawnedChildren(_contracts, _point)
67 .then(points => new Set(points))
70 const candidates = useMemo(() => {
71 const getCandidate = () => ob.patp(getSpawnCandidate(_point));
73 return [getCandidate(), getCandidate(), getCandidate(), getCandidate()];
85 const validateFormAsync = useCallback(
87 const point = patp2dec(values.name);
88 const hasPoint = (await availablePointsPromise).has(point);
91 return { point: 'This point cannot be spawned.' };
94 [availablePointsPromise]
97 const validateForm = useCallback(
99 if (hasErrors(errors)) {
103 return validateFormAsync(values, errors);
108 const validate = useMemo(
112 point: buildPointValidator(4),
113 owner: buildAddressValidator(),
120 const onValues = useCallback(
121 ({ valid, values }) => {
123 construct(patp2dec(values.point), values.owner);
128 [construct, unconstruct]
132 <View pop={pop} inset>
134 <Grid.Item full as={ViewHeader}>
139 <Grid.Item full as={Text}>
140 Perhaps one of {candidates.slice(0, 3).join(', ')}, or{' '}
141 {candidates[candidates.length - 1]}?
145 <BridgeForm validate={validate} onValues={onValues}>
146 {({ handleSubmit, values }) => (
152 className={cn('f5 wrap', {
155 {values.point} has been spawned and can be claimed by{' '}
166 disabled={inputsLocked}
174 label="Ethereum Address"
175 disabled={inputsLocked}
180 <Grid.Item full as={FormError} />
184 as={InlineEthereumTransaction}
186 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