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 { usePointCache } from 'store/pointCache';
10import * as need from 'lib/need';
11import { useAddressInput, useGalaxyInput } from 'lib/useInputs';
12import useEthereumTransaction from 'lib/useEthereumTransaction';
13import { GAS_LIMITS } from 'lib/constants';
14import patp2dec from 'lib/patp2dec';
15import { isZeroAddress } from 'lib/wallet';
16import { useLocalRouter } from 'lib/LocalRouter';
18import ViewHeader from 'components/ViewHeader';
19import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
20import View from 'components/View';
22function useCreateGalaxy() {
23 const { contracts } = useNetwork();
24 const { syncKnownPoint } = usePointCache();
26 const _contracts = need.contracts(contracts);
28 const [galaxy, setGalaxy] = useState();
30 return useEthereumTransaction(
34 return azimuth.ecliptic.createGalaxy(_contracts, galaxy, owner);
38 useCallback(() => syncKnownPoint(galaxy), [galaxy, syncKnownPoint]),
43export default function CreateGalaxy() {
44 const { pop } = useLocalRouter();
45 const { contracts } = useNetwork();
46 const _contracts = need.contracts(contracts);
48 const [error, setError] = useState();
49 const [isAvailable, setIsAvailable] = useState(Nothing());
57 } = useCreateGalaxy();
61 { pass: validGalaxyName, syncPass: syncValidGalaxyName, value: galaxyName },
62 // ^ we use value: here so our effect runs onChange
65 disabled: inputsLocked,
69 isAvailable.matchWith({
70 Nothing: () => 'Loading availability...', // TODO: make async loading?
71 Just: p => (p.value ? undefined : 'This galaxy is already owned.'),
75 const [ownerInput, { pass: validOwner, data: owner }] = useAddressInput({
77 label: `Ethereum Address`,
78 disabled: inputsLocked,
82 if (validGalaxyName && validOwner) {
83 construct(patp2dec(galaxyName), owner);
87 }, [owner, construct, unconstruct, validGalaxyName, validOwner, galaxyName]);
90 if (!syncValidGalaxyName || inputsLocked) {
95 setIsAvailable(Nothing());
97 let cancelled = false;
101 const currentOwner = await azimuth.azimuth.getOwner(
106 const isAvailable = isZeroAddress(currentOwner);
112 setIsAvailable(Just(isAvailable));
114 console.error(error);
115 setError(error.message);
116 setIsAvailable(Just(false));
120 return () => (cancelled = true);
130 <View pop={pop} inset>
132 <Grid.Item full as={ViewHeader}>
140 className={cn('f5', {
143 {galaxyName} has been created and can be claimed by {owner}.
147 <Grid.Item full as={Input} {...galaxyNameInput} className="mt4" />
148 <Grid.Item full as={Input} {...ownerInput} className="mb4" />
152 as={InlineEthereumTransaction}
154 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