1import React, { useCallback, useMemo, useState } from 'react';
2import cn from 'classnames';
3import { Grid, Text } from 'indigo-react';
4import * as azimuth from 'azimuth-js';
5import 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';
31import CopiableAddress from 'components/CopiableAddress';
32import convertToInt from 'lib/convertToInt';
34function useIssueChild() {
35 const { contracts } = useNetwork();
36 const { syncKnownPoint } = usePointCache();
38 const _contracts = need.contracts(contracts);
40 const [spawnedPoint, setSpawnedPoint] = useState();
42 return useEthereumTransaction(
44 (spawnedPoint, owner) => {
45 setSpawnedPoint(spawnedPoint);
46 return azimuth.ecliptic.spawn(_contracts, spawnedPoint, owner);
50 useCallback(() => syncKnownPoint(spawnedPoint), [
58export default function IssueChild() {
59 const { pop } = useLocalRouter();
60 const { contracts } = useNetwork();
61 const { pointCursor } = usePointCursor();
63 const _contracts = need.contracts(contracts);
64 const _point = convertToInt(need.point(pointCursor), 10);
66 const availablePointsPromise = useConstant(() =>
68 .getUnspawnedChildren(_contracts, _point)
69 .then(points => new Set(points))
72 const candidates = useMemo(() => {
73 const getCandidate = () => ob.patp(getSpawnCandidate(_point));
75 return [getCandidate(), getCandidate(), getCandidate(), getCandidate()];
87 const validateFormAsync = useCallback(
89 const point = patp2dec(values.point);
90 const hasPoint = (await availablePointsPromise).has(point);
93 return { point: 'This point cannot be spawned.' };
96 [availablePointsPromise]
99 const validateForm = useCallback(
100 (values, errors) => {
101 if (hasErrors(errors)) {
105 return validateFormAsync(values, errors);
110 const validate = useMemo(
114 point: buildPointValidator(4),
115 owner: buildAddressValidator(),
122 const onValues = useCallback(
123 ({ valid, values }) => {
125 construct(patp2dec(values.point), values.owner);
130 [construct, unconstruct]
134 <View pop={pop} inset>
136 <Grid.Item full as={ViewHeader}>
141 <Grid.Item full as={Text}>
142 Perhaps one of {candidates.slice(0, 3).join(', ')}, or{' '}
143 {candidates[candidates.length - 1]}?
147 <BridgeForm validate={validate} onValues={onValues}>
148 {({ handleSubmit, values }) => (
154 className={cn('f5 wrap', {
157 {values.point} has been spawned and can be claimed by{' '}
158 <CopiableAddress>{values.owner}</CopiableAddress>.
168 disabled={inputsLocked}
176 label="Ethereum Address"
177 disabled={inputsLocked}
182 <Grid.Item full as={FormError} />
186 as={InlineEthereumTransaction}
188 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