1import React from 'react'
2import Maybe from 'folktale/maybe'
3import * as azimuth from 'azimuth-js'
4import * as ob from 'urbit-ob'
6import { Button, } from '../components/Base'
7import { Row, Col, H1, P, Anchor } from '../components/Base'
8import { InnerLabel, GalaxyInput, AddressInput, ValidatedSigil, ShowBlockie } from '../components/Base'
9import StatelessTransaction from '../components/StatelessTransaction'
11import { BRIDGE_ERROR } from '../lib/error'
13import { NETWORK_NAMES } from '../lib/network'
16 sendSignedTransaction,
21import { ROUTE_NAMES } from '../lib/router'
24 addressFromSecp256k1Public,
35const buttonTriState = status => {
36 if (status === null) return 'blue'
37 if (status === false) return 'yellow'
38 if (status === true) return 'green'
41const buttonTriStateText = status => {
42 if (status === null) return 'Confirm Galaxy Availablility'
43 if (status === false) return 'Galaxy is Not Available'
44 if (status === true) return 'Galaxy is Available'
49class CreateGalaxy extends React.Component {
53 const galaxyOwner = props.wallet.matchWith({
54 Just: (wal) => addressFromSecp256k1Public(wal.value.publicKey),
56 throw BRIDGE_ERROR.MISSING_WALLET
61 galaxyOwner: galaxyOwner,
74 this.handleAddressInput = this.handleAddressInput.bind(this)
75 this.handleGalaxyNameInput = this.handleGalaxyNameInput.bind(this)
76 this.confirmAvailability = this.confirmAvailability.bind(this)
77 this.handleSubmit = this.handleSubmit.bind(this)
81 const { props } = this
82 const addr = props.wallet.matchWith({
83 Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
85 throw BRIDGE_ERROR.MISSING_WALLET
89 // getTxnInfo(props.web3.value, addr).then(txInfo => this.setState(txInfo))
90 props.web3.map(w3 => getTxnInfo(w3, addr)
91 .then(txInfo => this.setState(txInfo))
96 handleGalaxyNameInput = (galaxyName) => {
97 this.setState({ galaxyName, isAvailable: null })
98 this.clearTransaction()
101 handleAddressInput = (galaxyOwner) => {
102 this.setState({ galaxyOwner })
103 this.clearTransaction()
106 createUnsignedTxn = () => {
107 const { state, props } = this
108 if (isValidAddress(state.galaxyOwner) === false) return Maybe.Nothing()
109 if (state.isAvailable === false) return Maybe.Nothing()
110 if (canDecodePatp(state.galaxyName) === false) return Maybe.Nothing()
111 if (isValidGalaxy(state.galaxyName) === false) return Maybe.Nothing()
113 const validContracts = props.contracts.matchWith({
114 Just: (cs) => cs.value,
116 throw BRIDGE_ERROR.MISSING_CONTRACTS
120 const galaxyDec = parseInt(ob.patp2dec(state.galaxyName), 10)
122 const txn = azimuth.ecliptic.createGalaxy(
128 this.setState({ txn: Maybe.Just(txn) })
132 handleSubmit = () => {
133 const { props, state } = this
134 sendSignedTransaction(props.web3.value, state.stx)
136 props.setTxnHashCursor(sent)
138 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
142 confirmAvailability = async () => {
143 const { state, props } = this
145 if (canDecodePatp(state.galaxyName) === false) {
146 this.setState({ isAvailable: false })
150 const validContracts = props.contracts.matchWith({
151 Just: (cs) => cs.value,
153 throw BRIDGE_ERROR.MISSING_CONTRACTS
157 const galaxyDec = ob.patp2dec(state.galaxyName)
159 const currentOwner = await azimuth.azimuth.getOwner(
164 const available = eqAddr(currentOwner, ETH_ZERO_ADDR)
166 this.setState({ isAvailable: available })
170 clearTransaction = () => {
173 txn: Maybe.Nothing(),
174 stx: Maybe.Nothing(),
179 const { props, state } = this
181 const validAddress = isValidAddress(state.galaxyOwner)
182 const validGalaxy = isValidGalaxy(state.galaxyName)
185 props.networkType === NETWORK_NAMES.ROPSTEN ||
186 props.networkType === NETWORK_NAMES.MAINNET
189 props.networkType === NETWORK_NAMES.ROPSTEN
190 ? "ropsten.etherscan.io"
196 <H1> { 'Create a Galaxy' } </H1>
200 'Enter the galaxy to create and the address that will own ' +
201 'it (defaulting to this account, if not provided).'
208 prop-format='innerLabel'
210 placeholder='e.g. ~zod'
211 value={state.galaxyName}
212 onChange={v => this.handleGalaxyNameInput(v)}>
213 <InnerLabel>{ 'Galaxy Name' }</InnerLabel>
215 className='tr-0 mt-05 mr-0 abs'
216 patp={state.galaxyName}
222 className='mono mt-8'
224 prop-format='innerLabel'
225 value={ state.galaxyOwner }
226 onChange={ v => this.handleAddressInput(v) }>
228 { 'Address that will own this galaxy' }
232 address={state.galaxyOwner} />
238 prop-disabled={!validAddress || !esvisible}
240 href={`https://${esdomain}/address/${state.galaxyOwner}`}>
241 {'View on Etherscan ↗'}
247 prop-color={buttonTriState(state.isAvailable)}
248 disabled={!validGalaxy}
249 onClick={() => this.confirmAvailability()}>
250 {buttonTriStateText(state.isAvailable)}
253 <StatelessTransaction
254 address={state.galaxyOwner}
255 shipName={state.galaxyName}
256 isAvailable={state.isAvailable}
258 contracts={props.contracts}
259 wallet={props.wallet}
260 walletType={props.walletType}
261 walletHdPath={props.walletHdPath}
262 networkType={props.networkType}
264 txApproval={state.txApproval}
268 gasPrice={state.gasPrice}
269 chainId={state.chainId}
270 gasLimit={state.gasLimit}
272 validAddress === true &&
273 validGalaxy === true &&
274 state.isAvailable === true
276 canSign={!Maybe.Nothing.hasInstance(state.txn)}
277 canSend={!Maybe.Nothing.hasInstance(state.stx)}
279 createUnsignedTxn={() => this.createUnsignedTxn()}
280 clearTransaction={() => this.clearTransaction()}
281 setApproval={() => this.setState({txApproval: !state.txApproval})}
282 setTxn={txn => this.setState({txn})}
283 setStx={stx => this.setState({stx})}
284 setNonce={nonce => this.setState({nonce})}
285 setChainId={chainId => this.setState({chainId})}
286 setGasPrice={gasPrice => this.setState({gasPrice})}
287 setGasLimit={gasLimit => this.setState({gasLimit})}
288 handleSubmit={this.handleSubmit} />
299export default CreateGalaxy
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