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

Use estimateGas error (as per updated implementation) #4131

Merged
merged 3 commits into from
Jan 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this used anywhere?

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