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.setTxnHashCursor(sent)
240 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
243 this.setState({ txError: err.map(val => val.merge()) })
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
340 const validAddress = isValidAddress(state.receivingAddress)
341 const validPoint = canDecodePatp(state.desiredPoint)
343 const canGenerate = props.web3.matchWith({
345 return validAddress === true &&
349 return validAddress === true &&
350 validPoint === true &&
351 state.isAvailable.value === true
355 const canSign = !Maybe.Nothing.hasInstance(state.txn)
356 const canApprove = !Maybe.Nothing.hasInstance(state.stx)
357 const canSend = !Maybe.Nothing.hasInstance(state.stx) && state.userApproval === true
360 props.networkType === NETWORK_NAMES.ROPSTEN ||
361 props.networkType === NETWORK_NAMES.MAINNET
364 props.networkType === NETWORK_NAMES.ROPSTEN
365 ? "ropsten.etherscan.io"
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] }
413 prop-format='innerLabel'
414 className={'mono mt-8'}
415 placeholder={ `e.g. ${state.suggestions[3]}` }
416 value={ state.desiredPoint }
417 onChange={ this.handlePointInput }>
418 <InnerLabel>{ 'Point to Issue' }</InnerLabel>
420 className={'tr-0 mt-05 mr-0 abs'}
421 patp={state.desiredPoint}
424 validator={() => this.validatePoint(state.desiredPoint)} />
428 className='text-mono mt-8'
430 prop-format='innerLabel'
431 placeholder={ `e.g. 0x84295d5e054d8cff5a22428b195f5a1615bd644f` }
432 value={ state.receivingAddress }
433 disabled={ !state.available }
434 onChange={ v => this.handleAddressInput(v) }>
435 <InnerLabel>{ 'Receiving Address' }</InnerLabel>
436 <ShowBlockie className={'mt-1'} address={state.receivingAddress} />
442 prop-disabled={!isValidAddress(state.receivingAddress) || !esvisible}
444 href={`https://${esdomain}/address/${state.receivingAddress}`}>
445 {'View on Etherscan ↗'}
449 props.web3.matchWith({
450 Nothing: _ => <div />,
454 prop-color={this.buttonTriState()}
456 disabled={!validPoint}
457 onClick={this.handleConfirmAvailability}>
458 {this.buttonTriStateText()}
463 <StatelessTransaction
466 contracts={props.contracts}
467 wallet={props.wallet}
468 walletType={props.walletType}
469 walletHdPath={props.walletHdPath}
470 networkType={props.networkType}
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} />
497 Maybe.Nothing.hasInstance(state.txError)
499 : <Warning className={'mt-8'}>
500 <H3 style={{marginTop: 0, paddingTop: 0}}>
502 'There was an error sending your transaction.'
505 { state.txError.value }
515export 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