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();
32 construct: _construct,
37 } = useEthereumTransaction(GAS_LIMITS.DEFAULT);
39 const construct = useCallback(
42 _construct(azimuth.ecliptic.createGalaxy(_contracts, galaxy, owner));
44 [_construct, _contracts]
49 syncKnownPoint(galaxy);
51 }, [confirmed, galaxy, syncKnownPoint]);
62export default function CreateGalaxy() {
63 const { pop } = useHistory();
64 const { contracts } = useNetwork();
65 const _contracts = need.contracts(contracts);
67 const [error, setError] = useState();
68 const [isAvailable, setIsAvailable] = useState(Nothing());
76 } = useCreateGalaxy();
80 { pass: validGalaxyName, syncPass: syncValidGalaxyName, value: galaxyName },
81 // ^ we use value: here so our effect runs onChange
83 disabled: inputsLocked,
87 isAvailable.matchWith({
88 Nothing: () => 'Loading availabiliy...', // TODO: make async loading?
89 Just: p => (p.value ? undefined : 'This galaxy is already owned.'),
93 const [ownerInput, { pass: validOwner, data: owner }] = useAddressInput({
95 label: `Ethereum Address`,
96 disabled: inputsLocked,
100 if (validGalaxyName && validOwner) {
101 construct(patp2dec(galaxyName), owner);
105 }, [owner, construct, unconstruct, validGalaxyName, validOwner, galaxyName]);
108 if (!syncValidGalaxyName || inputsLocked) {
113 setIsAvailable(Nothing());
115 let cancelled = false;
119 const currentOwner = await azimuth.azimuth.getOwner(
124 const isAvailable = isZeroAddress(currentOwner);
130 setIsAvailable(Just(isAvailable));
132 console.error(error);
133 setError(error.message);
134 setIsAvailable(Just(false));
138 return () => (cancelled = true);
150 <Grid.Item full as={MiniBackButton} onClick={() => pop()} />
152 <Grid.Item full as={ViewHeader}>
160 className={cn('f5', {
163 {galaxyName} has been created and is owned by {owner}.
167 <Grid.Item full as={Input} {...galaxyNameInput} className="mt4" />
168 <Grid.Item full as={Input} {...ownerInput} className="mb4" />
172 as={InlineEthereumTransaction}
174 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