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';
18import { validateChild } from 'lib/validators';
20import ViewHeader from 'components/ViewHeader';
21import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
22import View from 'components/View';
23import { PointInput, AddressInput } from 'form/Inputs';
27 buildAddressValidator,
29} from 'form/validators';
30import BridgeForm from 'form/BridgeForm';
31import FormError from 'form/FormError';
32import CopiableAddress from 'components/copiable/CopiableAddress';
33import { convertToInt } from 'lib/convertToInt';
34import useCurrentPermissions from 'lib/useCurrentPermissions';
36export function useIssueChild() {
37 const { contracts } = useNetwork();
38 const { syncDates } = usePointCache();
40 const _contracts = need.contracts(contracts);
42 const [spawnedPoint, setSpawnedPoint] = useState();
44 return useEthereumTransaction(
46 (spawnedPoint, owner) => {
47 setSpawnedPoint(spawnedPoint);
48 return azimuth.ecliptic.spawn(_contracts, spawnedPoint, owner);
52 useCallback(() => syncDates(spawnedPoint), [spawnedPoint, syncDates]),
57export default function IssueChild() {
58 const { pop } = useLocalRouter();
59 const { contracts } = useNetwork();
60 const { pointCursor } = usePointCursor();
62 const _contracts = need.contracts(contracts);
63 const _point = convertToInt(need.point(pointCursor), 10);
65 const availablePointsPromise = useConstant(() =>
67 .getUnspawnedChildren(_contracts, _point)
68 .then(points => new Set(points))
71 const candidates = useMemo(() => {
72 const getCandidate = () => ob.patp(getSpawnCandidate(_point));
74 return [getCandidate(), getCandidate(), getCandidate(), getCandidate()];
86 const validateFormAsync = useCallback(
88 const point = patp2dec(values.point);
89 const hasPoint = (await availablePointsPromise).has(point);
92 return { point: 'This point cannot be spawned.' };
95 [availablePointsPromise]
98 const validateForm = useCallback(
100 if (hasErrors(errors)) {
104 return validateFormAsync(values, errors);
109 const validate = useMemo(
113 point: buildPointValidator(4, [validateChild(ob.patp(_point))]),
114 owner: buildAddressValidator(),
118 [_point, validateForm]
121 const onValues = useCallback(
122 ({ valid, values }) => {
124 construct(patp2dec(values.point), values.owner);
129 [construct, unconstruct]
132 const { isStar } = useCurrentPermissions();
135 <View pop={pop} inset>
137 <Grid.Item full as={ViewHeader}>
138 Spawn {isStar ? ' Planets' : ' Stars'}
142 <Grid.Item full as={Text}>
143 Perhaps one of {candidates.slice(0, 3).join(', ')}, or{' '}
144 {candidates[candidates.length - 1]}?
148 <BridgeForm validate={validate} onValues={onValues}>
149 {({ handleSubmit, values }) => (
155 className={cn('f5 wrap', {
158 {values.point} has been spawned and can be claimed by{' '}
159 <CopiableAddress>{values.owner}</CopiableAddress>.
169 disabled={inputsLocked}
177 label="Ethereum Address"
178 disabled={inputsLocked}
183 <Grid.Item full as={FormError} />
187 as={InlineEthereumTransaction}
189 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