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,
46 this.handleAddressInput = this.handleAddressInput.bind(this)
47 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
48 this.handleSubmit = this.handleSubmit.bind(this)
49 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
50 this.handleSetTxn = this.handleSetTxn.bind(this)
51 this.handleSetStx = this.handleSetStx.bind(this)
52 this.handleSetNonce = this.handleSetNonce.bind(this)
53 this.handleSetChainId = this.handleSetChainId.bind(this)
54 this.handleSetGasPrice = this.handleSetGasPrice.bind(this)
55 this.handleSetGasLimit = this.handleSetGasLimit.bind(this)
59 const { props } = this
61 const addr = props.wallet.matchWith({
62 Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
64 throw BRIDGE_ERROR.MISSING_WALLET
68 props.web3.matchWith({
71 const validWeb3 = w3.value
73 const getTxMetadata = [
74 validWeb3.eth.getTransactionCount(addr),
75 validWeb3.eth.net.getId(),
76 validWeb3.eth.getGasPrice()
79 Promise.all(getTxMetadata).then(r => {
83 gasPrice: fromWei(r[2], 'gwei'),
86 this.setState({...txMetadata})
93 handleAddressInput(proxyAddress) {
94 this.setState({ proxyAddress })
98 handleCreateUnsignedTxn() {
99 const txn = this.createUnsignedTxn()
100 this.setState({ txn })
103 handleSetUserApproval(){
105 this.setState({ userApproval: !state.userApproval })
109 this.setState({ txn })
119 handleSetNonce(nonce){
120 this.setState({ nonce })
121 this.handleClearStx()
124 handleSetChainId(chainId){
125 this.setState({ chainId })
126 this.handleClearStx()
129 handleSetGasPrice(gasPrice){
130 this.setState({ gasPrice })
131 this.handleClearStx()
134 handleSetGasLimit(gasLimit){
135 this.setState({ gasLimit })
136 this.handleClearStx()
155 const { props, state } = this
156 sendSignedTransaction(props.web3.value, state.stx)
158 props.setTxnHashCursor(sent)
160 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
163 this.setState({ txError: err.map(val => val.merge()) })
167 createUnsignedTxn() {
168 const { state, props } = this
170 const validContracts = props.contracts.matchWith({
171 Just: (cs) => cs.value,
173 throw BRIDGE_ERROR.MISSING_CONTRACTS
177 const validPoint = props.pointCursor.matchWith({
178 Just: (shp) => shp.value,
180 throw BRIDGE_ERROR.MISSING_POINT
184 const owner = props.pointCache[validPoint].owner
186 return Just(azimuth.ecliptic.transferFrom(
189 state.receivingAddress,
196 const { state, props } = this
197 const validAddress = isValidAddress(state.receivingAddress)
198 const canGenerate = validAddress === true
199 const canSign = Just.hasInstance(state.txn)
200 const canApprove = Just.hasInstance(state.stx)
202 Just.hasInstance(state.stx)
203 && state.userApproval === true
206 props.networkType === NETWORK_NAMES.ROPSTEN ||
207 props.networkType === NETWORK_NAMES.MAINNET
210 props.networkType === NETWORK_NAMES.ROPSTEN
211 ? "ropsten.etherscan.io"
218 { 'Accept Transfer of '} <code>{ ` ${ob.patp(state.incomingPoint)} ` }</code>
223 "By default, the recipient is the address you're logged in " +
224 "as. But you can transfer to any address you like."
229 className='mono mt-8'
231 prop-format='innerLabel'
232 value={ state.receivingAddress }
233 onChange={ v => this.handleAddressInput(v) }>
234 <InnerLabel>{ 'Receiving Address' }</InnerLabel>
235 <ShowBlockie className={'mt-1'} address={state.receivingAddress} />
239 className={'mt-1 sm'}
241 prop-disabled={!isValidAddress(state.receivingAddress) || !esvisible}
243 href={`https://${esdomain}/address/${state.receivingAddress}`}>
244 {'View on Etherscan ↗'}
247 <StatelessTransaction
250 contracts={props.contracts}
251 wallet={props.wallet}
252 walletType={props.walletType}
253 walletHdPath={props.walletHdPath}
254 networkType={props.networkType}
260 gasPrice={state.gasPrice}
261 chainId={state.chainId}
262 gasLimit={state.gasLimit}
264 userApproval={state.userApproval}
265 canGenerate={ canGenerate }
267 canApprove={ canApprove }
270 createUnsignedTxn={this.handleCreateUnsignedTxn}
271 setUserApproval={this.handleSetUserApproval}
272 setTxn={this.handleSetTxn}
273 setStx={this.handleSetStx}
274 setNonce={this.handleSetNonce}
275 setChainId={this.handleSetChainId}
276 setGasPrice={this.handleSetGasPrice}
277 setGasLimit={this.handleSetGasLimit}
278 handleSubmit={this.handleSubmit} />
281 Nothing.hasInstance(state.txError)
283 : <Warning className={'mt-8'}>
284 <H3 style={{marginTop: 0, paddingTop: 0}}>
286 'There was an error sending your transaction.'
289 { state.txError.value }
299export 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