Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Use estimateGas error (as per updated implementation) (#4131)
Browse files Browse the repository at this point in the history
* Use estimateGas error (as per updated implementation)

* EXCEPTION_ERROR as per #4142
  • Loading branch information
jacogr authored and ngotchac committed Jan 12, 2017
1 parent 311730e commit 389e4e3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions js/src/api/transport/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions js/src/modals/DeployContract/deployContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
4 changes: 2 additions & 2 deletions js/src/modals/ExecuteContract/executeContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ class ExecuteContract extends Component {
}

return (
<Warning
warning={ errorEstimated } />
<Warning warning={ errorEstimated } />
);
}

Expand Down Expand Up @@ -378,6 +377,7 @@ class ExecuteContract extends Component {
this.gasStore.setGas(gas.toFixed(0));
})
.catch((error) => {
this.gasStore.setEstimatedError();
console.warn('estimateGas', error);
});
}
Expand Down
1 change: 1 addition & 0 deletions js/src/modals/Transfer/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ export default class TransferStore {
});
})
.catch((error) => {
this.gasStore.setEstimatedError();
console.warn('etimateGas', error);
this.recalculate(redo);
});
Expand Down
10 changes: 7 additions & 3 deletions js/src/ui/GasPriceEditor/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,22 @@ export default class GasPriceEditor {
this.errorTotal = errorTotal;
}

@action setEstimatedError = (errorEstimated = ERRORS.gasException) => {
this.errorEstimated = errorEstimated;
}

@action setEstimated = (estimated) => {
transaction(() => {
const bn = new BigNumber(estimated);

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);
}
});
}
Expand Down
18 changes: 18 additions & 0 deletions js/src/ui/GasPriceEditor/store.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 389e4e3

Please sign in to comment.