@@ -33,191 +33,26 @@ class Transfer extends React.Component {
35 this.state = {
35 this.state = {
36− txError: Maybe.Nothing(),
37 receivingAddress: '',
36 receivingAddress: '',
38 issuingPoint: issuingPoint,
37 issuingPoint: issuingPoint,
42− showGasDetails: false,
45− txn: Maybe.Nothing(),
46− stx: Maybe.Nothing(),
48− this.handleAddressInput = this.handleAddressInput.bind(this)
50− this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
51− this.handleSubmit = this.handleSubmit.bind(this)
52− this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
53− this.handleSetTxn = this.handleSetTxn.bind(this)
54− this.handleSetStx = this.handleSetStx.bind(this)
55− this.handleSetNonce = this.handleSetNonce.bind(this)
56− this.handleSetChainId = this.handleSetChainId.bind(this)
57− this.handleSetGasPrice = this.handleSetGasPrice.bind(this)
58− this.handleSetGasLimit = this.handleSetGasLimit.bind(this)
59− this.toggleGasDetails = this.toggleGasDetails.bind(this)
64− showGasDetails: !this.state.showGasDetails
68− componentDidMount() {
69− const { props } = this
71− const addr = props.wallet.matchWith({
72− Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
74− throw BRIDGE_ERROR.MISSING_WALLET
78− props.web3.matchWith({
81− const validWeb3 = w3.value
83− const getTxMetadata = [
84− validWeb3.eth.getTransactionCount(addr),
85− validWeb3.eth.net.getId(),
86− validWeb3.eth.getGasPrice()
89− Promise.all(getTxMetadata).then(r => {
93− gasPrice: fromWei(r[2], 'gwei'),
96− this.setState({...txMetadata})
40+ this.handleAddressInput = this.handleAddressInput.bind(this)
41+ this.createUnsignedTxn = this.createUnsignedTxn.bind(this)
42+ this.statelessRef = React.createRef();
106 handleAddressInput(receivingAddress) {
45 handleAddressInput(receivingAddress) {
107 this.setState({ receivingAddress })
46 this.setState({ receivingAddress })
108− this.handleClearTxn()
47+ this.statelessRef.current.clearTxn()
113 handleConfirmAvailability() {
50 handleConfirmAvailability() {
114 this.confirmPointAvailability().then(r => {
51 this.confirmPointAvailability().then(r => {
115 this.setState({ isAvailable: r })
52 this.setState({ isAvailable: r })
121− handleCreateUnsignedTxn() {
122− const txn = this.createUnsignedTxn()
123− this.setState({ txn })
127− handleSetUserApproval(){
128− const {state} = this
129− this.setState({ userApproval: !state.userApproval })
135− this.setState({ txn })
143− userApproval: false,
149− handleSetNonce(nonce){
150− this.setState({ nonce })
151− this.handleClearStx()
156− handleSetChainId(chainId){
157− this.setState({ chainId })
158− this.handleClearStx()
163− handleSetGasPrice(gasPrice){
164− this.setState({ gasPrice })
165− this.handleClearStx()
170− handleSetGasLimit(gasLimit){
171− this.setState({ gasLimit })
172− this.handleClearStx()
179− userApproval: false,
180− stx: Maybe.Nothing(),
188− userApproval: false,
189− txn: Maybe.Nothing(),
190− stx: Maybe.Nothing(),
196− handleClearTransaction() {
198− userApproval: false,
199− txn: Maybe.Nothing(),
200− stx: Maybe.Nothing(),
207− const { props, state } = this
208− sendSignedTransaction(props.web3.value, state.stx)
210− props.setTxnHashCursor(sent)
212− props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
215− this.setState({ txError: err.map(val => val.merge()) })
221 createUnsignedTxn() {
56 createUnsignedTxn() {
222 const { state, props } = this
57 const { state, props } = this
@@ -244,19 +79,12 @@ class Transfer extends React.Component {
244 return Maybe.Just(txn)
79 return Maybe.Just(txn)
249 render() {
82 render() {
250 const { props, state } = this
83 const { props, state } = this
252 const validAddress = isValidAddress(state.receivingAddress)
85 const validAddress = isValidAddress(state.receivingAddress)
254 const canGenerate = validAddress === true
86 const canGenerate = validAddress === true
256− const canSign = Maybe.Just.hasInstance(state.txn)
257− const canApprove = Maybe.Just.hasInstance(state.stx)
258− const canSend = Maybe.Just.hasInstance(state.stx) && state.userApproval === true
260 const esvisible =
88 const esvisible =
261 props.networkType === NETWORK_NAMES.ROPSTEN ||
89 props.networkType === NETWORK_NAMES.ROPSTEN ||
262 props.networkType === NETWORK_NAMES.MAINNET
90 props.networkType === NETWORK_NAMES.MAINNET
@@ -310,46 +138,15 @@ class Transfer extends React.Component {
310 walletType={props.walletType}
138 walletType={props.walletType}
311 walletHdPath={props.walletHdPath}
139 walletHdPath={props.walletHdPath}
312 networkType={props.networkType}
140 networkType={props.networkType}
313− // Tx
141+ setTxnHashCursor={props.setTxnHashCursor}
314− txn={state.txn}
142+ popRoute={props.popRoute}
315− stx={state.stx}
143+ pushRoute={props.pushRoute}
318− gasPrice={state.gasPrice}
319− chainId={state.chainId}
320− gasLimit={state.gasLimit}
321− showGasDetails={state.showGasDetails}
322− toggleGasDetails={this.toggleGasDetails}
323 // Checks
144 // Checks
324 userApproval={state.userApproval}
145 userApproval={state.userApproval}
325 canGenerate={ canGenerate }
146 canGenerate={ canGenerate }
327− canApprove={ canApprove }
329 // Methods
147 // Methods
330− createUnsignedTxn={this.handleCreateUnsignedTxn}
148+ createUnsignedTxn={this.createUnsignedTxn}
331− setUserApproval={this.handleSetUserApproval}
149+ ref={this.statelessRef} />
332− setTxn={this.handleSetTxn}
333− setStx={this.handleSetStx}
334− setNonce={this.handleSetNonce}
335− setChainId={this.handleSetChainId}
336− setGasPrice={this.handleSetGasPrice}
337− setGasLimit={this.handleSetGasLimit}
338− handleSubmit={this.handleSubmit} />
341− Maybe.Nothing.hasInstance(state.txError)
343− : <Warning className={'mt-8'}>
344− <H3 style={{marginTop: 0, paddingTop: 0}}>
346− 'There was an error sending your transaction.'
349− { state.txError.value }