1import Maybe from 'folktale/maybe'
2import React from 'react'
3import { Row, Col, H1, H3, P, Form, Warning } from '../components/Base'
4import { InnerLabel, AddressInput, ShowBlockie, Anchor } from '../components/Base'
5import * as azimuth from 'azimuth-js'
6import * as ob from 'urbit-ob'
8import StatelessTransaction from '../components/StatelessTransaction'
9import { BRIDGE_ERROR } from '../lib/error'
10import { ROUTE_NAMES } from '../lib/router'
13 sendSignedTransaction,
19 addressFromSecp256k1Public,
23class AcceptTransfer extends React.Component {
27 const receivingAddress = props.wallet.matchWith({
28 Just: (wal) => addressFromSecp256k1Public(wal.value.publicKey),
30 throw BRIDGE_ERROR.MISSING_WALLET
34 const incomingPoint = props.pointCursor.matchWith({
35 Just: (shp) => shp.value,
37 throw BRIDGE_ERROR.MISSING_POINT
42 receivingAddress: receivingAddress,
44 txError: Maybe.Nothing(),
45 incomingPoint: incomingPoint,
53 this.handleAddressInput = this.handleAddressInput.bind(this)
55 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
56 this.handleSubmit = this.handleSubmit.bind(this)
57 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
58 this.handleSetTxn = this.handleSetTxn.bind(this)
59 this.handleSetStx = this.handleSetStx.bind(this)
60 this.handleSetNonce = this.handleSetNonce.bind(this)
61 this.handleSetChainId = this.handleSetChainId.bind(this)
62 this.handleSetGasPrice = this.handleSetGasPrice.bind(this)
63 this.handleSetGasLimit = this.handleSetGasLimit.bind(this)
67 const { props } = this
69 const addr = props.wallet.matchWith({
70 Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
72 throw BRIDGE_ERROR.MISSING_WALLET
76 props.web3.matchWith({
79 const validWeb3 = w3.value
81 const getTxMetadata = [
82 validWeb3.eth.getTransactionCount(addr),
83 validWeb3.eth.net.getId(),
84 validWeb3.eth.getGasPrice()
87 Promise.all(getTxMetadata).then(r => {
91 gasPrice: fromWei(r[2], 'gwei'),
94 this.setState({...txMetadata})
100 // const validPoint = props.pointCursor.matchWith({
101 // Just: (shp) => shp.value,
103 // throw BRIDGE_ERROR.MISSING_POINT
109 // We need to get the point's owner, so it's not possible to perform this
110 // transaction offline.
112 // Perhaps we could add an 'owner' input in the offline case, if necessary.
114 // const owner = props.pointCache[validPoint].owner
116 // const txn = Maybe.Just(this.createUnsignedTxn(
118 // state.receivingAddress))
120 // this.setState({ txn })
125 handleAddressInput(proxyAddress) {
126 this.setState({ proxyAddress })
127 this.handleClearTxn()
131 handleCreateUnsignedTxn() {
132 const txn = this.createUnsignedTxn()
133 this.setState({ txn })
137 handleSetUserApproval(){
139 this.setState({ userApproval: !state.userApproval })
145 this.setState({ txn })
159 handleSetNonce(nonce){
160 this.setState({ nonce })
161 this.handleClearStx()
166 handleSetChainId(chainId){
167 this.setState({ chainId })
168 this.handleClearStx()
173 handleSetGasPrice(gasPrice){
174 this.setState({ gasPrice })
175 this.handleClearStx()
180 handleSetGasLimit(gasLimit){
181 this.setState({ gasLimit })
182 this.handleClearStx()
190 stx: Maybe.Nothing(),
199 txn: Maybe.Nothing(),
200 stx: Maybe.Nothing(),
206 handleClearTransaction() {
209 txn: Maybe.Nothing(),
210 stx: Maybe.Nothing(),
217 const { props, state } = this
218 sendSignedTransaction(props.web3.value, state.stx)
220 props.setTxnCursor(sent)
222 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
225 // Note that value.value is due to wrapped Maybe.Just + Result.Error
226 this.setState({ txError: Maybe.Just(err.value.value) })
230 createUnsignedTxn() {
231 const { state, props } = this
233 const validContracts = props.contracts.matchWith({
234 Just: (cs) => cs.value,
236 throw BRIDGE_ERROR.MISSING_CONTRACTS
240 const validPoint = props.pointCursor.matchWith({
241 Just: (shp) => shp.value,
243 throw BRIDGE_ERROR.MISSING_POINT
247 const owner = props.pointCache[validPoint].owner
249 return Maybe.Just(azimuth.ecliptic.transferFrom(
252 state.receivingAddress,
259 const { state, props } = this
260 const validAddress = isValidAddress(state.receivingAddress)
261 const canGenerate = validAddress === true
262 const canSign = !Maybe.Nothing.hasInstance(state.txn)
263 const canApprove = !Maybe.Nothing.hasInstance(state.stx)
264 const canSend = !Maybe.Nothing.hasInstance(state.stx) && state.userApproval === true
271 { 'Accept Transfer of '} <code>{ ` ${ob.patp(state.incomingPoint)} ` }</code>
276 "By default, the recipient is the address you're logged in " +
277 "as. But you can transfer to any address you like."
282 className='mono mt-8'
284 prop-format='innerLabel'
285 value={ state.receivingAddress }
286 onChange={ v => this.handleAddressInput(v) }>
287 <InnerLabel>{ 'Receiving Address' }</InnerLabel>
288 <ShowBlockie className={'mt-1'} address={state.receivingAddress} />
292 className={'mt-1 sm'}
294 prop-disabled={!isValidAddress(state.receivingAddress)}
296 href={`https://etherscan.io/address/${state.receivingAddress}`}>
297 {'View on Etherscan ↗'}
300 <StatelessTransaction
303 contracts={props.contracts}
304 wallet={props.wallet}
305 walletType={props.walletType}
306 walletHdPath={props.walletHdPath}
312 gasPrice={state.gasPrice}
313 chainId={state.chainId}
314 gasLimit={state.gasLimit}
316 userApproval={state.userApproval}
317 canGenerate={ canGenerate }
319 canApprove={ canApprove }
322 createUnsignedTxn={this.handleCreateUnsignedTxn}
323 setUserApproval={this.handleSetUserApproval}
324 setTxn={this.handleSetTxn}
325 setStx={this.handleSetStx}
326 setNonce={this.handleSetNonce}
327 setChainId={this.handleSetChainId}
328 setGasPrice={this.handleSetGasPrice}
329 setGasLimit={this.handleSetGasLimit}
330 handleSubmit={this.handleSubmit} />
335 Maybe.Nothing.hasInstance(state.txError)
337 : <Warning className={'mt-8'}>
338 <H3 style={{marginTop: 0, paddingTop: 0}}>
340 'There was an error sending your transaction.'
343 { state.txError.value }
352export default AcceptTransfer
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