1import React, { useCallback, useEffect, useState } from 'react';
2import { Nothing, Just } from 'folktale/maybe';
3import cn from 'classnames';
4import { Grid, Text, Input } from 'indigo-react';
5import * as azimuth from 'azimuth-js';
7import { useNetwork } from 'store/network';
8import { useHistory } from 'store/history';
9import { usePointCache } from 'store/pointCache';
11import * as need from 'lib/need';
12import { useAddressInput, useGalaxyInput } from 'lib/useInputs';
13import useEthereumTransaction from 'lib/useEthereumTransaction';
14import { GAS_LIMITS } from 'lib/constants';
15import patp2dec from 'lib/patp2dec';
17import ViewHeader from 'components/ViewHeader';
18import MiniBackButton from 'components/MiniBackButton';
19import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
20import View from 'components/View';
21import { isZeroAddress } from 'lib/wallet';
23function useCreateGalaxy() {
24 const { contracts } = useNetwork();
25 const { syncKnownPoint } = usePointCache();
27 const _contracts = need.contracts(contracts);
29 const [galaxy, setGalaxy] = useState();
31 return useEthereumTransaction(
35 return azimuth.ecliptic.createGalaxy(_contracts, galaxy, owner);
39 useCallback(() => syncKnownPoint(galaxy), [galaxy, syncKnownPoint]),
44export default function CreateGalaxy() {
45 const { pop } = useHistory();
46 const { contracts } = useNetwork();
47 const _contracts = need.contracts(contracts);
49 const [error, setError] = useState();
50 const [isAvailable, setIsAvailable] = useState(Nothing());
58 } = useCreateGalaxy();
62 { pass: validGalaxyName, syncPass: syncValidGalaxyName, value: galaxyName },
63 // ^ we use value: here so our effect runs onChange
66 disabled: inputsLocked,
70 isAvailable.matchWith({
71 Nothing: () => 'Loading availability...', // TODO: make async loading?
72 Just: p => (p.value ? undefined : 'This galaxy is already owned.'),
76 const [ownerInput, { pass: validOwner, data: owner }] = useAddressInput({
78 label: `Ethereum Address`,
79 disabled: inputsLocked,
83 if (validGalaxyName && validOwner) {
84 construct(patp2dec(galaxyName), owner);
88 }, [owner, construct, unconstruct, validGalaxyName, validOwner, galaxyName]);
91 if (!syncValidGalaxyName || inputsLocked) {
96 setIsAvailable(Nothing());
98 let cancelled = false;
102 const currentOwner = await azimuth.azimuth.getOwner(
107 const isAvailable = isZeroAddress(currentOwner);
113 setIsAvailable(Just(isAvailable));
115 console.error(error);
116 setError(error.message);
117 setIsAvailable(Just(false));
121 return () => (cancelled = true);
133 <Grid.Item full as={MiniBackButton} onClick={() => pop()} />
135 <Grid.Item full as={ViewHeader}>
143 className={cn('f5', {
146 {galaxyName} has been created and can be claimed by {owner}.
150 <Grid.Item full as={Input} {...galaxyNameInput} className="mt4" />
151 <Grid.Item full as={Input} {...ownerInput} className="mb4" />
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