1import Maybe from 'folktale/maybe'
2import React from 'react'
3import { Row, Col, H1, P, Warning, H3 } from '../components/Base'
4import * as azimuth from 'azimuth-js'
5import * as ob from 'urbit-ob'
7import StatelessTransaction from '../components/StatelessTransaction'
8import { BRIDGE_ERROR } from '../lib/error'
9import { ETH_ZERO_ADDR } from '../lib/wallet'
10import { ROUTE_NAMES } from '../lib/router'
13 sendSignedTransaction,
18 addressFromSecp256k1Public,
22class CancelTransfer extends React.Component {
26 const pointInTransfer = props.pointCursor.matchWith({
27 Just: (pt) => pt.value,
29 throw BRIDGE_ERROR.MISSING_POINT
36 txError: Maybe.Nothing(),
37 pointInTransfer: pointInTransfer,
41 showGasDetails: false,
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)
56 this.toggleGasDetails = this.toggleGasDetails.bind(this)
61 showGasDetails: !this.state.showGasDetails
66 const { props } = this
68 const addr = props.wallet.matchWith({
69 Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
71 throw BRIDGE_ERROR.MISSING_WALLET
75 props.web3.matchWith({
78 const validWeb3 = w3.value
80 const getTxMetadata = [
81 validWeb3.eth.getTransactionCount(addr),
82 validWeb3.eth.net.getId(),
83 validWeb3.eth.getGasPrice()
86 Promise.all(getTxMetadata).then(r => {
90 gasPrice: fromWei(r[2], 'gwei'),
93 this.setState({...txMetadata})
103 handleCreateUnsignedTxn() {
104 const txn = this.createUnsignedTxn()
105 this.setState({ txn })
110 handleSetUserApproval(){
112 this.setState({ userApproval: !state.userApproval })
118 this.setState({ txn })
132 handleSetNonce(nonce){
133 this.setState({ nonce })
134 this.handleClearStx()
139 handleSetChainId(chainId){
140 this.setState({ chainId })
141 this.handleClearStx()
146 handleSetGasPrice(gasPrice){
147 this.setState({ gasPrice })
148 this.handleClearStx()
153 handleSetGasLimit(gasLimit){
154 this.setState({ gasLimit })
155 this.handleClearStx()
163 stx: Maybe.Nothing(),
169 const { props, state } = this
170 sendSignedTransaction(props.web3.value, state.stx)
172 props.setTxnHashCursor(sent)
174 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
177 this.setState({ txError: err.map(val => val.merge()) })
181 createUnsignedTxn() {
182 const { props } = this
184 const validContracts = props.contracts.matchWith({
185 Just: (cs) => cs.value,
187 throw BRIDGE_ERROR.MISSING_CONTRACTS
191 const validPoint = props.pointCursor.matchWith({
192 Just: (pt) => pt.value,
194 throw BRIDGE_ERROR.MISSING_POINT
198 const txn = azimuth.ecliptic.setTransferProxy(
204 return Maybe.Just(txn)
209 const { props, state } = this
211 const online = Maybe.Just.hasInstance(props.web3)
214 ? props.pointCache[state.pointInTransfer].transferProxy
215 : 'any outgoing addresses'
217 // const canGenerate = validAddress === true
219 const canGenerate = true
220 const canSign = Maybe.Just.hasInstance(state.txn)
221 const canApprove = Maybe.Just.hasInstance(state.stx)
222 const canSend = Maybe.Just.hasInstance(state.stx) && state.userApproval === true
229 { 'Cancel Transfer of '} <code>{ ` ${ob.patp(state.pointInTransfer)} ` }</code>
234 `This action will cancel the transfer to ${proxy}.`
237 <StatelessTransaction
240 contracts={props.contracts}
241 wallet={props.wallet}
242 walletType={props.walletType}
243 walletHdPath={props.walletHdPath}
244 networkType={props.networkType}
250 gasPrice={state.gasPrice}
251 chainId={state.chainId}
252 gasLimit={state.gasLimit}
253 showGasDetails={state.showGasDetails}
254 toggleGasDetails={this.toggleGasDetails}
256 userApproval={state.userApproval}
257 canGenerate={ canGenerate }
259 canApprove={ canApprove }
262 createUnsignedTxn={this.handleCreateUnsignedTxn}
263 setUserApproval={this.handleSetUserApproval}
264 setTxn={this.handleSetTxn}
265 setStx={this.handleSetStx}
266 setNonce={this.handleSetNonce}
267 setChainId={this.handleSetChainId}
268 setGasPrice={this.handleSetGasPrice}
269 setGasLimit={this.handleSetGasLimit}
270 handleSubmit={this.handleSubmit} />
273 Maybe.Nothing.hasInstance(state.txError)
275 : <Warning className={'mt-8'}>
276 <H3 style={{marginTop: 0, paddingTop: 0}}>
278 'There was an error sending your transaction.'
281 { state.txError.value }
291export default CancelTransfer
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