on master help sign in
- More WIP on statelessTransaction refactor
d3c70b7Chris Johnson
src/bridge/components/StatelessTransaction.js+31−6
@@ -1,11 +1,21 @@
1−import { Nothing } from 'folktale/maybe'
1+import { Maybe, Nothing } from 'folktale/maybe'
2import React from 'react'
2import React from 'react'
3
3
4import { Code, H3 } from './Base'
4import { Code, H3 } from './Base'
5import { Button } from './Base'
5import { Button } from './Base'
6import { CheckboxButton, Input, InnerLabel } from './Base'
6import { CheckboxButton, Input, InnerLabel } from './Base'
7+import { Warning } from '../components/Base'
7
8
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,
8−import { renderSignedTx, signTransaction } from '../lib/txn'
17+ signTransaction
18+ } from '../lib/txn'
9
19
10class StatelessTransaction extends React.Component {
20class StatelessTransaction extends React.Component {
11
21
@@ -129,12 +139,12 @@ class StatelessTransaction extends React.Component {
129 this.handleClearStx()
139 this.handleClearStx()
130 }
140 }
131
141
132− handleSetGasPrice(gasPrice){
142+ handleSetGasPrice(gasPrice) {
133 this.setState({ gasPrice })
143 this.setState({ gasPrice })
134 this.handleClearStx()
144 this.handleClearStx()
135 }
145 }
136
146
137− handleRangeChange(e) => {
147+ handleRangeChange(e) {
138 this.handleSetGasPrice(e.target.value);
148 this.handleSetGasPrice(e.target.value);
139 }
149 }
140
150
@@ -167,7 +177,9 @@ class StatelessTransaction extends React.Component {
167 const { gasPrice, gasLimit, nonce, chainId, txn, stx, userApproval } = this.state
177 const { gasPrice, gasLimit, nonce, chainId, txn, stx, userApproval } = this.state
168
178
169 const { setNonce, setChainId, setGasLimit, setGasPrice, handleSubmit } = this
179 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
171
183
172 const canSign = Maybe.Just.hasInstance(state.txn)
184 const canSign = Maybe.Just.hasInstance(state.txn)
173 const canApprove = Maybe.Just.hasInstance(state.stx)
185 const canApprove = Maybe.Just.hasInstance(state.stx)
@@ -227,7 +239,7 @@ class StatelessTransaction extends React.Component {
227 max="20"
239 max="20"
228 list="gweiVals"
240 list="gweiVals"
229 value={gasPrice}
241 value={gasPrice}
230− onChange={handleRangeChange}
242+ onChange={this.handleRangeChange}
231 />
243 />
232
244
233 <div className="flex space-between text-sm mb-8">
245 <div className="flex space-between text-sm mb-8">
@@ -359,6 +371,17 @@ class StatelessTransaction extends React.Component {
359 </React.Fragment>
371 </React.Fragment>
360 })
372 })
361
373
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+
362 return (
385 return (
363 <React.Fragment>
386 <React.Fragment>
364 { generateTxnButton }
387 { generateTxnButton }
@@ -379,6 +402,8 @@ class StatelessTransaction extends React.Component {
379
402
380 { signedTxnDisplay }
403 { signedTxnDisplay }
381 { sendDialogue }
404 { sendDialogue }
405+
406+ { txnErrorDialogue }
382 </React.Fragment>
407 </React.Fragment>
383 )
408 )
384 }
409 }
src/bridge/views/SetProxy.js+3−58
@@ -2,7 +2,7 @@ import Maybe from 'folktale/maybe'
2import React from 'react'
2import React from 'react'
3import * as azimuth from 'azimuth-js'
3import * as azimuth from 'azimuth-js'
4import { Row, Col, H1, H3, P, InnerLabel, ShowBlockie, Anchor } from '../components/Base'
4import { Row, Col, H1, H3, P, InnerLabel, ShowBlockie, Anchor } from '../components/Base'
5−import { AddressInput, Warning } from '../components/Base'
5+import { AddressInput } from '../components/Base'
6import * as ob from 'urbit-ob'
6import * as ob from 'urbit-ob'
7
7
8import { PROXY_TYPE, renderProxyType } from '../lib/proxy'
8import { PROXY_TYPE, renderProxyType } from '../lib/proxy'
@@ -12,17 +12,7 @@ import { NETWORK_NAMES } from '../lib/network'
12
12
13import StatelessTransaction from '../components/StatelessTransaction'
13import StatelessTransaction from '../components/StatelessTransaction'
14
14
15−import { ROUTE_NAMES } from '../lib/router'
16−
17−import {
18− sendSignedTransaction,
19− fromWei,
20− } from '../lib/txn'
21−
22−import {
23− isValidAddress,
15+import { isValidAddress } from '../lib/wallet'
24− addressFromSecp256k1Public,
25−} from '../lib/wallet'
26
16
27const SetManagementProxy = (props) =>
17const SetManagementProxy = (props) =>
28 <SetProxy
18 <SetProxy
@@ -101,19 +91,12 @@ class SetProxy extends React.Component {
101 }
91 }
102
92
103 render() {
93 render() {
104−
105 const { props, state } = this
94 const { props, state } = this
106
95
107 const renderedProxyType = renderProxyType(props.proxyType)
96 const renderedProxyType = renderProxyType(props.proxyType)
108−
109 const validAddress = isValidAddress(state.proxyAddress)
97 const validAddress = isValidAddress(state.proxyAddress)
110−
111 const canGenerate = validAddress === true
98 const canGenerate = validAddress === true
112
99
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−
117 const esvisible =
100 const esvisible =
118 props.networkType === NETWORK_NAMES.ROPSTEN ||
101 props.networkType === NETWORK_NAMES.ROPSTEN ||
119 props.networkType === NETWORK_NAMES.MAINNET
102 props.networkType === NETWORK_NAMES.MAINNET
@@ -170,46 +153,8 @@ class SetProxy extends React.Component {
170 walletType={props.walletType}
153 walletType={props.walletType}
171 walletHdPath={props.walletHdPath}
154 walletHdPath={props.walletHdPath}
172 networkType={props.networkType}
155 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}
183 // Checks
156 // Checks
184− userApproval={state.userApproval}
185− canGenerate={ canGenerate }
157+ 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−
213 </Col>
158 </Col>
214 </Row>
159 </Row>
215 )
160 )