1import Maybe from 'folktale/maybe'
2import React from 'react'
3import * as azimuth from 'azimuth-js'
4import * as ob from 'urbit-ob'
6import { Row, Col, H1, H3, P, Anchor, Warning } from '../components/Base'
7import { Button, ShowBlockie, ValidatedSigil } from '../components/Base'
8import { PointInput, AddressInput, Form, InnerLabel } from '../components/Base'
10import StatelessTransaction from '../components/StatelessTransaction'
12import { ROUTE_NAMES } from '../lib/router'
13import { BRIDGE_ERROR } from '../lib/error'
14import { getSpawnCandidate } from '../lib/child'
17 sendSignedTransaction,
25 addressFromSecp256k1Public
28class IssueChild extends React.Component {
33 const issuingPoint = props.pointCursor.matchWith({
34 Just: (pt) => parseInt(pt.value, 10),
36 throw BRIDGE_ERROR.MISSING_POINT
40 const getCandidate = () => ob.patp(getSpawnCandidate(issuingPoint))
50 txError: Maybe.Nothing(),
52 issuingPoint: issuingPoint,
54 isAvailable: Maybe.Nothing(), // allow attempt when offline
62 suggestions: suggestions,
65 this.handlePointInput = this.handlePointInput.bind(this)
66 this.handleAddressInput = this.handleAddressInput.bind(this)
67 this.handleConfirmAvailability = this.handleConfirmAvailability.bind(this)
69 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
70 this.handleSubmit = this.handleSubmit.bind(this)
71 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
72 this.handleSetTxn = this.handleSetTxn.bind(this)
73 this.handleSetStx = this.handleSetStx.bind(this)
74 this.handleSetNonce = this.handleSetNonce.bind(this)
75 this.handleSetChainId = this.handleSetChainId.bind(this)
76 this.handleSetGasPrice = this.handleSetGasPrice.bind(this)
77 this.handleSetGasLimit = this.handleSetGasLimit.bind(this)
81 const { props } = this
83 const addr = props.wallet.matchWith({
84 Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
86 throw BRIDGE_ERROR.MISSING_WALLET
90 props.web3.matchWith({
93 const validWeb3 = w3.value
95 const getTxMetadata = [
96 validWeb3.eth.getTransactionCount(addr),
97 validWeb3.eth.net.getId(),
98 validWeb3.eth.getGasPrice()
101 Promise.all(getTxMetadata).then(r => {
105 gasPrice: fromWei(r[2], 'gwei'),
108 this.setState({...txMetadata})
118 handleAddressInput = (receivingAddress) => {
119 this.setState({ receivingAddress })
120 this.handleClearTxn()
125 handlePointInput(desiredPoint) {
126 if (desiredPoint.length < 15) {
129 isAvailable: Maybe.Nothing()
131 this.handleClearTxn()
137 handleConfirmAvailability() {
138 this.confirmPointAvailability().then(r => {
148 handleCreateUnsignedTxn() {
149 const txn = this.createUnsignedTxn()
150 this.setState({ txn })
154 handleSetUserApproval(){
156 this.setState({ userApproval: !state.userApproval })
162 this.setState({ txn })
176 handleSetNonce(nonce){
177 this.setState({ nonce })
178 this.handleClearStx()
183 handleSetChainId(chainId){
184 this.setState({ chainId })
185 this.handleClearStx()
190 handleSetGasPrice(gasPrice){
191 this.setState({ gasPrice })
192 this.handleClearStx()
197 handleSetGasLimit(gasLimit){
198 this.setState({ gasLimit })
199 this.handleClearStx()
207 stx: Maybe.Nothing(),
216 txn: Maybe.Nothing(),
217 stx: Maybe.Nothing(),
223 handleClearTransaction() {
226 txn: Maybe.Nothing(),
227 stx: Maybe.Nothing(),
234 const { props, state } = this
235 sendSignedTransaction(props.web3.value, state.stx)
237 props.setTxnCursor(sent)
239 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
242 // Note that value.value is due to wrapped Maybe.Just + Result.Error
243 this.setState({ txError: Maybe.Just(err.value.value) })
249 async confirmPointAvailability() {
250 const { state, props } = this
252 if (canDecodePatp(state.desiredPoint) === false) return Maybe.Just(false)
254 const validContracts = props.contracts.matchWith({
255 Just: (cs) => cs.value,
257 throw BRIDGE_ERROR.MISSING_CONTRACTS
261 const pointDec = ob.patp2dec(state.desiredPoint)
263 // This check prevents galaxies from creating planets, bc right now it results in a failed tx
264 // The intention is for the Azimuth contract to allow this in the future someday soon
265 // This size check will need to be removed at that time
266 const prefixSize = azimuth.azimuth.getPointSize(azimuth.azimuth.getPrefix(pointDec))
267 if (prefixSize + 1 !== azimuth.azimuth.getPointSize(pointDec)) return Maybe.Just(false)
269 const owner = await azimuth.azimuth.getOwner(
274 if (eqAddr(owner, ETH_ZERO_ADDR)) return Maybe.Just(true)
276 return Maybe.Just(false)
281 createUnsignedTxn() {
282 const { state, props } = this
284 if (isValidAddress(state.receivingAddress) === false) return Maybe.Nothing()
285 if (state.isAvailable === false) return Maybe.Nothing()
286 if (canDecodePatp(state.desiredPoint) === false) return Maybe.Nothing()
288 const validContracts = props.contracts.matchWith({
289 Just: (cs) => cs.value,
291 throw BRIDGE_ERROR.MISSING_CONTRACTS
295 const pointDec = ob.patp2dec(state.desiredPoint)
297 const txn = azimuth.ecliptic.spawn(
300 state.receivingAddress
303 return Maybe.Just(txn)
309 const a = this.state.isAvailable
310 if (Maybe.Nothing.hasInstance(a)) return 'blue'
311 if (a.value === false) return 'yellow'
312 if (a.value === true) return 'green'
317 buttonTriStateText() {
318 const a = this.state.isAvailable
319 if (Maybe.Nothing.hasInstance(a)) return 'Confirm Availablility'
320 if (a.value === false) return 'Point is Not Available'
321 if (a.value === true) return 'Available'
324 validatePoint = patp => {
325 const point = this.point
329 vpatp = ob.isValidPatp(patp)
335 vchild = ob.sein(patp) === ob.patp(point)
339 return vpatp && vchild
344 const { props, state } = this
348 const validAddress = isValidAddress(state.receivingAddress)
349 const validPoint = canDecodePatp(state.desiredPoint)
351 const canGenerate = props.web3.matchWith({
353 return validAddress === true &&
357 return validAddress === true &&
358 validPoint === true &&
359 state.isAvailable.value === true
364 const canSign = !Maybe.Nothing.hasInstance(state.txn)
365 const canApprove = !Maybe.Nothing.hasInstance(state.stx)
366 const canSend = !Maybe.Nothing.hasInstance(state.stx) && state.userApproval === true
372 { 'Issue a Child From ' } <code>{ `${ob.patp(state.issuingPoint)}` }</code>
378 `Please enter the point you would like to issue, and specify the
379 receiving Ethereum address. If you need to create an address, you
380 can also use Wallet Generator.`
386 `Your point can only issue children with particular names. Some
387 valid suggestions for `
391 { ob.patp(state.issuingPoint) }
398 { state.suggestions[0] }
402 { state.suggestions[1] }
406 { state.suggestions[2] }
414 prop-format='innerLabel'
415 className={'mono mt-8'}
416 placeholder={ `e.g. ${state.suggestions[3]}` }
417 value={ state.desiredPoint }
418 onChange={ this.handlePointInput }>
419 <InnerLabel>{ 'Point to Issue' }</InnerLabel>
421 className={'tr-0 mt-05 mr-0 abs'}
422 patp={state.desiredPoint}
425 validator={() => this.validatePoint(state.desiredPoint)} />
429 className='text-mono mt-8'
431 prop-format='innerLabel'
432 placeholder={ `e.g. 0x84295d5e054d8cff5a22428b195f5a1615bd644f` }
433 value={ state.receivingAddress }
434 disabled={ !state.available }
435 onChange={ v => this.handleAddressInput(v) }>
436 <InnerLabel>{ 'Receiving Address' }</InnerLabel>
437 <ShowBlockie className={'mt-1'} address={state.receivingAddress} />
443 prop-disabled={!isValidAddress(state.receivingAddress)}
445 href={`https://etherscan.io/address/${state.receivingAddress}`}>
446 {'View on Etherscan ↗'}
450 props.web3.matchWith({
451 Nothing: _ => <div />,
455 prop-color={this.buttonTriState()}
457 disabled={!validPoint}
458 onClick={this.handleConfirmAvailability}>
459 {this.buttonTriStateText()}
464 <StatelessTransaction
467 contracts={props.contracts}
468 wallet={props.wallet}
469 walletType={props.walletType}
470 walletHdPath={props.walletHdPath}
476 gasPrice={state.gasPrice}
477 chainId={state.chainId}
478 gasLimit={state.gasLimit}
480 userApproval={state.userApproval}
481 canGenerate={ canGenerate }
483 canApprove={ canApprove }
486 createUnsignedTxn={this.handleCreateUnsignedTxn}
487 setUserApproval={this.handleSetUserApproval}
488 setTxn={this.handleSetTxn}
489 setStx={this.handleSetStx}
490 setNonce={this.handleSetNonce}
491 setChainId={this.handleSetChainId}
492 setGasPrice={this.handleSetGasPrice}
493 setGasLimit={this.handleSetGasLimit}
494 handleSubmit={this.handleSubmit} />
499 Maybe.Nothing.hasInstance(state.txError)
501 : <Warning className={'mt-8'}>
502 <H3 style={{marginTop: 0, paddingTop: 0}}>
504 'There was an error sending your transaction.'
507 { state.txError.value }
516export default IssueChild
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