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,
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.setTxnHashCursor(sent)
166 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
169 this.setState({ txError: err.map(val => val.merge()) })
173 createUnsignedTxn() {
174 const { props } = this
176 const validContracts = props.contracts.matchWith({
177 Just: (cs) => cs.value,
179 throw BRIDGE_ERROR.MISSING_CONTRACTS
183 const validPoint = props.pointCursor.matchWith({
184 Just: (pt) => pt.value,
186 throw BRIDGE_ERROR.MISSING_POINT
190 const txn = azimuth.ecliptic.setTransferProxy(
196 return Maybe.Just(txn)
201 const { props, state } = this
203 const online = Maybe.Just.hasInstance(props.web3)
206 ? props.pointCache[state.pointInTransfer].transferProxy
207 : 'any outgoing addresses'
209 // const canGenerate = validAddress === true
211 const canGenerate = true
212 const canSign = !Maybe.Nothing.hasInstance(state.txn)
213 const canApprove = !Maybe.Nothing.hasInstance(state.stx)
214 const canSend = !Maybe.Nothing.hasInstance(state.stx) && state.userApproval === true
221 { 'Cancel Transfer of '} <code>{ ` ${ob.patp(state.pointInTransfer)} ` }</code>
226 `This action will cancel the transfer to ${proxy}.`
229 <StatelessTransaction
232 contracts={props.contracts}
233 wallet={props.wallet}
234 walletType={props.walletType}
235 walletHdPath={props.walletHdPath}
236 networkType={props.networkType}
242 gasPrice={state.gasPrice}
243 chainId={state.chainId}
244 gasLimit={state.gasLimit}
246 userApproval={state.userApproval}
247 canGenerate={ canGenerate }
249 canApprove={ canApprove }
252 createUnsignedTxn={this.handleCreateUnsignedTxn}
253 setUserApproval={this.handleSetUserApproval}
254 setTxn={this.handleSetTxn}
255 setStx={this.handleSetStx}
256 setNonce={this.handleSetNonce}
257 setChainId={this.handleSetChainId}
258 setGasPrice={this.handleSetGasPrice}
259 setGasLimit={this.handleSetGasLimit}
260 handleSubmit={this.handleSubmit} />
263 Maybe.Nothing.hasInstance(state.txError)
265 : <Warning className={'mt-8'}>
266 <H3 style={{marginTop: 0, paddingTop: 0}}>
268 'There was an error sending your transaction.'
271 { state.txError.value }
281export 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