on master help sign in
- issueChild and setKeys views refactored
commita31db0ae9f9e568bcdeae14376727344c6b6e132 authorChris Johnson <chris@cjohnson.io> dateWed 3 Apr 2019, 19:50 (8 years ago) parent2de5d63
4 files changed+21−418
src/bridge/components/StatelessTransaction.js+5−5 src/bridge/views/IssueChild.js+11−220 src/bridge/views/SetKeys.js+5−191 src/bridge/views/SetProxy.js−2
src/bridge/components/StatelessTransaction.js+5−5
@@ -92,8 +92,7 @@ class StatelessTransaction extends React.Component {
9292 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
9393 })
9494 .catch(err => {
95− console.log('err = ', err)
96− // this.setState({ txError: err.map(val => val.merge()) })
95+ this.setState({ txError: err })
9796 })
9897 }
9998
@@ -121,6 +120,7 @@ class StatelessTransaction extends React.Component {
121120
122121 createUnsignedTxn() {
123122 const txn = this.props.createUnsignedTxn()
123+
124124 this.setState({ txn })
125125 }
126126
@@ -186,9 +186,9 @@ class StatelessTransaction extends React.Component {
186186
187187 const { state } = this
188188
189− const canSign = Just.hasInstance(state.txn)
190− const canApprove = Just.hasInstance(state.stx)
191− const canSend = Just.hasInstance(state.stx) && state.userApproval === true
189+ const canSign = Just.hasInstance(txn)
190+ const canApprove = Just.hasInstance(stx)
191+ const canSend = Just.hasInstance(stx) && userApproval === true
192192
193193 const generateButtonColor =
194194 Nothing.hasInstance(txn)
src/bridge/views/IssueChild.js+11−220
@@ -43,100 +43,35 @@ class IssueChild extends React.Component {
4343 ]
4444
4545 this.state = {
46− txError: Nothing(),
4746 receivingAddress: '',
4847 issuingPoint: issuingPoint,
4948 desiredPoint: '',
5049 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(),
5950 suggestions: suggestions,
6051 }
6152
6253 this.handlePointInput = this.handlePointInput.bind(this)
6354 this.handleAddressInput = this.handleAddressInput.bind(this)
6455 this.handleConfirmAvailability = this.handleConfirmAvailability.bind(this)
65− this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.bind(this)
66− this.handleSubmit = this.handleSubmit.bind(this)
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)
56+ this.createUnsignedTxn = this.createUnsignedTxn.bind(this)
57+ this.statelessRef = React.createRef();
7558 }
7659
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−
12160 handleAddressInput = (receivingAddress) => {
12261 this.setState({ receivingAddress })
123− this.handleClearTxn()
62+ this.statelessRef.current.clearTxn()
12463 }
12564
126−
127−
12865 handlePointInput(desiredPoint) {
12966 if (desiredPoint.length < 15) {
13067 this.setState({
13168 desiredPoint,
13269 isAvailable: Nothing()
13370 })
134− this.handleClearTxn()
71+ this.statelessRef.current.clearTxn()
13572 }
13673 }
13774
138−
139−
14075 handleConfirmAvailability() {
14176 this.confirmPointAvailability().then(r => {
14277 this.setState({
@@ -146,106 +81,6 @@ class IssueChild extends React.Component {
14681
14782 }
14883
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−
24984 async confirmPointAvailability() {
25085 const { contracts } = this.props
25186 const { desiredPoint } = this.state
@@ -307,8 +142,6 @@ class IssueChild extends React.Component {
307142 return Just(txn)
308143 }
309144
310−
311−
312145 buttonTriState() {
313146 const a = this.state.isAvailable
314147 if (Nothing.hasInstance(a)) return 'blue'
@@ -316,8 +149,6 @@ class IssueChild extends React.Component {
316149 if (a.value === true) return 'green'
317150 }
318151
319−
320−
321152 buttonTriStateText() {
322153 const a = this.state.isAvailable
323154 if (Nothing.hasInstance(a)) return 'Confirm Availablility'
@@ -343,7 +174,6 @@ class IssueChild extends React.Component {
343174 return vpatp && vchild
344175 }
345176
346−
347177 render() {
348178 const { props, state } = this
349179
@@ -362,12 +192,6 @@ class IssueChild extends React.Component {
362192 }
363193 })
364194
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−
371195 const esvisible =
372196 props.networkType === NETWORK_NAMES.ROPSTEN ||
373197 props.networkType === NETWORK_NAMES.MAINNET
@@ -480,46 +304,13 @@ class IssueChild extends React.Component {
480304 walletType={props.walletType}
481305 walletHdPath={props.walletHdPath}
482306 networkType={props.networkType}
483− // Tx
484− txn={state.txn}
485− stx={state.stx}
486− // Tx details
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 }
496− canSign={ canSign }
497− canApprove={ canApprove }
498− canSend={ canSend }
499− // Methods
500− createUnsignedTxn={this.handleCreateUnsignedTxn}
501− setUserApproval={this.handleSetUserApproval}
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−
307+ setTxnHashCursor={props.setTxnHashCursor}
308+ popRoute={props.popRoute}
309+ pushRoute={props.pushRoute}
310+ // Other
311+ canGenerate={canGenerate}
312+ createUnsignedTxn={this.createUnsignedTxn}
313+ ref={this.statelessRef} />
523314 </Col>
524315 </Row>
525316 )
src/bridge/views/SetKeys.js+5−191
@@ -45,36 +45,12 @@ class SetKeys extends React.Component {
4545 point: point,
4646 cryptoSuiteVersion: 1,
4747 continuity: false,
48− txn: Maybe.Nothing(),
49− txError: Maybe.Nothing(),
5048 isManagementSeed: false,
51− userApproval: false,
52− nonce: '',
53− gasPrice: '5',
54− showGasDetails: false,
55− chainId: '',
56− gasLimit: '600000',
57− stx: Maybe.Nothing(),
5849 }
5950
6051 this.handleNetworkSeedInput = this.handleNetworkSeedInput.bind(this)
6152 // Transaction
62− this.handleCreateUnsignedTxn = this.handleCreateUnsignedTxn.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− })
53+ this.createUnsignedTxn = this.createUnsignedTxn.bind(this)
7854 }
7955
8056 componentDidMount() {
@@ -90,30 +66,6 @@ class SetKeys extends React.Component {
9066 })
9167
9268 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− });
11769 }
11870
11971 async determineManagementSeed(ctrcs, addr) {
@@ -157,90 +109,6 @@ class SetKeys extends React.Component {
157109 this.setState({ networkSeed })
158110 }
159111
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−
244112 downloadKeyfile(networkSeed) {
245113 const { pointCache } = this.props
246114 const { pointCursor } = this.props
@@ -263,20 +131,6 @@ class SetKeys extends React.Component {
263131 saveAs(blob, `${ob.patp(point).slice(1)}-${revision}.key`)
264132 }
265133
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−
280134 createUnsignedTxn() {
281135 const { state, props } = this
282136
@@ -325,13 +179,6 @@ class SetKeys extends React.Component {
325179 state.networkSeed.length === 64
326180 && state.networkSeed.length === 64
327181
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−
335182 const pointDetails =
336183 state.point in props.pointCache
337184 ? props.pointCache[state.point]
@@ -379,45 +226,12 @@ class SetKeys extends React.Component {
379226 walletType={props.walletType}
380227 walletHdPath={props.walletHdPath}
381228 networkType={props.networkType}
229+ setTxnHashCursor={props.setTxnHashCursor}
230+ popRoute={props.popRoute}
231+ pushRoute={props.pushRoute}
382232 // 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}
394233 canGenerate={ canGenerate }
395− canSign={ canSign }
396− canApprove={ canApprove }
397− canSend={ canSend }
398− // Methods
399− createUnsignedTxn={this.handleCreateUnsignedTxn}
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− }
234+ createUnsignedTxn={this.createUnsignedTxn} />
421235
422236 </Col>
423237 </Row>
src/bridge/views/SetProxy.js−2
@@ -60,8 +60,6 @@ class SetProxy extends React.Component {
6060 }
6161
6262 createUnsignedTxn(proxyAddress) {
63− console.log('creatingTxn')
64−
6563 const { state, props } = this
6664
6765 const validContracts = props.contracts.matchWith({