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,
27} from 'form/validators';
28import BridgeForm from 'form/BridgeForm';
29import FormError from 'form/FormError';
31function useIssueChild() {
32 const { contracts } = useNetwork();
33 const { syncKnownPoint } = usePointCache();
35 const _contracts = need.contracts(contracts);
37 const [spawnedPoint, setSpawnedPoint] = useState();
39 return useEthereumTransaction(
41 (spawnedPoint, owner) => {
42 setSpawnedPoint(spawnedPoint);
43 return azimuth.ecliptic.spawn(_contracts, spawnedPoint, owner);
47 useCallback(() => syncKnownPoint(spawnedPoint), [
55export default function IssueChild() {
56 const { pop } = useLocalRouter();
57 const { contracts } = useNetwork();
58 const { pointCursor } = usePointCursor();
60 const _contracts = need.contracts(contracts);
61 const _point = parseInt(need.point(pointCursor), 10);
63 const availablePointsPromise = useConstant(() =>
65 .getUnspawnedChildren(_contracts, _point)
66 .then(points => new Set(points))
69 const candidates = useMemo(() => {
70 const getCandidate = () => ob.patp(getSpawnCandidate(_point));
72 return [getCandidate(), getCandidate(), getCandidate(), getCandidate()];
84 const validatePoint = useCallback(
86 const point = patp2dec(name);
87 const hasPoint = (await availablePointsPromise).has(point);
90 return 'This point cannot be spawned.';
93 [availablePointsPromise]
96 const validate = useMemo(
99 point: buildPointValidator(4, [validatePoint]),
100 owner: buildAddressValidator(),
105 const onValues = useCallback(
106 ({ valid, values }) => {
108 construct(patp2dec(values.point), values.owner);
113 [construct, unconstruct]
117 <View pop={pop} inset>
119 <Grid.Item full as={ViewHeader}>
124 <Grid.Item full as={Text}>
125 Perhaps one of {candidates.slice(0, 3).join(', ')}, or{' '}
126 {candidates[candidates.length - 1]}?
130 <BridgeForm validate={validate} onValues={onValues}>
131 {({ handleSubmit, values }) => (
137 className={cn('f5', {
140 {values.point} has been spawned and can be claimed by{' '}
151 disabled={inputsLocked}
159 label="Ethereum Address"
160 disabled={inputsLocked}
165 <Grid.Item full as={FormError} />
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