Use estimateGas error (as per updated implementation) (#4131)

* Use estimateGas error (as per updated implementation)

* EXCEPTION_ERROR as per #4142
This commit is contained in:
Jaco Greeff 2017-01-12 13:56:37 +01:00 committed by Nicolas Gotchac
parent 311730ea95
commit 389e4e3bc0
6 changed files with 33 additions and 5 deletions

View File

@ -25,6 +25,7 @@ export const ERROR_CODES = {
UNKNOWN_ERROR: -32009, UNKNOWN_ERROR: -32009,
TRANSACTION_ERROR: -32010, TRANSACTION_ERROR: -32010,
EXECUTION_ERROR: -32015, EXECUTION_ERROR: -32015,
EXCEPTION_ERROR: -32016,
ACCOUNT_LOCKED: -32020, ACCOUNT_LOCKED: -32020,
PASSWORD_INVALID: -32021, PASSWORD_INVALID: -32021,
ACCOUNT_ERROR: -32023, ACCOUNT_ERROR: -32023,

View File

@ -391,6 +391,10 @@ class DeployContract extends Component {
.then(([gasEst, gas]) => { .then(([gasEst, gas]) => {
this.gasStore.setEstimated(gasEst.toFixed(0)); this.gasStore.setEstimated(gasEst.toFixed(0));
this.gasStore.setGas(gas.toFixed(0)); this.gasStore.setGas(gas.toFixed(0));
})
.catch((error) => {
this.gasStore.setEstimatedError();
console.warn('estimateGas', error);
}); });
} }

View File

@ -155,8 +155,7 @@ class ExecuteContract extends Component {
} }
return ( return (
<Warning <Warning warning={ errorEstimated } />
warning={ errorEstimated } />
); );
} }
@ -378,6 +377,7 @@ class ExecuteContract extends Component {
this.gasStore.setGas(gas.toFixed(0)); this.gasStore.setGas(gas.toFixed(0));
}) })
.catch((error) => { .catch((error) => {
this.gasStore.setEstimatedError();
console.warn('estimateGas', error); console.warn('estimateGas', error);
}); });
} }

View File

@ -357,6 +357,7 @@ export default class TransferStore {
}); });
}) })
.catch((error) => { .catch((error) => {
this.gasStore.setEstimatedError();
console.warn('etimateGas', error); console.warn('etimateGas', error);
this.recalculate(redo); this.recalculate(redo);
}); });

View File

@ -62,6 +62,10 @@ export default class GasPriceEditor {
this.errorTotal = errorTotal; this.errorTotal = errorTotal;
} }
@action setEstimatedError = (errorEstimated = ERRORS.gasException) => {
this.errorEstimated = errorEstimated;
}
@action setEstimated = (estimated) => { @action setEstimated = (estimated) => {
transaction(() => { transaction(() => {
const bn = new BigNumber(estimated); const bn = new BigNumber(estimated);
@ -69,11 +73,11 @@ export default class GasPriceEditor {
this.estimated = estimated; this.estimated = estimated;
if (bn.gte(MAX_GAS_ESTIMATION)) { if (bn.gte(MAX_GAS_ESTIMATION)) {
this.errorEstimated = ERRORS.gasException; this.setEstimatedError(ERRORS.gasException);
} else if (bn.gte(this.gasLimit)) { } else if (bn.gte(this.gasLimit)) {
this.errorEstimated = ERRORS.gasBlockLimit; this.setEstimatedError(ERRORS.gasBlockLimit);
} else { } else {
this.errorEstimated = null; this.setEstimatedError(null);
} }
}); });
} }

View File

@ -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', () => { describe('setEstimated', () => {
it('sets the value', () => { it('sets the value', () => {
store.setEstimated('789'); store.setEstimated('789');