1import React from 'react';
2import Maybe from 'folktale/maybe';
3import * as azimuth from 'azimuth-js';
4import * as ob from 'urbit-ob';
5import * as need from '../lib/need';
7import { Button } from '../components/old/Base';
8import { Row, Col, H1, P, Anchor } from '../components/old/Base';
15} from '../components/old/Base';
16import StatelessTransaction from '../components/old/StatelessTransaction';
18import { NETWORK_TYPES } from '../lib/network';
19import { canDecodePatp } from '../lib/txn';
21import { ETH_ZERO_ADDR, isValidAddress, eqAddr } from '../lib/wallet';
23import { isValidGalaxy, compose } from '../lib/lib';
24import { withNetwork } from '../store/network';
25import { withWallet } from '../store/wallet';
27const buttonTriState = status => {
28 if (status === null) return 'blue';
29 if (status === false) return 'yellow';
30 if (status === true) return 'green';
33const buttonTriStateText = status => {
34 if (status === null) return 'Confirm Galaxy Availablility';
35 if (status === false) return 'Galaxy is Not Available';
36 if (status === true) return 'Galaxy is Available';
39class CreateGalaxy extends React.Component {
43 const galaxyOwner = need.address(props);
46 galaxyOwner: galaxyOwner,
51 this.handleAddressInput = this.handleAddressInput.bind(this);
52 this.handleGalaxyNameInput = this.handleGalaxyNameInput.bind(this);
53 this.confirmAvailability = this.confirmAvailability.bind(this);
54 this.createUnsignedTxn = this.createUnsignedTxn.bind(this);
55 this.statelessRef = React.createRef();
58 handleGalaxyNameInput = galaxyName => {
59 this.setState({ galaxyName, isAvailable: null });
60 this.statelessRef.current.clearTxn();
63 handleAddressInput = galaxyOwner => {
64 this.setState({ galaxyOwner });
65 this.statelessRef.current.clearTxn();
68 createUnsignedTxn = () => {
69 const { state, props } = this;
70 if (isValidAddress(state.galaxyOwner) === false) return Maybe.Nothing();
71 if (state.isAvailable === false) return Maybe.Nothing();
72 if (canDecodePatp(state.galaxyName) === false) return Maybe.Nothing();
73 if (isValidGalaxy(state.galaxyName) === false) return Maybe.Nothing();
75 const validContracts = need.contracts(props);
77 const galaxyDec = parseInt(ob.patp2dec(state.galaxyName), 10);
79 const txn = azimuth.ecliptic.createGalaxy(
85 return Maybe.Just(txn);
88 confirmAvailability = async () => {
89 const { state, props } = this;
91 if (canDecodePatp(state.galaxyName) === false) {
92 this.setState({ isAvailable: false });
96 const validContracts = need.contracts(props);
98 const galaxyDec = ob.patp2dec(state.galaxyName);
100 const currentOwner = await azimuth.azimuth.getOwner(
105 const available = eqAddr(currentOwner, ETH_ZERO_ADDR);
107 this.setState({ isAvailable: available });
111 const { props, state } = this;
113 const validAddress = isValidAddress(state.galaxyOwner);
114 const validGalaxy = isValidGalaxy(state.galaxyName);
117 validAddress === true &&
118 validGalaxy === true &&
119 state.isAvailable === true;
122 props.networkType === NETWORK_TYPES.ROPSTEN ||
123 props.networkType === NETWORK_TYPES.MAINNET;
126 props.networkType === NETWORK_TYPES.ROPSTEN
127 ? 'ropsten.etherscan.io'
133 <H1> {'Create a Galaxy'} </H1>
136 {'Enter the galaxy to create and the address that will own ' +
137 'it (defaulting to this account, if not provided).'}
143 prop-format="innerLabel"
145 placeholder="e.g. ~zod"
146 value={state.galaxyName}
147 onChange={v => this.handleGalaxyNameInput(v)}>
148 <InnerLabel>{'Galaxy Name'}</InnerLabel>
150 className="tr-0 mt-05 mr-0 abs"
151 patp={state.galaxyName}
158 className="mono mt-8"
160 prop-format="innerLabel"
161 value={state.galaxyOwner}
162 onChange={v => this.handleAddressInput(v)}>
163 <InnerLabel>{'Address that will own this galaxy'}</InnerLabel>
164 <ShowBlockie className={'mt-1'} address={state.galaxyOwner} />
170 prop-disabled={!validAddress || !esvisible}
172 href={`https://${esdomain}/address/${state.galaxyOwner}`}>
173 {'View on Etherscan ↗'}
179 prop-color={buttonTriState(state.isAvailable)}
180 disabled={!validGalaxy}
181 onClick={() => this.confirmAvailability()}>
182 {buttonTriStateText(state.isAvailable)}
185 <StatelessTransaction
186 ref={this.statelessRef}
187 canGenerate={canGenerate}
188 createUnsignedTxn={this.createUnsignedTxn}
196export default compose(
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