sms verification: check if tx failed, minor UI fixes
- checks if the tx failed by the amount of gas used - don't show the pending indicator if an error occured
This commit is contained in:
		
							parent
							
								
									8d4b1a332b
								
							
						
					
					
						commit
						da8c70fbe7
					
				@ -66,7 +66,7 @@ export default class SMSVerification extends Component {
 | 
				
			|||||||
        visible scroll
 | 
					        visible scroll
 | 
				
			||||||
        current={ phase }
 | 
					        current={ phase }
 | 
				
			||||||
        steps={ ['Enter Data', 'Request', 'Enter Code', 'Confirm', 'Done!'] }
 | 
					        steps={ ['Enter Data', 'Request', 'Enter Code', 'Confirm', 'Done!'] }
 | 
				
			||||||
        waiting={ [ 1, 3 ] }
 | 
					        waiting={ error ? [] : [ 1, 3 ] }
 | 
				
			||||||
      >
 | 
					      >
 | 
				
			||||||
        { this.renderStep(phase, error) }
 | 
					        { this.renderStep(phase, error) }
 | 
				
			||||||
      </Modal>
 | 
					      </Modal>
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										28
									
								
								js/src/modals/SMSVerification/check-if-tx-failed.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								js/src/modals/SMSVerification/check-if-tx-failed.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					// Copyright 2015, 2016 Ethcore (UK) Ltd.
 | 
				
			||||||
 | 
					// This file is part of Parity.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Parity is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					// it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 | 
					// the Free Software Foundation, either version 3 of the License, or
 | 
				
			||||||
 | 
					// (at your option) any later version.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Parity is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					// GNU General Public License for more details.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// You should have received a copy of the GNU General Public License
 | 
				
			||||||
 | 
					// along with Parity.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const checkIfTxFailed = (api, tx, gasSent) => {
 | 
				
			||||||
 | 
					  return api.pollMethod('eth_getTransactionReceipt', tx)
 | 
				
			||||||
 | 
					  .then((receipt) => {
 | 
				
			||||||
 | 
					    // TODO: Right now, there's no way to tell wether the EVM code crashed.
 | 
				
			||||||
 | 
					    // Because you usually send a bit more gas than estimated (to make sure
 | 
				
			||||||
 | 
					    // it gets mined quickly), we transaction probably failed if all the gas
 | 
				
			||||||
 | 
					    // has been used up.
 | 
				
			||||||
 | 
					    return receipt.gasUsed.eq(gasSent);
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default checkIfTxFailed;
 | 
				
			||||||
@ -24,6 +24,7 @@ const contract = '0xcE381B876A85A72303f7cA7b3a012f58F4CEEEeB';
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import checkIfVerified from './check-if-verified';
 | 
					import checkIfVerified from './check-if-verified';
 | 
				
			||||||
import checkIfRequested from './check-if-requested';
 | 
					import checkIfRequested from './check-if-requested';
 | 
				
			||||||
 | 
					import checkIfTxFailed from './check-if-tx-failed';
 | 
				
			||||||
import waitForConfirmations from './wait-for-confirmations';
 | 
					import waitForConfirmations from './wait-for-confirmations';
 | 
				
			||||||
import postToVerificationServer from './post-to-verification-server';
 | 
					import postToVerificationServer from './post-to-verification-server';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -163,8 +164,14 @@ export default class VerificationStore {
 | 
				
			|||||||
        })
 | 
					        })
 | 
				
			||||||
        .then((txHash) => {
 | 
					        .then((txHash) => {
 | 
				
			||||||
          this.requestTx = txHash;
 | 
					          this.requestTx = txHash;
 | 
				
			||||||
          this.step = POSTED_REQUEST;
 | 
					          return checkIfTxFailed(api, txHash, options.gas)
 | 
				
			||||||
          return waitForConfirmations(api, txHash, 1);
 | 
					          .then((hasFailed) => {
 | 
				
			||||||
 | 
					            if (hasFailed) {
 | 
				
			||||||
 | 
					              throw new Error('Transaction failed, all gas used up.');
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            this.step = POSTED_REQUEST;
 | 
				
			||||||
 | 
					            return waitForConfirmations(api, txHash, 1);
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -206,8 +213,14 @@ export default class VerificationStore {
 | 
				
			|||||||
      })
 | 
					      })
 | 
				
			||||||
      .then((txHash) => {
 | 
					      .then((txHash) => {
 | 
				
			||||||
        this.confirmationTx = txHash;
 | 
					        this.confirmationTx = txHash;
 | 
				
			||||||
        this.step = POSTED_CONFIRMATION;
 | 
					        return checkIfTxFailed(api, txHash, options.gas)
 | 
				
			||||||
        return waitForConfirmations(api, txHash, 2);
 | 
					        .then((hasFailed) => {
 | 
				
			||||||
 | 
					          if (hasFailed) {
 | 
				
			||||||
 | 
					            throw new Error('Transaction failed, all gas used up.');
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          this.step = POSTED_CONFIRMATION;
 | 
				
			||||||
 | 
					          return waitForConfirmations(api, txHash, 1);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
      .then(() => {
 | 
					      .then(() => {
 | 
				
			||||||
        this.step = DONE;
 | 
					        this.step = DONE;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user