1import React, { useCallback, useMemo, useState } from 'react';
2import cn from 'classnames';
3import { Grid, Text, Input } from 'indigo-react';
4import * as azimuth from 'azimuth-js';
6import { useNetwork } from 'store/network';
7import { usePointCache } from 'store/pointCache';
9import * as need from 'lib/need';
10import useEthereumTransaction from 'lib/useEthereumTransaction';
11import { GAS_LIMITS } from 'lib/constants';
12import patp2dec from 'lib/patp2dec';
13import { isZeroAddress } from 'lib/wallet';
14import { useLocalRouter } from 'lib/LocalRouter';
16import ViewHeader from 'components/ViewHeader';
17import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
18import View from 'components/View';
19import BridgeForm from 'form/BridgeForm';
20import { PointInput } from 'form/Inputs';
24 buildAddressValidator,
25} from 'form/validators';
26import FormError from 'form/FormError';
28function useCreateGalaxy() {
29 const { contracts } = useNetwork();
30 const { syncKnownPoint } = usePointCache();
32 const _contracts = need.contracts(contracts);
34 const [galaxy, setGalaxy] = useState();
36 return useEthereumTransaction(
40 return azimuth.ecliptic.createGalaxy(_contracts, galaxy, owner);
44 useCallback(() => syncKnownPoint(galaxy), [galaxy, syncKnownPoint]),
49export default function CreateGalaxy() {
50 const { pop } = useLocalRouter();
51 const { contracts } = useNetwork();
52 const _contracts = need.contracts(contracts);
60 } = useCreateGalaxy();
62 const validateForm = useCallback(
64 const currentOwner = await azimuth.azimuth.getOwner(
66 patp2dec(values.galaxyName)
69 const isAvailable = isZeroAddress(currentOwner);
71 return { galaxyName: 'This galaxy is already spawned and owned.' };
77 const validate = useMemo(
81 galaxyName: buildPointValidator(1),
82 owner: buildAddressValidator(),
89 const onValues = useCallback(
90 ({ valid, values }) => {
92 construct(patp2dec(values.galaxyName), values.owner);
97 [construct, unconstruct]
101 <View pop={pop} inset>
103 <Grid.Item full as={ViewHeader}>
107 <BridgeForm validate={validate} onValues={onValues}>
108 {({ handleSubmit, values }) => (
114 className={cn('f5', {
117 {values.galaxyName} has been created and can be claimed by{' '}
128 disabled={inputsLocked}
135 label="Ethereum Address"
136 disabled={inputsLocked}
139 <Grid.Item full as={FormError} />
143 as={InlineEthereumTransaction}
145 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