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, Form } from '../components/Base'
9import StatelessTransaction from '../components/StatelessTransaction'
11import { BRIDGE_ERROR } from '../lib/error'
14 sendSignedTransaction,
19import { ROUTE_NAMES } from '../lib/router'
22 addressFromSecp256k1Public,
33const buttonTriState = status => {
34 if (status === null) return 'blue'
35 if (status === false) return 'yellow'
36 if (status === true) return 'green'
39const buttonTriStateText = status => {
40 if (status === null) return 'Confirm Galaxy Availablility'
41 if (status === false) return 'Galaxy is Not Available'
42 if (status === true) return 'Galaxy is Available'
47class CreateGalaxy extends React.Component {
51 const galaxyOwner = props.wallet.matchWith({
52 Just: (wal) => addressFromSecp256k1Public(wal.value.publicKey),
54 throw BRIDGE_ERROR.MISSING_WALLET
59 galaxyOwner: galaxyOwner,
72 this.handleAddressInput = this.handleAddressInput.bind(this)
73 this.handleGalaxyNameInput = this.handleGalaxyNameInput.bind(this)
74 this.confirmAvailability = this.confirmAvailability.bind(this)
75 this.handleSubmit = this.handleSubmit.bind(this)
79 const { props } = this
80 const addr = props.wallet.matchWith({
81 Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
83 throw BRIDGE_ERROR.MISSING_WALLET
87 // getTxnInfo(props.web3.value, addr).then(txInfo => this.setState(txInfo))
88 props.web3.map(w3 => getTxnInfo(w3, addr)
89 .then(txInfo => this.setState(txInfo))
94 handleGalaxyNameInput = (galaxyName) => {
95 this.setState({ galaxyName, isAvailable: null })
96 this.clearTransaction()
99 handleAddressInput = (galaxyOwner) => {
100 this.setState({ galaxyOwner })
101 this.clearTransaction()
104 createUnsignedTxn = () => {
105 const { state, props } = this
106 if (isValidAddress(state.galaxyOwner) === false) return Maybe.Nothing()
107 if (state.isAvailable === false) return Maybe.Nothing()
108 if (canDecodePatp(state.galaxyName) === false) return Maybe.Nothing()
109 if (isValidGalaxy(state.galaxyName) === false) return Maybe.Nothing()
111 const validContracts = props.contracts.matchWith({
112 Just: (cs) => cs.value,
114 throw BRIDGE_ERROR.MISSING_CONTRACTS
118 const galaxyDec = parseInt(ob.patp2dec(state.galaxyName), 10)
120 const txn = azimuth.ecliptic.createGalaxy(
126 this.setState({ txn: Maybe.Just(txn) })
130 handleSubmit = () => {
131 const { props, state } = this
132 sendSignedTransaction(props.web3.value, state.stx)
134 props.setTxnCursor(sent)
136 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
140 confirmAvailability = async () => {
141 const { state, props } = this
143 if (canDecodePatp(state.galaxyName) === false) {
144 this.setState({ isAvailable: false })
148 const validContracts = props.contracts.matchWith({
149 Just: (cs) => cs.value,
151 throw BRIDGE_ERROR.MISSING_CONTRACTS
155 const galaxyDec = ob.patp2dec(state.galaxyName)
157 const currentOwner = await azimuth.azimuth.getOwner(
162 const available = eqAddr(currentOwner, ETH_ZERO_ADDR)
164 this.setState({ isAvailable: available })
168 clearTransaction = () => {
171 txn: Maybe.Nothing(),
172 stx: Maybe.Nothing(),
177 const { props, state } = this
179 const validAddress = isValidAddress(state.galaxyOwner)
180 const validGalaxy = isValidGalaxy(state.galaxyName)
186 <H1> { 'Create a Galaxy' } </H1>
190 'Enter the galaxy to create and the address that will own ' +
191 'it (defaulting to this account, if not provided).'
200 prop-format='innerLabel'
202 placeholder='e.g. ~zod'
203 value={state.galaxyName}
204 onChange={v => this.handleGalaxyNameInput(v)}>
205 <InnerLabel>{ 'Galaxy Name' }</InnerLabel>
207 className='tr-0 mt-05 mr-0 abs'
208 patp={state.galaxyName}
214 className='mono mt-8'
216 prop-format='innerLabel'
217 value={ state.galaxyOwner }
218 onChange={ v => this.handleAddressInput(v) }>
220 { 'Address that will own this galaxy' }
224 address={state.galaxyOwner} />
230 prop-disabled={!validAddress}
232 href={`https://etherscan.io/address/${state.galaxyOwner}`}>
233 {'View on Etherscan ↗'}
239 prop-color={buttonTriState(state.isAvailable)}
240 disabled={!validGalaxy}
241 onClick={() => this.confirmAvailability()}>
242 {buttonTriStateText(state.isAvailable)}
245 <StatelessTransaction
246 address={state.galaxyOwner}
247 shipName={state.galaxyName}
248 isAvailable={state.isAvailable}
250 contracts={props.contracts}
251 wallet={props.wallet}
252 walletType={props.walletType}
253 walletHdPath={props.walletHdPath}
255 txApproval={state.txApproval}
259 gasPrice={state.gasPrice}
260 chainId={state.chainId}
261 gasLimit={state.gasLimit}
263 validAddress === true &&
264 validGalaxy === true &&
265 state.isAvailable === true
267 canSign={!Maybe.Nothing.hasInstance(state.txn)}
268 canSend={!Maybe.Nothing.hasInstance(state.stx)}
270 createUnsignedTxn={() => this.createUnsignedTxn()}
271 clearTransaction={() => this.clearTransaction()}
272 setApproval={() => this.setState({txApproval: !state.txApproval})}
273 setTxn={txn => this.setState({txn})}
274 setStx={stx => this.setState({stx})}
275 setNonce={nonce => this.setState({nonce})}
276 setChainId={chainId => this.setState({chainId})}
277 setGasPrice={gasPrice => this.setState({gasPrice})}
278 setGasLimit={gasLimit => this.setState({gasLimit})}
279 handleSubmit={this.handleSubmit} />
291export 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