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,
67 showGasDetails: false,
75 this.handleAddressInput = this.handleAddressInput.bind(this)
76 this.handleGalaxyNameInput = this.handleGalaxyNameInput.bind(this)
77 this.confirmAvailability = this.confirmAvailability.bind(this)
78 this.handleSubmit = this.handleSubmit.bind(this)
79 this.toggleGasDetails = this.toggleGasDetails.bind(this)
84 showGasDetails: !this.state.showGasDetails
89 const { props } = this
90 const addr = props.wallet.matchWith({
91 Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
93 throw BRIDGE_ERROR.MISSING_WALLET
97 // getTxnInfo(props.web3.value, addr).then(txInfo => this.setState(txInfo))
98 props.web3.map(w3 => getTxnInfo(w3, addr)
99 .then(txInfo => this.setState(txInfo))
104 handleGalaxyNameInput = (galaxyName) => {
105 this.setState({ galaxyName, isAvailable: null })
106 this.clearTransaction()
109 handleAddressInput = (galaxyOwner) => {
110 this.setState({ galaxyOwner })
111 this.clearTransaction()
114 createUnsignedTxn = () => {
115 const { state, props } = this
116 if (isValidAddress(state.galaxyOwner) === false) return Maybe.Nothing()
117 if (state.isAvailable === false) return Maybe.Nothing()
118 if (canDecodePatp(state.galaxyName) === false) return Maybe.Nothing()
119 if (isValidGalaxy(state.galaxyName) === false) return Maybe.Nothing()
121 const validContracts = props.contracts.matchWith({
122 Just: (cs) => cs.value,
124 throw BRIDGE_ERROR.MISSING_CONTRACTS
128 const galaxyDec = parseInt(ob.patp2dec(state.galaxyName), 10)
130 const txn = azimuth.ecliptic.createGalaxy(
136 this.setState({ txn: Maybe.Just(txn) })
140 handleSubmit = () => {
141 const { props, state } = this
142 sendSignedTransaction(props.web3.value, state.stx)
144 props.setTxnHashCursor(sent)
146 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
150 confirmAvailability = async () => {
151 const { state, props } = this
153 if (canDecodePatp(state.galaxyName) === false) {
154 this.setState({ isAvailable: false })
158 const validContracts = props.contracts.matchWith({
159 Just: (cs) => cs.value,
161 throw BRIDGE_ERROR.MISSING_CONTRACTS
165 const galaxyDec = ob.patp2dec(state.galaxyName)
167 const currentOwner = await azimuth.azimuth.getOwner(
172 const available = eqAddr(currentOwner, ETH_ZERO_ADDR)
174 this.setState({ isAvailable: available })
178 clearTransaction = () => {
181 txn: Maybe.Nothing(),
182 stx: Maybe.Nothing(),
187 const { props, state } = this
189 const validAddress = isValidAddress(state.galaxyOwner)
190 const validGalaxy = isValidGalaxy(state.galaxyName)
193 props.networkType === NETWORK_NAMES.ROPSTEN ||
194 props.networkType === NETWORK_NAMES.MAINNET
197 props.networkType === NETWORK_NAMES.ROPSTEN
198 ? "ropsten.etherscan.io"
204 <H1> { 'Create a Galaxy' } </H1>
208 'Enter the galaxy to create and the address that will own ' +
209 'it (defaulting to this account, if not provided).'
216 prop-format='innerLabel'
218 placeholder='e.g. ~zod'
219 value={state.galaxyName}
220 onChange={v => this.handleGalaxyNameInput(v)}>
221 <InnerLabel>{ 'Galaxy Name' }</InnerLabel>
223 className='tr-0 mt-05 mr-0 abs'
224 patp={state.galaxyName}
230 className='mono mt-8'
232 prop-format='innerLabel'
233 value={ state.galaxyOwner }
234 onChange={ v => this.handleAddressInput(v) }>
236 { 'Address that will own this galaxy' }
240 address={state.galaxyOwner} />
246 prop-disabled={!validAddress || !esvisible}
248 href={`https://${esdomain}/address/${state.galaxyOwner}`}>
249 {'View on Etherscan ↗'}
255 prop-color={buttonTriState(state.isAvailable)}
256 disabled={!validGalaxy}
257 onClick={() => this.confirmAvailability()}>
258 {buttonTriStateText(state.isAvailable)}
261 <StatelessTransaction
262 address={state.galaxyOwner}
263 shipName={state.galaxyName}
264 isAvailable={state.isAvailable}
266 contracts={props.contracts}
267 wallet={props.wallet}
268 walletType={props.walletType}
269 walletHdPath={props.walletHdPath}
270 networkType={props.networkType}
272 txApproval={state.txApproval}
276 gasPrice={state.gasPrice}
277 showGasDetails={state.showGasDetails}
278 toggleGasDetails={this.toggleGasDetails}
279 chainId={state.chainId}
280 gasLimit={state.gasLimit}
282 validAddress === true &&
283 validGalaxy === true &&
284 state.isAvailable === true
286 canSign={Maybe.Just.hasInstance(state.txn)}
287 canSend={Maybe.Just.hasInstance(state.stx)}
289 createUnsignedTxn={() => this.createUnsignedTxn()}
290 clearTransaction={() => this.clearTransaction()}
291 setApproval={() => this.setState({txApproval: !state.txApproval})}
292 setTxn={txn => this.setState({txn})}
293 setStx={stx => this.setState({stx})}
294 setNonce={nonce => this.setState({nonce})}
295 setChainId={chainId => this.setState({chainId})}
296 setGasPrice={gasPrice => this.setState({gasPrice})}
297 setGasLimit={gasLimit => this.setState({gasLimit})}
298 handleSubmit={this.handleSubmit} />
309export 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