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 validateGalaxy = useCallback(
64 const currentOwner = await azimuth.azimuth.getOwner(
69 const isAvailable = isZeroAddress(currentOwner);
71 return 'This galaxy is already spawned and owned.';
77 const validate = useMemo(
80 galaxyName: buildPointValidator(1, [validateGalaxy]),
81 owner: buildAddressValidator(),
86 const onValues = useCallback(
87 ({ valid, values }) => {
89 construct(patp2dec(values.galaxyName), values.owner);
94 [construct, unconstruct]
98 <View pop={pop} inset>
100 <Grid.Item full as={ViewHeader}>
104 <BridgeForm validate={validate} onValues={onValues}>
105 {({ handleSubmit, values }) => (
111 className={cn('f5', {
114 {values.galaxyName} has been created and can be claimed by{' '}
125 disabled={inputsLocked}
132 label="Ethereum Address"
133 disabled={inputsLocked}
136 <Grid.Item full as={FormError} />
140 as={InlineEthereumTransaction}
142 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