1import { Just, Nothing } from 'folktale/maybe'
2import React from 'react'
3import { Row, Col, H1, H3, P, 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 { NETWORK_NAMES } from '../lib/network'
11import { ROUTE_NAMES } from '../lib/router'
12import { sendSignedTransaction, fromWei } from '../lib/txn'
13import { isValidAddress, addressFromSecp256k1Public } from '../lib/wallet'
15class AcceptTransfer extends React.Component {
19 const receivingAddress = props.wallet.matchWith({
20 Just: (wal) => addressFromSecp256k1Public(wal.value.publicKey),
22 throw BRIDGE_ERROR.MISSING_WALLET
26 const incomingPoint = props.pointCursor.matchWith({
27 Just: (shp) => shp.value,
29 throw BRIDGE_ERROR.MISSING_POINT
34 receivingAddress: receivingAddress,
37 incomingPoint: incomingPoint,
41 showGasDetails: false,
47 this.handleAddressInput = this.handleAddressInput.bind(this)
48 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
49 this.handleSubmit = this.handleSubmit.bind(this)
50 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
51 this.handleSetTxn = this.handleSetTxn.bind(this)
52 this.handleSetStx = this.handleSetStx.bind(this)
53 this.handleSetNonce = this.handleSetNonce.bind(this)
54 this.handleSetChainId = this.handleSetChainId.bind(this)
55 this.handleSetGasPrice = this.handleSetGasPrice.bind(this)
56 this.handleSetGasLimit = this.handleSetGasLimit.bind(this)
57 this.toggleGasDetails = this.toggleGasDetails.bind(this)
62 showGasDetails: !this.state.showGasDetails
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})
101 handleAddressInput(proxyAddress) {
102 this.setState({ proxyAddress })
103 this.handleClearTxn()
106 handleCreateUnsignedTxn() {
107 const txn = this.createUnsignedTxn()
108 this.setState({ txn })
111 handleSetUserApproval(){
113 this.setState({ userApproval: !state.userApproval })
117 this.setState({ txn })
127 handleSetNonce(nonce){
128 this.setState({ nonce })
129 this.handleClearStx()
132 handleSetChainId(chainId){
133 this.setState({ chainId })
134 this.handleClearStx()
137 handleSetGasPrice(gasPrice){
138 this.setState({ gasPrice })
139 this.handleClearStx()
142 handleSetGasLimit(gasLimit){
143 this.setState({ gasLimit })
144 this.handleClearStx()
163 const { props, state } = this
164 sendSignedTransaction(props.web3.value, state.stx)
166 props.setTxnHashCursor(sent)
168 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
171 this.setState({ txError: err.map(val => val.merge()) })
175 createUnsignedTxn() {
176 const { state, props } = this
178 const validContracts = props.contracts.matchWith({
179 Just: (cs) => cs.value,
181 throw BRIDGE_ERROR.MISSING_CONTRACTS
185 const validPoint = props.pointCursor.matchWith({
186 Just: (shp) => shp.value,
188 throw BRIDGE_ERROR.MISSING_POINT
192 const owner = props.pointCache[validPoint].owner
194 return Just(azimuth.ecliptic.transferFrom(
197 state.receivingAddress,
204 const { state, props } = this
205 const validAddress = isValidAddress(state.receivingAddress)
206 const canGenerate = validAddress === true
207 const canSign = Just.hasInstance(state.txn)
208 const canApprove = Just.hasInstance(state.stx)
210 Just.hasInstance(state.stx)
211 && state.userApproval === true
214 props.networkType === NETWORK_NAMES.ROPSTEN ||
215 props.networkType === NETWORK_NAMES.MAINNET
218 props.networkType === NETWORK_NAMES.ROPSTEN
219 ? "ropsten.etherscan.io"
226 { 'Accept Transfer of '} <code>{ ` ${ob.patp(state.incomingPoint)} ` }</code>
231 "By default, the recipient is the address you're logged in " +
232 "as. But you can transfer to any address you like."
237 className='mono mt-8'
239 prop-format='innerLabel'
240 value={ state.receivingAddress }
241 onChange={ v => this.handleAddressInput(v) }>
242 <InnerLabel>{ 'Receiving Address' }</InnerLabel>
243 <ShowBlockie className={'mt-1'} address={state.receivingAddress} />
247 className={'mt-1 sm'}
249 prop-disabled={!isValidAddress(state.receivingAddress) || !esvisible}
251 href={`https://${esdomain}/address/${state.receivingAddress}`}>
252 {'View on Etherscan ↗'}
255 <StatelessTransaction
258 contracts={props.contracts}
259 wallet={props.wallet}
260 walletType={props.walletType}
261 walletHdPath={props.walletHdPath}
262 networkType={props.networkType}
268 gasPrice={state.gasPrice}
269 chainId={state.chainId}
270 gasLimit={state.gasLimit}
271 showGasDetails={state.showGasDetails}
272 toggleGasDetails={this.toggleGasDetails}
274 userApproval={state.userApproval}
275 canGenerate={ canGenerate }
277 canApprove={ canApprove }
280 createUnsignedTxn={this.handleCreateUnsignedTxn}
281 setUserApproval={this.handleSetUserApproval}
282 setTxn={this.handleSetTxn}
283 setStx={this.handleSetStx}
284 setNonce={this.handleSetNonce}
285 setChainId={this.handleSetChainId}
286 setGasPrice={this.handleSetGasPrice}
287 setGasLimit={this.handleSetGasLimit}
288 handleSubmit={this.handleSubmit} />
291 Nothing.hasInstance(state.txError)
293 : <Warning className={'mt-8'}>
294 <H3 style={{marginTop: 0, paddingTop: 0}}>
296 'There was an error sending your transaction.'
299 { state.txError.value }
309export 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