on master help sign in
- issueChild and setKeys views refactored
a31db0aChris Johnson
src/bridge/components/StatelessTransaction.js+5−5
@@ -92,8 +92,7 @@ class StatelessTransaction extends React.Component {
92 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
92 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
93 })
93 })
94 .catch(err => {
94 .catch(err => {
95− console.log('err = ', err)
96− // this.setState({ txError: err.map(val => val.merge()) })
95+ this.setState({ txError: err })
97 })
96 })
98 }
97 }
99
98
@@ -121,6 +120,7 @@ class StatelessTransaction extends React.Component {
121
120
122 createUnsignedTxn() {
121 createUnsignedTxn() {
123 const txn = this.props.createUnsignedTxn()
122 const txn = this.props.createUnsignedTxn()
123+
124 this.setState({ txn })
124 this.setState({ txn })
125 }
125 }
126
126
@@ -186,9 +186,9 @@ class StatelessTransaction extends React.Component {
186
186
187 const { state } = this
187 const { state } = this
188
188
189− const canSign = Just.hasInstance(state.txn)
189+ const canSign = Just.hasInstance(txn)
190− const canApprove = Just.hasInstance(state.stx)
190+ const canApprove = Just.hasInstance(stx)
191− const canSend = Just.hasInstance(state.stx) && state.userApproval === true
191+ const canSend = Just.hasInstance(stx) && userApproval === true
192
192
193 const generateButtonColor =
193 const generateButtonColor =
194 Nothing.hasInstance(txn)
194 Nothing.hasInstance(txn)
src/bridge/views/IssueChild.js+11−220
@@ -43,100 +43,35 @@ class IssueChild extends React.Component {
43 ]
43 ]
44
44
45 this.state = {
45 this.state = {
46− txError: Nothing(),
47 receivingAddress: '',
46 receivingAddress: '',
48 issuingPoint: issuingPoint,
47 issuingPoint: issuingPoint,
49 desiredPoint: '',
48 desiredPoint: '',
50 isAvailable: Nothing(), // use Nothing to allow attempt when offline
49 isAvailable: Nothing(), // use Nothing to allow attempt when offline
51− userApproval: false,
52− nonce: '',
53− gasPrice: '5',
54− showGasDetails: false,
55− chainId: '',
56− gasLimit: '600000',
57− txn: Nothing(),
58− stx: Nothing(),
59 suggestions: suggestions,
50 suggestions: suggestions,
60 }
51 }
61
52
62 this.handlePointInput = this.handlePointInput.bind(this)
53 this.handlePointInput = this.handlePointInput.bind(this)
63 this.handleAddressInput = this.handleAddressInput.bind(this)
54 this.handleAddressInput = this.handleAddressInput.bind(this)
64 this.handleConfirmAvailability = this.handleConfirmAvailability.bind(this)
55 this.handleConfirmAvailability = this.handleConfirmAvailability.bind(this)
65− this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
56+ this.createUnsignedTxn = this.createUnsignedTxn.bind(this)
66− this.handleSubmit = this.handleSubmit.bind(this)
57+ this.statelessRef = React.createRef();
67− this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
68− this.handleSetTxn = this.handleSetTxn.bind(this)
69− this.handleSetStx = this.handleSetStx.bind(this)
70− this.handleSetNonce = this.handleSetNonce.bind(this)
71− this.handleSetChainId = this.handleSetChainId.bind(this)
72− this.handleSetGasPrice = this.handleSetGasPrice.bind(this)
73− this.handleSetGasLimit = this.handleSetGasLimit.bind(this)
74− this.toggleGasDetails = this.toggleGasDetails.bind(this)
75 }
58 }
76
59
77− toggleGasDetails() {
78− this.setState({
79− showGasDetails: !this.state.showGasDetails
80− })
81− }
82−
83− componentDidMount() {
84− const { props } = this
85−
86− const addr = props.wallet.matchWith({
87− Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
88− Nothing: () => {
89− throw BRIDGE_ERROR.MISSING_WALLET
90− }
91− })
92−
93− props.web3.matchWith({
94− Nothing: () => {},
95− Just: (w3) => {
96− const validWeb3 = w3.value
97−
98− const getTxMetadata = [
99− validWeb3.eth.getTransactionCount(addr),
100− validWeb3.eth.net.getId(),
101− validWeb3.eth.getGasPrice()
102− ]
103−
104− Promise.all(getTxMetadata).then(r => {
105− const txMetadata = {
106− nonce: r[0],
107− chainId: r[1],
108− gasPrice: fromWei(r[2], 'gwei'),
109− }
110−
111− this.setState({...txMetadata})
112−
113− })
114− }
115− })
116−
117− }
118−
119−
120−
121 handleAddressInput = (receivingAddress) => {
60 handleAddressInput = (receivingAddress) => {
122 this.setState({ receivingAddress })
61 this.setState({ receivingAddress })
123− this.handleClearTxn()
62+ this.statelessRef.current.clearTxn()
124 }
63 }
125
64
126−
127−
128 handlePointInput(desiredPoint) {
65 handlePointInput(desiredPoint) {
129 if (desiredPoint.length < 15) {
66 if (desiredPoint.length < 15) {
130 this.setState({
67 this.setState({
131 desiredPoint,
68 desiredPoint,
132 isAvailable: Nothing()
69 isAvailable: Nothing()
133 })
70 })
134− this.handleClearTxn()
71+ this.statelessRef.current.clearTxn()
135 }
72 }
136 }
73 }
137
74
138−
139−
140 handleConfirmAvailability() {
75 handleConfirmAvailability() {
141 this.confirmPointAvailability().then(r => {
76 this.confirmPointAvailability().then(r => {
142 this.setState({
77 this.setState({
@@ -146,106 +81,6 @@ class IssueChild extends React.Component {
146
81
147 }
82 }
148
83
149−
150−
151− handleCreateUnsignedTxn() {
152− const txn = this.createUnsignedTxn()
153− this.setState({ txn })
154− }
155−
156−
157− handleSetUserApproval(){
158− const {state} = this
159− this.setState({ userApproval: !state.userApproval })
160− }
161−
162−
163−
164− handleSetTxn(txn){
165− this.setState({ txn })
166− }
167−
168−
169−
170− handleSetStx(stx){
171− this.setState({
172− stx,
173− userApproval: false,
174− })
175− }
176−
177−
178−
179− handleSetNonce(nonce){
180− this.setState({ nonce })
181− this.handleClearStx()
182− }
183−
184−
185−
186− handleSetChainId(chainId){
187− this.setState({ chainId })
188− this.handleClearStx()
189− }
190−
191−
192−
193− handleSetGasPrice(gasPrice){
194− this.setState({ gasPrice })
195− this.handleClearStx()
196− }
197−
198−
199−
200− handleSetGasLimit(gasLimit){
201− this.setState({ gasLimit })
202− this.handleClearStx()
203− }
204−
205−
206−
207− handleClearStx() {
208− this.setState({
209− userApproval: false,
210− stx: Nothing(),
211− })
212− }
213−
214−
215−
216− handleClearTxn() {
217− this.setState({
218− userApproval: false,
219− txn: Nothing(),
220− stx: Nothing(),
221− })
222− }
223−
224−
225−
226− handleClearTransaction() {
227− this.setState({
228− userApproval: false,
229− txn: Nothing(),
230− stx: Nothing(),
231− })
232− }
233−
234−
235−
236− handleSubmit(){
237− const { props, state } = this
238− sendSignedTransaction(props.web3.value, state.stx)
239− .then(sent => {
240− props.setTxnHashCursor(sent)
241− props.popRoute()
242− props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
243− })
244− .catch(err => {
245− this.setState({ txError: err.map(val => val.merge()) })
246− })
247− }
248−
249 async confirmPointAvailability() {
84 async confirmPointAvailability() {
250 const { contracts } = this.props
85 const { contracts } = this.props
251 const { desiredPoint } = this.state
86 const { desiredPoint } = this.state
@@ -307,8 +142,6 @@ class IssueChild extends React.Component {
307 return Just(txn)
142 return Just(txn)
308 }
143 }
309
144
310−
311−
312 buttonTriState() {
145 buttonTriState() {
313 const a = this.state.isAvailable
146 const a = this.state.isAvailable
314 if (Nothing.hasInstance(a)) return 'blue'
147 if (Nothing.hasInstance(a)) return 'blue'
@@ -316,8 +149,6 @@ class IssueChild extends React.Component {
316 if (a.value === true) return 'green'
149 if (a.value === true) return 'green'
317 }
150 }
318
151
319−
320−
321 buttonTriStateText() {
152 buttonTriStateText() {
322 const a = this.state.isAvailable
153 const a = this.state.isAvailable
323 if (Nothing.hasInstance(a)) return 'Confirm Availablility'
154 if (Nothing.hasInstance(a)) return 'Confirm Availablility'
@@ -343,7 +174,6 @@ class IssueChild extends React.Component {
343 return vpatp && vchild
174 return vpatp && vchild
344 }
175 }
345
176
346−
347 render() {
177 render() {
348 const { props, state } = this
178 const { props, state } = this
349
179
@@ -362,12 +192,6 @@ class IssueChild extends React.Component {
362 }
192 }
363 })
193 })
364
194
365− const canSign = Just.hasInstance(state.txn)
366− const canApprove = Just.hasInstance(state.stx)
367− const canSend =
368− Just.hasInstance(state.stx)
369− && state.userApproval === true
370−
371 const esvisible =
195 const esvisible =
372 props.networkType === NETWORK_NAMES.ROPSTEN ||
196 props.networkType === NETWORK_NAMES.ROPSTEN ||
373 props.networkType === NETWORK_NAMES.MAINNET
197 props.networkType === NETWORK_NAMES.MAINNET
@@ -480,46 +304,13 @@ class IssueChild extends React.Component {
480 walletType={props.walletType}
304 walletType={props.walletType}
481 walletHdPath={props.walletHdPath}
305 walletHdPath={props.walletHdPath}
482 networkType={props.networkType}
306 networkType={props.networkType}
483− // Tx
307+ setTxnHashCursor={props.setTxnHashCursor}
484− txn={state.txn}
308+ popRoute={props.popRoute}
485− stx={state.stx}
309+ pushRoute={props.pushRoute}
486− // Tx details
310+ // Other
487− nonce={state.nonce}
488− gasPrice={state.gasPrice}
489− showGasDetails={state.showGasDetails}
490− toggleGasDetails={this.toggleGasDetails}
491− chainId={state.chainId}
492− gasLimit={state.gasLimit}
493− // Checks
494− userApproval={state.userApproval}
495− canGenerate={ canGenerate }
311+ canGenerate={canGenerate}
496− canSign={ canSign }
497− canApprove={ canApprove }
498− canSend={ canSend }
499− // Methods
500− createUnsignedTxn={this.handleCreateUnsignedTxn}
312+ createUnsignedTxn={this.createUnsignedTxn}
501− setUserApproval={this.handleSetUserApproval}
313+ ref={this.statelessRef} />
502− setTxn={this.handleSetTxn}
503− setStx={this.handleSetStx}
504− setNonce={this.handleSetNonce}
505− setChainId={this.handleSetChainId}
506− setGasPrice={this.handleSetGasPrice}
507− setGasLimit={this.handleSetGasLimit}
508− handleSubmit={this.handleSubmit} />
509−
510− {
511− Nothing.hasInstance(state.txError)
512− ? ''
513− : <Warning className={'mt-8'}>
514− <H3 style={{marginTop: 0, paddingTop: 0}}>
515− {
516− 'There was an error sending your transaction.'
517− }
518− </H3>
519− { state.txError.value }
520− </Warning>
521− }
522−
523 </Col>
314 </Col>
524 </Row>
315 </Row>
525 )
316 )
src/bridge/views/SetKeys.js+5−191
@@ -45,36 +45,12 @@ class SetKeys extends React.Component {
45 point: point,
45 point: point,
46 cryptoSuiteVersion: 1,
46 cryptoSuiteVersion: 1,
47 continuity: false,
47 continuity: false,
48− txn: Maybe.Nothing(),
49− txError: Maybe.Nothing(),
50 isManagementSeed: false,
48 isManagementSeed: false,
51− userApproval: false,
52− nonce: '',
53− gasPrice: '5',
54− showGasDetails: false,
55− chainId: '',
56− gasLimit: '600000',
57− stx: Maybe.Nothing(),
58 }
49 }
59
50
60 this.handleNetworkSeedInput = this.handleNetworkSeedInput.bind(this)
51 this.handleNetworkSeedInput = this.handleNetworkSeedInput.bind(this)
61 // Transaction
52 // Transaction
62− this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
53+ this.createUnsignedTxn = this.createUnsignedTxn.bind(this)
63− this.handleSubmit = this.handleSubmit.bind(this)
64− this.handleSetUserApproval = this.handleSetUserApproval.bind(this)
65− this.handleSetTxn = this.handleSetTxn.bind(this)
66− this.handleSetStx = this.handleSetStx.bind(this)
67− this.handleSetNonce = this.handleSetNonce.bind(this)
68− this.handleSetChainId = this.handleSetChainId.bind(this)
69− this.handleSetGasPrice = this.handleSetGasPrice.bind(this)
70− this.handleSetGasLimit = this.handleSetGasLimit.bind(this)
71− this.toggleGasDetails = this.toggleGasDetails.bind(this)
72− }
73−
74− toggleGasDetails() {
75− this.setState({
76− showGasDetails: !this.state.showGasDetails
77− })
78 }
54 }
79
55
80 componentDidMount() {
56 componentDidMount() {
@@ -90,30 +66,6 @@ class SetKeys extends React.Component {
90 })
66 })
91
67
92 this.determineManagementSeed(props.contracts.value, addr)
68 this.determineManagementSeed(props.contracts.value, addr)
93−
94− props.web3.matchWith({
95− Nothing: () => {},
96− Just: (w3) => {
97− const validWeb3 = w3.value
98−
99− const getTxMetadata = [
100− validWeb3.eth.getTransactionCount(addr),
101− validWeb3.eth.net.getId(),
102− validWeb3.eth.getGasPrice()
103− ];
104−
105− Promise.all(getTxMetadata).then(r => {
106− const txMetadata = {
107− nonce: r[0],
108− chainId: r[1],
109− gasPrice: fromWei(r[2], 'gwei'),
110− };
111−
112− this.setState({...txMetadata})
113−
114− })
115− }
116− });
117 }
69 }
118
70
119 async determineManagementSeed(ctrcs, addr) {
71 async determineManagementSeed(ctrcs, addr) {
@@ -157,90 +109,6 @@ class SetKeys extends React.Component {
157 this.setState({ networkSeed })
109 this.setState({ networkSeed })
158 }
110 }
159
111
160− handleCreateUnsignedTxn() {
161− const txn = this.createUnsignedTxn()
162− this.setState({ txn })
163− }
164−
165−
166− handleSetUserApproval(){
167− const {state} = this
168− this.setState({ userApproval: !state.userApproval })
169− }
170−
171−
172−
173− handleSetTxn(txn){
174− this.setState({ txn })
175− }
176−
177−
178−
179− handleSetStx(stx){
180− this.setState({
181− stx,
182− userApproval: false,
183− })
184− }
185−
186−
187−
188− handleSetNonce(nonce){
189− this.setState({ nonce })
190− this.handleClearStx()
191− }
192−
193−
194−
195− handleSetChainId(chainId){
196− this.setState({ chainId })
197− this.handleClearStx()
198− }
199−
200−
201−
202− handleSetGasPrice(gasPrice){
203− this.setState({ gasPrice })
204− this.handleClearStx()
205− }
206−
207−
208−
209− handleSetGasLimit(gasLimit){
210− this.setState({ gasLimit })
211− this.handleClearStx()
212− }
213−
214−
215−
216− handleClearStx() {
217− this.setState({
218− userApproval: false,
219− stx: Maybe.Nothing(),
220− })
221− }
222−
223−
224−
225−
226− handleClearTxn() {
227− this.setState({
228− userApproval: false,
229− txn: Maybe.Nothing(),
230− stx: Maybe.Nothing(),
231− })
232− }
233−
234−
235−
236− handleClearTransaction() {
237− this.setState({
238− userApproval: false,
239− txn: Maybe.Nothing(),
240− stx: Maybe.Nothing(),
241− })
242− }
243−
244 downloadKeyfile(networkSeed) {
112 downloadKeyfile(networkSeed) {
245 const { pointCache } = this.props
113 const { pointCache } = this.props
246 const { pointCursor } = this.props
114 const { pointCursor } = this.props
@@ -263,20 +131,6 @@ class SetKeys extends React.Component {
263 saveAs(blob, `${ob.patp(point).slice(1)}-${revision}.key`)
131 saveAs(blob, `${ob.patp(point).slice(1)}-${revision}.key`)
264 }
132 }
265
133
266− handleSubmit(){
267− const { props, state } = this
268− sendSignedTransaction(props.web3.value, state.stx)
269− .then(sent => {
270− props.setNetworkSeedCache(this.state.networkSeed)
271− props.setTxnHashCursor(sent)
272− props.popRoute()
273− props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION, {promptKeyfile: true})
274− })
275− .catch(err => {
276− this.setState({ txError: err.map(val => val.merge()) })
277− })
278− }
279−
280 createUnsignedTxn() {
134 createUnsignedTxn() {
281 const { state, props } = this
135 const { state, props } = this
282
136
@@ -325,13 +179,6 @@ class SetKeys extends React.Component {
325 state.networkSeed.length === 64
179 state.networkSeed.length === 64
326 && state.networkSeed.length === 64
180 && state.networkSeed.length === 64
327
181
328− const canSign = Maybe.Just.hasInstance(state.txn)
329− const canApprove = Maybe.Just.hasInstance(state.stx)
330−
331− const canSend =
332− Maybe.Just.hasInstance(state.stx)
333− && state.userApproval === true
334−
335 const pointDetails =
182 const pointDetails =
336 state.point in props.pointCache
183 state.point in props.pointCache
337 ? props.pointCache[state.point]
184 ? props.pointCache[state.point]
@@ -379,45 +226,12 @@ class SetKeys extends React.Component {
379 walletType={props.walletType}
226 walletType={props.walletType}
380 walletHdPath={props.walletHdPath}
227 walletHdPath={props.walletHdPath}
381 networkType={props.networkType}
228 networkType={props.networkType}
229+ setTxnHashCursor={props.setTxnHashCursor}
230+ popRoute={props.popRoute}
231+ pushRoute={props.pushRoute}
382 // Tx
232 // Tx
383− txn={state.txn}
384− stx={state.stx}
385− // Tx details
386− nonce={state.nonce}
387− gasPrice={state.gasPrice}
388− chainId={state.chainId}
389− gasLimit={state.gasLimit}
390− showGasDetails={state.showGasDetails}
391− toggleGasDetails={this.toggleGasDetails}
392− // Checks
393− userApproval={state.userApproval}
394 canGenerate={ canGenerate }
233 canGenerate={ canGenerate }
395− canSign={ canSign }
396− canApprove={ canApprove }
397− canSend={ canSend }
398− // Methods
399− createUnsignedTxn={this.handleCreateUnsignedTxn}
234+ createUnsignedTxn={this.createUnsignedTxn} />
400− setUserApproval={this.handleSetUserApproval}
401− setTxn={this.handleSetTxn}
402− setStx={this.handleSetStx}
403− setNonce={this.handleSetNonce}
404− setChainId={this.handleSetChainId}
405− setGasPrice={this.handleSetGasPrice}
406− setGasLimit={this.handleSetGasLimit}
407− handleSubmit={this.handleSubmit} />
408−
409− {
410− Maybe.Nothing.hasInstance(state.txError)
411− ? ''
412− : <Warning className={'mt-8'}>
413− <H3 style={{marginTop: 0, paddingTop: 0}}>
414− {
415− 'There was an error sending your transaction.'
416− }
417− </H3>
418− { state.txError.value }
419− </Warning>
420− }
421
235
422 </Col>
236 </Col>
423 </Row>
237 </Row>
src/bridge/views/SetProxy.js−2
@@ -60,8 +60,6 @@ class SetProxy extends React.Component {
60 }
60 }
61
61
62 createUnsignedTxn(proxyAddress) {
62 createUnsignedTxn(proxyAddress) {
63− console.log('creatingTxn')
64−
65 const { state, props } = this
63 const { state, props } = this
66
64
67 const validContracts = props.contracts.matchWith({
65 const validContracts = props.contracts.matchWith({