on master help sign in
- More WIP on statelessTransaction refactor
commitd3c70b7194a508e57cfcdf155a96e252d05722d3 authorChris Johnson <chris@cjohnson.io> dateWed 3 Apr 2019, 12:46 (8 years ago) parent4f34a5f
2 files changed+34−64
src/bridge/components/StatelessTransaction.js+31−6 src/bridge/views/SetProxy.js+3−58
src/bridge/components/StatelessTransaction.js+31−6
@@ -1,11 +1,21 @@
1−import { Nothing } from 'folktale/maybe'
1+import { Maybe, Nothing } from 'folktale/maybe'
22import React from 'react'
33
44import { Code, H3 } from './Base'
55import { Button } from './Base'
66import { CheckboxButton, Input, InnerLabel } from './Base'
7+import { Warning } from '../components/Base'
78
8−import { renderSignedTx, signTransaction } from '../lib/txn'
9+import { addressFromSecp256k1Public } from '../lib/wallet'
10+import { BRIDGE_ERROR } from '../lib/error'
11+import { ROUTE_NAMES } from '../lib/router'
12+
13+import {
14+ sendSignedTransaction,
15+ fromWei,
16+ renderSignedTx,
17+ signTransaction
18+ } from '../lib/txn'
919
1020class StatelessTransaction extends React.Component {
1121
@@ -129,12 +139,12 @@ class StatelessTransaction extends React.Component {
129139 this.handleClearStx()
130140 }
131141
132− handleSetGasPrice(gasPrice){
142+ handleSetGasPrice(gasPrice) {
133143 this.setState({ gasPrice })
134144 this.handleClearStx()
135145 }
136146
137− handleRangeChange(e) => {
147+ handleRangeChange(e) {
138148 this.handleSetGasPrice(e.target.value);
139149 }
140150
@@ -167,7 +177,9 @@ class StatelessTransaction extends React.Component {
167177 const { gasPrice, gasLimit, nonce, chainId, txn, stx, userApproval } = this.state
168178
169179 const { setNonce, setChainId, setGasLimit, setGasPrice, handleSubmit } = this
170− const { showGasDetails, toggleGasDetails, setUserApproval } = this
180+ const { showGasDetails, toggleGasDetails, setUserApproval, sendTxn } = this
181+
182+ const { state } = this
171183
172184 const canSign = Maybe.Just.hasInstance(state.txn)
173185 const canApprove = Maybe.Just.hasInstance(state.stx)
@@ -227,7 +239,7 @@ class StatelessTransaction extends React.Component {
227239 max="20"
228240 list="gweiVals"
229241 value={gasPrice}
230− onChange={handleRangeChange}
242+ onChange={this.handleRangeChange}
231243 />
232244
233245 <div className="flex space-between text-sm mb-8">
@@ -359,6 +371,17 @@ class StatelessTransaction extends React.Component {
359371 </React.Fragment>
360372 })
361373
374+ const txnErrorDialogue = Maybe.Nothing.hasInstance(state.txError)
375+ ? ''
376+ : <Warning className={'mt-8'}>
377+ <H3 style={{marginTop: 0, paddingTop: 0}}>
378+ {
379+ 'There was an error sending your transaction.'
380+ }
381+ </H3>
382+ { state.txError.value }
383+ </Warning>
384+
362385 return (
363386 <React.Fragment>
364387 { generateTxnButton }
@@ -379,6 +402,8 @@ class StatelessTransaction extends React.Component {
379402
380403 { signedTxnDisplay }
381404 { sendDialogue }
405+
406+ { txnErrorDialogue }
382407 </React.Fragment>
383408 )
384409 }
src/bridge/views/SetProxy.js+3−58
@@ -2,7 +2,7 @@ import Maybe from 'folktale/maybe'
22import React from 'react'
33import * as azimuth from 'azimuth-js'
44import { Row, Col, H1, H3, P, InnerLabel, ShowBlockie, Anchor } from '../components/Base'
5−import { AddressInput, Warning } from '../components/Base'
5+import { AddressInput } from '../components/Base'
66import * as ob from 'urbit-ob'
77
88import { PROXY_TYPE, renderProxyType } from '../lib/proxy'
@@ -12,17 +12,7 @@ import { NETWORK_NAMES } from '../lib/network'
1212
1313import StatelessTransaction from '../components/StatelessTransaction'
1414
15−import { ROUTE_NAMES } from '../lib/router'
16−
17−import {
18− sendSignedTransaction,
19− fromWei,
20− } from '../lib/txn'
21−
22−import {
23− isValidAddress,
24− addressFromSecp256k1Public,
25−} from '../lib/wallet'
15+import { isValidAddress } from '../lib/wallet'
2616
2717const SetManagementProxy = (props) =>
2818 <SetProxy
@@ -101,19 +91,12 @@ class SetProxy extends React.Component {
10191 }
10292
10393 render() {
104−
10594 const { props, state } = this
10695
10796 const renderedProxyType = renderProxyType(props.proxyType)
108−
10997 const validAddress = isValidAddress(state.proxyAddress)
110−
11198 const canGenerate = validAddress === true
11299
113− const canSign = Maybe.Just.hasInstance(state.txn)
114− const canApprove = Maybe.Just.hasInstance(state.stx)
115− const canSend = Maybe.Just.hasInstance(state.stx) && state.userApproval === true
116−
117100 const esvisible =
118101 props.networkType === NETWORK_NAMES.ROPSTEN ||
119102 props.networkType === NETWORK_NAMES.MAINNET
@@ -170,46 +153,8 @@ class SetProxy extends React.Component {
170153 walletType={props.walletType}
171154 walletHdPath={props.walletHdPath}
172155 networkType={props.networkType}
173− // Tx
174− txn={state.txn}
175− stx={state.stx}
176− // Tx details
177− nonce={state.nonce}
178− gasPrice={state.gasPrice}
179− chainId={state.chainId}
180− gasLimit={state.gasLimit}
181− showGasDetails={state.showGasDetails}
182− toggleGasDetails={this.toggleGasDetails}
183156 // Checks
184− userApproval={state.userApproval}
185− canGenerate={ canGenerate }
186− canSign={ canSign }
187− canApprove={ canApprove }
188− canSend={ canSend }
189− // Methods
190− createUnsignedTxn={this.handleCreateUnsignedTxn}
191− setUserApproval={this.handleSetUserApproval}
192− setTxn={this.handleSetTxn}
193− setStx={this.handleSetStx}
194− setNonce={this.handleSetNonce}
195− setChainId={this.handleSetChainId}
196− setGasPrice={this.handleSetGasPrice}
197− setGasLimit={this.handleSetGasLimit}
198− handleSubmit={this.handleSubmit} />
199−
200− {
201− Maybe.Nothing.hasInstance(state.txError)
202− ? ''
203− : <Warning className={'mt-8'}>
204− <H3 style={{marginTop: 0, paddingTop: 0}}>
205− {
206− 'There was an error sending your transaction.'
207− }
208− </H3>
209− { state.txError.value }
210− </Warning>
211− }
212−
157+ canGenerate={ canGenerate } />
213158 </Col>
214159 </Row>
215160 )