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
65 disabled: inputsLocked,
69 isAvailable.matchWith({
70 Nothing: () => 'Loading availabiliy...', // 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);
132 <Grid.Item full as={MiniBackButton} onClick={() => pop()} />
134 <Grid.Item full as={ViewHeader}>
142 className={cn('f5', {
145 {galaxyName} has been created and is owned by {owner}.
149 <Grid.Item full as={Input} {...galaxyNameInput} className="mt4" />
150 <Grid.Item full as={Input} {...ownerInput} className="mb4" />
154 as={InlineEthereumTransaction}
156 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