From 389e4e3bc0201c540a3903e2e2501dc75493fe5b Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 12 Jan 2017 13:56:37 +0100 Subject: [PATCH] Use estimateGas error (as per updated implementation) (#4131) * Use estimateGas error (as per updated implementation) * EXCEPTION_ERROR as per #4142 --- js/src/api/transport/error.js | 1 + js/src/modals/DeployContract/deployContract.js | 4 ++++ .../modals/ExecuteContract/executeContract.js | 4 ++-- js/src/modals/Transfer/store.js | 1 + js/src/ui/GasPriceEditor/store.js | 10 +++++++--- js/src/ui/GasPriceEditor/store.spec.js | 18 ++++++++++++++++++ 6 files changed, 33 insertions(+), 5 deletions(-) diff --git a/js/src/api/transport/error.js b/js/src/api/transport/error.js index 5fe9aac06a7..512d4289e7a 100644 --- a/js/src/api/transport/error.js +++ b/js/src/api/transport/error.js @@ -25,6 +25,7 @@ export const ERROR_CODES = { UNKNOWN_ERROR: -32009, TRANSACTION_ERROR: -32010, EXECUTION_ERROR: -32015, + EXCEPTION_ERROR: -32016, ACCOUNT_LOCKED: -32020, PASSWORD_INVALID: -32021, ACCOUNT_ERROR: -32023, diff --git a/js/src/modals/DeployContract/deployContract.js b/js/src/modals/DeployContract/deployContract.js index 1bda0dddf77..701c689ad6d 100644 --- a/js/src/modals/DeployContract/deployContract.js +++ b/js/src/modals/DeployContract/deployContract.js @@ -391,6 +391,10 @@ class DeployContract extends Component { .then(([gasEst, gas]) => { this.gasStore.setEstimated(gasEst.toFixed(0)); this.gasStore.setGas(gas.toFixed(0)); + }) + .catch((error) => { + this.gasStore.setEstimatedError(); + console.warn('estimateGas', error); }); } diff --git a/js/src/modals/ExecuteContract/executeContract.js b/js/src/modals/ExecuteContract/executeContract.js index 569356cf9c0..689678a7c74 100644 --- a/js/src/modals/ExecuteContract/executeContract.js +++ b/js/src/modals/ExecuteContract/executeContract.js @@ -155,8 +155,7 @@ class ExecuteContract extends Component { } return ( - + ); } @@ -378,6 +377,7 @@ class ExecuteContract extends Component { this.gasStore.setGas(gas.toFixed(0)); }) .catch((error) => { + this.gasStore.setEstimatedError(); console.warn('estimateGas', error); }); } diff --git a/js/src/modals/Transfer/store.js b/js/src/modals/Transfer/store.js index 3a01b94aeb6..9da9023f1a3 100644 --- a/js/src/modals/Transfer/store.js +++ b/js/src/modals/Transfer/store.js @@ -357,6 +357,7 @@ export default class TransferStore { }); }) .catch((error) => { + this.gasStore.setEstimatedError(); console.warn('etimateGas', error); this.recalculate(redo); }); diff --git a/js/src/ui/GasPriceEditor/store.js b/js/src/ui/GasPriceEditor/store.js index 22867fdd098..bb83738546c 100644 --- a/js/src/ui/GasPriceEditor/store.js +++ b/js/src/ui/GasPriceEditor/store.js @@ -62,6 +62,10 @@ export default class GasPriceEditor { this.errorTotal = errorTotal; } + @action setEstimatedError = (errorEstimated = ERRORS.gasException) => { + this.errorEstimated = errorEstimated; + } + @action setEstimated = (estimated) => { transaction(() => { const bn = new BigNumber(estimated); @@ -69,11 +73,11 @@ export default class GasPriceEditor { this.estimated = estimated; if (bn.gte(MAX_GAS_ESTIMATION)) { - this.errorEstimated = ERRORS.gasException; + this.setEstimatedError(ERRORS.gasException); } else if (bn.gte(this.gasLimit)) { - this.errorEstimated = ERRORS.gasBlockLimit; + this.setEstimatedError(ERRORS.gasBlockLimit); } else { - this.errorEstimated = null; + this.setEstimatedError(null); } }); } diff --git a/js/src/ui/GasPriceEditor/store.spec.js b/js/src/ui/GasPriceEditor/store.spec.js index 889eee4db30..3dcf2e22c2a 100644 --- a/js/src/ui/GasPriceEditor/store.spec.js +++ b/js/src/ui/GasPriceEditor/store.spec.js @@ -82,6 +82,24 @@ describe('ui/GasPriceEditor/store', () => { }); }); + describe('setEstimatedError', () => { + it('sets the value as provided', () => { + store.setEstimatedError('errorTest'); + expect(store.errorEstimated).to.equal('errorTest'); + }); + + it('sets the null value as provided', () => { + store.setEstimatedError('errorTest'); + store.setEstimatedError(null); + expect(store.errorEstimated).to.be.null; + }); + + it('sets a default error when none provided', () => { + store.setEstimatedError(); + expect(store.errorEstimated).to.equal(ERRORS.gasException); + }); + }); + describe('setEstimated', () => { it('sets the value', () => { store.setEstimated('789');