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, InnerLabel } from '../components/Base'
10import StatelessTransaction from '../components/StatelessTransaction'
12import { ROUTE_NAMES } from '../lib/router'
13import { NETWORK_NAMES } from '../lib/network'
14import { BRIDGE_ERROR } from '../lib/error'
15import { getSpawnCandidate } from '../lib/child'
18 sendSignedTransaction,
26 addressFromSecp256k1Public
29class IssueChild extends React.Component {
34 const issuingPoint = props.pointCursor.matchWith({
35 Just: (pt) => parseInt(pt.value, 10),
37 throw BRIDGE_ERROR.MISSING_POINT
41 const getCandidate = () => ob.patp(getSpawnCandidate(issuingPoint))
51 txError: Maybe.Nothing(),
53 issuingPoint: issuingPoint,
55 isAvailable: Maybe.Nothing(), // allow attempt when offline
63 suggestions: suggestions,
66 this.handlePointInput = this.handlePointInput.bind(this)
67 this.handleAddressInput = this.handleAddressInput.bind(this)
68 this.handleConfirmAvailability = this.handleConfirmAvailability.bind(this)
70 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
71 this.handleSubmit = this.handleSubmit.bind(this)
72 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
73 this.handleSetTxn = this.handleSetTxn.bind(this)
74 this.handleSetStx = this.handleSetStx.bind(this)
75 this.handleSetNonce = this.handleSetNonce.bind(this)
76 this.handleSetChainId = this.handleSetChainId.bind(this)
77 this.handleSetGasPrice = this.handleSetGasPrice.bind(this)
78 this.handleSetGasLimit = this.handleSetGasLimit.bind(this)
82 const { props } = this
84 const addr = props.wallet.matchWith({
85 Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
87 throw BRIDGE_ERROR.MISSING_WALLET
91 props.web3.matchWith({
94 const validWeb3 = w3.value
96 const getTxMetadata = [
97 validWeb3.eth.getTransactionCount(addr),
98 validWeb3.eth.net.getId(),
99 validWeb3.eth.getGasPrice()
102 Promise.all(getTxMetadata).then(r => {
106 gasPrice: fromWei(r[2], 'gwei'),
109 this.setState({...txMetadata})
119 handleAddressInput = (receivingAddress) => {
120 this.setState({ receivingAddress })
121 this.handleClearTxn()
126 handlePointInput(desiredPoint) {
127 if (desiredPoint.length < 15) {
130 isAvailable: Maybe.Nothing()
132 this.handleClearTxn()
138 handleConfirmAvailability() {
139 this.confirmPointAvailability().then(r => {
149 handleCreateUnsignedTxn() {
150 const txn = this.createUnsignedTxn()
151 this.setState({ txn })
155 handleSetUserApproval(){
157 this.setState({ userApproval: !state.userApproval })
163 this.setState({ txn })
177 handleSetNonce(nonce){
178 this.setState({ nonce })
179 this.handleClearStx()
184 handleSetChainId(chainId){
185 this.setState({ chainId })
186 this.handleClearStx()
191 handleSetGasPrice(gasPrice){
192 this.setState({ gasPrice })
193 this.handleClearStx()
198 handleSetGasLimit(gasLimit){
199 this.setState({ gasLimit })
200 this.handleClearStx()
208 stx: Maybe.Nothing(),
217 txn: Maybe.Nothing(),
218 stx: Maybe.Nothing(),
224 handleClearTransaction() {
227 txn: Maybe.Nothing(),
228 stx: Maybe.Nothing(),
235 const { props, state } = this
236 sendSignedTransaction(props.web3.value, state.stx)
238 props.setTxnCursor(sent)
240 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
243 // Note that value.value is due to wrapped Maybe.Just + Result.Error
244 this.setState({ txError: Maybe.Just(err.value.value) })
250 async confirmPointAvailability() {
251 const { state, props } = this
253 if (canDecodePatp(state.desiredPoint) === false) return Maybe.Just(false)
255 const validContracts = props.contracts.matchWith({
256 Just: (cs) => cs.value,
258 throw BRIDGE_ERROR.MISSING_CONTRACTS
262 const pointDec = ob.patp2dec(state.desiredPoint)
264 const owner = await azimuth.azimuth.getOwner(
269 if (eqAddr(owner, ETH_ZERO_ADDR)) return Maybe.Just(true)
271 return Maybe.Just(false)
276 createUnsignedTxn() {
277 const { state, props } = this
279 if (isValidAddress(state.receivingAddress) === false) return Maybe.Nothing()
280 if (state.isAvailable === false) return Maybe.Nothing()
281 if (canDecodePatp(state.desiredPoint) === false) return Maybe.Nothing()
283 const validContracts = props.contracts.matchWith({
284 Just: (cs) => cs.value,
286 throw BRIDGE_ERROR.MISSING_CONTRACTS
290 const pointDec = ob.patp2dec(state.desiredPoint)
292 const txn = azimuth.ecliptic.spawn(
295 state.receivingAddress
298 return Maybe.Just(txn)
304 const a = this.state.isAvailable
305 if (Maybe.Nothing.hasInstance(a)) return 'blue'
306 if (a.value === false) return 'yellow'
307 if (a.value === true) return 'green'
312 buttonTriStateText() {
313 const a = this.state.isAvailable
314 if (Maybe.Nothing.hasInstance(a)) return 'Confirm Availablility'
315 if (a.value === false) return 'Point is Not Available'
316 if (a.value === true) return 'Available'
319 validatePoint = patp => {
320 const point = this.point
324 vpatp = ob.isValidPatp(patp)
330 vchild = ob.sein(patp) === ob.patp(point)
334 return vpatp && vchild
339 const { props, state } = this
341 const validAddress = isValidAddress(state.receivingAddress)
342 const validPoint = canDecodePatp(state.desiredPoint)
344 const canGenerate = props.web3.matchWith({
346 return validAddress === true &&
350 return validAddress === true &&
351 validPoint === true &&
352 state.isAvailable.value === true
356 const canSign = !Maybe.Nothing.hasInstance(state.txn)
357 const canApprove = !Maybe.Nothing.hasInstance(state.stx)
358 const canSend = !Maybe.Nothing.hasInstance(state.stx) && state.userApproval === true
361 props.networkType === NETWORK_NAMES.ROPSTEN ||
362 props.networkType === NETWORK_NAMES.MAINNET
365 props.networkType === NETWORK_NAMES.ROPSTEN
366 ? "ropsten.etherscan.io"
373 { 'Issue a Child From ' } <code>{ `${ob.patp(state.issuingPoint)}` }</code>
379 `Please enter the point you would like to issue, and specify the
380 receiving Ethereum address. If you need to create an address, you
381 can also use Wallet Generator.`
387 `Your point can only issue children with particular names. Some
388 valid suggestions for `
392 { ob.patp(state.issuingPoint) }
399 { state.suggestions[0] }
403 { state.suggestions[1] }
407 { 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) || !esvisible}
445 href={`https://${esdomain}/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}
471 networkType={props.networkType}
477 gasPrice={state.gasPrice}
478 chainId={state.chainId}
479 gasLimit={state.gasLimit}
481 userApproval={state.userApproval}
482 canGenerate={ canGenerate }
484 canApprove={ canApprove }
487 createUnsignedTxn={this.handleCreateUnsignedTxn}
488 setUserApproval={this.handleSetUserApproval}
489 setTxn={this.handleSetTxn}
490 setStx={this.handleSetStx}
491 setNonce={this.handleSetNonce}
492 setChainId={this.handleSetChainId}
493 setGasPrice={this.handleSetGasPrice}
494 setGasLimit={this.handleSetGasLimit}
495 handleSubmit={this.handleSubmit} />
498 Maybe.Nothing.hasInstance(state.txError)
500 : <Warning className={'mt-8'}>
501 <H3 style={{marginTop: 0, paddingTop: 0}}>
503 'There was an error sending your transaction.'
506 { 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