1import Maybe from 'folktale/maybe'
2import React from 'react'
3import { Row, Col, H1, P, Form, 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,
46 this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
47 this.handleSubmit = this.handleSubmit.bind(this)
48 this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
49 this.handleSetTxn = this.handleSetTxn.bind(this)
50 this.handleSetStx = this.handleSetStx.bind(this)
51 this.handleSetNonce = this.handleSetNonce.bind(this)
52 this.handleSetChainId = this.handleSetChainId.bind(this)
53 this.handleSetGasPrice = this.handleSetGasPrice.bind(this)
54 this.handleSetGasLimit = this.handleSetGasLimit.bind(this)
58 const { props } = this
60 const addr = props.wallet.matchWith({
61 Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
63 throw BRIDGE_ERROR.MISSING_WALLET
67 props.web3.matchWith({
70 const validWeb3 = w3.value
72 const getTxMetadata = [
73 validWeb3.eth.getTransactionCount(addr),
74 validWeb3.eth.net.getId(),
75 validWeb3.eth.getGasPrice()
78 Promise.all(getTxMetadata).then(r => {
82 gasPrice: fromWei(r[2], 'gwei'),
85 this.setState({...txMetadata})
95 handleCreateUnsignedTxn() {
96 const txn = this.createUnsignedTxn()
97 this.setState({ txn })
102 handleSetUserApproval(){
104 this.setState({ userApproval: !state.userApproval })
110 this.setState({ txn })
124 handleSetNonce(nonce){
125 this.setState({ nonce })
126 this.handleClearStx()
131 handleSetChainId(chainId){
132 this.setState({ chainId })
133 this.handleClearStx()
138 handleSetGasPrice(gasPrice){
139 this.setState({ gasPrice })
140 this.handleClearStx()
145 handleSetGasLimit(gasLimit){
146 this.setState({ gasLimit })
147 this.handleClearStx()
155 stx: Maybe.Nothing(),
161 const { props, state } = this
162 sendSignedTransaction(props.web3.value, state.stx)
164 props.setTxnCursor(sent)
166 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
169 // Note that value.value is due to wrapped Maybe.Just + Result.Error
170 this.setState({ txError: Maybe.Just(err.value.value) })
174 createUnsignedTxn() {
175 const { props } = this
177 const validContracts = props.contracts.matchWith({
178 Just: (cs) => cs.value,
180 throw BRIDGE_ERROR.MISSING_CONTRACTS
184 const validPoint = props.pointCursor.matchWith({
185 Just: (pt) => pt.value,
187 throw BRIDGE_ERROR.MISSING_POINT
191 const txn = azimuth.ecliptic.setTransferProxy(
197 return Maybe.Just(txn)
202 const { props, state } = this
204 const online = Maybe.Just.hasInstance(props.web3)
207 ? props.pointCache[state.pointInTransfer].transferProxy
208 : 'any outgoing addresses'
210 // const canGenerate = validAddress === true
212 const canGenerate = true
213 const canSign = !Maybe.Nothing.hasInstance(state.txn)
214 const canApprove = !Maybe.Nothing.hasInstance(state.stx)
215 const canSend = !Maybe.Nothing.hasInstance(state.stx) && state.userApproval === true
222 { 'Cancel Transfer of '} <code>{ ` ${ob.patp(state.pointInTransfer)} ` }</code>
227 `This action will cancel the transfer to ${proxy}.`
231 <StatelessTransaction
234 contracts={props.contracts}
235 wallet={props.wallet}
236 walletType={props.walletType}
237 walletHdPath={props.walletHdPath}
243 gasPrice={state.gasPrice}
244 chainId={state.chainId}
245 gasLimit={state.gasLimit}
247 userApproval={state.userApproval}
248 canGenerate={ canGenerate }
250 canApprove={ canApprove }
253 createUnsignedTxn={this.handleCreateUnsignedTxn}
254 setUserApproval={this.handleSetUserApproval}
255 setTxn={this.handleSetTxn}
256 setStx={this.handleSetStx}
257 setNonce={this.handleSetNonce}
258 setChainId={this.handleSetChainId}
259 setGasPrice={this.handleSetGasPrice}
260 setGasLimit={this.handleSetGasLimit}
261 handleSubmit={this.handleSubmit} />
264 Maybe.Nothing.hasInstance(state.txError)
266 : <Warning className={'mt-8'}>
267 <H3 style={{marginTop: 0, paddingTop: 0}}>
269 'There was an error sending your transaction.'
272 { state.txError.value }
283export 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