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 const owner = await azimuth.azimuth.getOwner(
268 if (eqAddr(owner, ETH_ZERO_ADDR)) return Maybe.Just(true)
270 return Maybe.Just(false)
275 createUnsignedTxn() {
276 const { state, props } = this
278 if (isValidAddress(state.receivingAddress) === false) return Maybe.Nothing()
279 if (state.isAvailable === false) return Maybe.Nothing()
280 if (canDecodePatp(state.desiredPoint) === false) return Maybe.Nothing()
282 const validContracts = props.contracts.matchWith({
283 Just: (cs) => cs.value,
285 throw BRIDGE_ERROR.MISSING_CONTRACTS
289 const pointDec = ob.patp2dec(state.desiredPoint)
291 const txn = azimuth.ecliptic.spawn(
294 state.receivingAddress
297 return Maybe.Just(txn)
303 const a = this.state.isAvailable
304 if (Maybe.Nothing.hasInstance(a)) return 'blue'
305 if (a.value === false) return 'yellow'
306 if (a.value === true) return 'green'
311 buttonTriStateText() {
312 const a = this.state.isAvailable
313 if (Maybe.Nothing.hasInstance(a)) return 'Confirm Availablility'
314 if (a.value === false) return 'Point is Not Available'
315 if (a.value === true) return 'Available'
318 validatePoint = patp => {
319 const point = this.point
323 vpatp = ob.isValidPatp(patp)
329 vchild = ob.sein(patp) === ob.patp(point)
333 return vpatp && vchild
338 const { props, state } = this
342 const validAddress = isValidAddress(state.receivingAddress)
343 const validPoint = canDecodePatp(state.desiredPoint)
345 const canGenerate = props.web3.matchWith({
347 return validAddress === true &&
351 return validAddress === true &&
352 validPoint === true &&
353 state.isAvailable.value === true
358 const canSign = !Maybe.Nothing.hasInstance(state.txn)
359 const canApprove = !Maybe.Nothing.hasInstance(state.stx)
360 const canSend = !Maybe.Nothing.hasInstance(state.stx) && state.userApproval === true
366 { 'Issue a Child From ' } <code>{ `${ob.patp(state.issuingPoint)}` }</code>
372 `Please enter the point you would like to issue, and specify the
373 receiving Ethereum address. If you need to create an address, you
374 can also use Wallet Generator.`
380 `Your point can only issue children with particular names. Some
381 valid suggestions for `
385 { ob.patp(state.issuingPoint) }
392 { state.suggestions[0] }
396 { state.suggestions[1] }
400 { state.suggestions[2] }
408 prop-format='innerLabel'
409 className={'mono mt-8'}
410 placeholder={ `e.g. ${state.suggestions[3]}` }
411 value={ state.desiredPoint }
412 onChange={ this.handlePointInput }>
413 <InnerLabel>{ 'Point to Issue' }</InnerLabel>
415 className={'tr-0 mt-05 mr-0 abs'}
416 patp={state.desiredPoint}
419 validator={() => this.validatePoint(state.desiredPoint)} />
423 className='text-mono mt-8'
425 prop-format='innerLabel'
426 placeholder={ `e.g. 0x84295d5e054d8cff5a22428b195f5a1615bd644f` }
427 value={ state.receivingAddress }
428 disabled={ !state.available }
429 onChange={ v => this.handleAddressInput(v) }>
430 <InnerLabel>{ 'Receiving Address' }</InnerLabel>
431 <ShowBlockie className={'mt-1'} address={state.receivingAddress} />
437 prop-disabled={!isValidAddress(state.receivingAddress)}
439 href={`https://etherscan.io/address/${state.receivingAddress}`}>
440 {'View on Etherscan ↗'}
444 props.web3.matchWith({
445 Nothing: _ => <div />,
449 prop-color={this.buttonTriState()}
451 disabled={!validPoint}
452 onClick={this.handleConfirmAvailability}>
453 {this.buttonTriStateText()}
458 <StatelessTransaction
461 contracts={props.contracts}
462 wallet={props.wallet}
463 walletType={props.walletType}
464 walletHdPath={props.walletHdPath}
470 gasPrice={state.gasPrice}
471 chainId={state.chainId}
472 gasLimit={state.gasLimit}
474 userApproval={state.userApproval}
475 canGenerate={ canGenerate }
477 canApprove={ canApprove }
480 createUnsignedTxn={this.handleCreateUnsignedTxn}
481 setUserApproval={this.handleSetUserApproval}
482 setTxn={this.handleSetTxn}
483 setStx={this.handleSetStx}
484 setNonce={this.handleSetNonce}
485 setChainId={this.handleSetChainId}
486 setGasPrice={this.handleSetGasPrice}
487 setGasLimit={this.handleSetGasLimit}
488 handleSubmit={this.handleSubmit} />
493 Maybe.Nothing.hasInstance(state.txError)
495 : <Warning className={'mt-8'}>
496 <H3 style={{marginTop: 0, paddingTop: 0}}>
498 'There was an error sending your transaction.'
501 { state.txError.value }
510export 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