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/utils/address';
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';
28import CopiableAddress from 'components/copiable/CopiableAddress';
30function useCreateGalaxy() {
31 const { contracts } = useNetwork();
32 const { syncDates } = usePointCache();
34 const _contracts = need.contracts(contracts);
36 const [galaxy, setGalaxy] = useState();
38 return useEthereumTransaction(
42 return azimuth.ecliptic.createGalaxy(_contracts, galaxy, owner);
46 useCallback(() => syncDates(galaxy), [galaxy, syncDates]),
51export default function CreateGalaxy() {
52 const { pop } = useLocalRouter();
53 const { contracts } = useNetwork();
54 const _contracts = need.contracts(contracts);
62 } = useCreateGalaxy();
64 const validateFormAsync = useCallback(
66 const currentOwner = await azimuth.azimuth.getOwner(
68 patp2dec(values.galaxyName)
71 const isAvailable = isZeroAddress(currentOwner);
73 return { galaxyName: 'This galaxy is already spawned and owned.' };
79 const validateForm = useCallback(
81 if (hasErrors(errors)) {
85 return validateFormAsync(values, errors);
90 const validate = useMemo(
94 galaxyName: buildPointValidator(1),
95 owner: buildAddressValidator(),
102 const onValues = useCallback(
103 ({ valid, values }) => {
105 construct(patp2dec(values.galaxyName), values.owner);
110 [construct, unconstruct]
114 <View pop={pop} inset>
116 <Grid.Item full as={ViewHeader}>
120 <BridgeForm validate={validate} onValues={onValues}>
121 {({ handleSubmit, values }) => (
127 className={cn('f5 wrap', {
130 {values.galaxyName} has been created and can be claimed by{' '}
131 <CopiableAddress>{values.owner}</CopiableAddress>.
141 disabled={inputsLocked}
148 label="Ethereum Address"
149 disabled={inputsLocked}
152 <Grid.Item full as={FormError} />
156 as={InlineEthereumTransaction}
158 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