diff --git a/js/src/modals/SMSVerification/SMSVerification.js b/js/src/modals/SMSVerification/SMSVerification.js index dbdb7625f..3575fc76a 100644 --- a/js/src/modals/SMSVerification/SMSVerification.js +++ b/js/src/modals/SMSVerification/SMSVerification.js @@ -66,7 +66,7 @@ export default class SMSVerification extends Component { visible scroll current={ phase } steps={ ['Enter Data', 'Request', 'Enter Code', 'Confirm', 'Done!'] } - waiting={ [ 1, 3 ] } + waiting={ error ? [] : [ 1, 3 ] } > { this.renderStep(phase, error) } diff --git a/js/src/modals/SMSVerification/check-if-tx-failed.js b/js/src/modals/SMSVerification/check-if-tx-failed.js new file mode 100644 index 000000000..39689bedd --- /dev/null +++ b/js/src/modals/SMSVerification/check-if-tx-failed.js @@ -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 . + +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; diff --git a/js/src/modals/SMSVerification/store.js b/js/src/modals/SMSVerification/store.js index 2d4aa099b..d8a1247e5 100644 --- a/js/src/modals/SMSVerification/store.js +++ b/js/src/modals/SMSVerification/store.js @@ -24,6 +24,7 @@ const contract = '0xcE381B876A85A72303f7cA7b3a012f58F4CEEEeB'; import checkIfVerified from './check-if-verified'; import checkIfRequested from './check-if-requested'; +import checkIfTxFailed from './check-if-tx-failed'; import waitForConfirmations from './wait-for-confirmations'; import postToVerificationServer from './post-to-verification-server'; @@ -163,8 +164,14 @@ export default class VerificationStore { }) .then((txHash) => { this.requestTx = txHash; - this.step = POSTED_REQUEST; - return waitForConfirmations(api, txHash, 1); + return checkIfTxFailed(api, txHash, options.gas) + .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) => { this.confirmationTx = txHash; - this.step = POSTED_CONFIRMATION; - return waitForConfirmations(api, txHash, 2); + return checkIfTxFailed(api, txHash, options.gas) + .then((hasFailed) => { + if (hasFailed) { + throw new Error('Transaction failed, all gas used up.'); + } + this.step = POSTED_CONFIRMATION; + return waitForConfirmations(api, txHash, 1); + }); }) .then(() => { this.step = DONE;