1import React, { useCallback, useMemo, useState } from 'react';
2import cn from 'classnames';
3import { Grid, Text } 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, AddressInput } from 'form/Inputs';
24 buildAddressValidator,
26} from 'form/validators';
27import FormError from 'form/FormError';
29function useCreateGalaxy() {
30 const { contracts } = useNetwork();
31 const { syncKnownPoint } = usePointCache();
33 const _contracts = need.contracts(contracts);
35 const [galaxy, setGalaxy] = useState();
37 return useEthereumTransaction(
41 return azimuth.ecliptic.createGalaxy(_contracts, galaxy, owner);
45 useCallback(() => syncKnownPoint(galaxy), [galaxy, syncKnownPoint]),
50export default function CreateGalaxy() {
51 const { pop } = useLocalRouter();
52 const { contracts } = useNetwork();
53 const _contracts = need.contracts(contracts);
61 } = useCreateGalaxy();
63 const validateFormAsync = useCallback(
65 const currentOwner = await azimuth.azimuth.getOwner(
67 patp2dec(values.galaxyName)
70 const isAvailable = isZeroAddress(currentOwner);
72 return { galaxyName: 'This galaxy is already spawned and owned.' };
78 const validateForm = useCallback(
80 if (hasErrors(errors)) {
84 return validateFormAsync(values, errors);
89 const validate = useMemo(
93 galaxyName: buildPointValidator(1),
94 owner: buildAddressValidator(),
101 const onValues = useCallback(
102 ({ valid, values }) => {
104 construct(patp2dec(values.galaxyName), values.owner);
109 [construct, unconstruct]
113 <View pop={pop} inset>
115 <Grid.Item full as={ViewHeader}>
119 <BridgeForm validate={validate} onValues={onValues}>
120 {({ handleSubmit, values }) => (
126 className={cn('f5 wrap', {
129 {values.galaxyName} has been created and can be claimed by{' '}
140 disabled={inputsLocked}
147 label="Ethereum Address"
148 disabled={inputsLocked}
151 <Grid.Item full as={FormError} />
155 as={InlineEthereumTransaction}
157 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