diff --git a/js/src/ui/GasPriceEditor/store.js b/js/src/ui/GasPriceEditor/store.js index 87dcce56e..c050a44ce 100644 --- a/js/src/ui/GasPriceEditor/store.js +++ b/js/src/ui/GasPriceEditor/store.js @@ -124,7 +124,12 @@ export default class GasPriceEditor { @action loadDefaults () { Promise .all([ - this._api.parity.gasPriceHistogram(), + // NOTE fetching histogram may fail if there is not enough data. + // We fallback to empty histogram. + this._api.parity.gasPriceHistogram().catch(() => ({ + bucket_bounds: [], + counts: [] + })), this._api.eth.gasPrice() ]) .then(([histogram, _price]) => { diff --git a/js/src/ui/GasPriceEditor/store.spec.js b/js/src/ui/GasPriceEditor/store.spec.js index efe30f48a..34b4d69f8 100644 --- a/js/src/ui/GasPriceEditor/store.spec.js +++ b/js/src/ui/GasPriceEditor/store.spec.js @@ -62,6 +62,31 @@ describe('ui/GasPriceEditor/store', () => { }); }); + describe('constructor (defaults) when histogram not available', () => { + const api = { + eth: { + gasPrice: sinon.stub().resolves(GASPRICE) + }, + parity: { + gasPriceHistogram: sinon.stub().rejects('Data not available') + } + }; + + beforeEach(() => { + store = new Store(api, { gasLimit: GASLIMIT }); + }); + + it('retrieves the histogram and gasPrice', done => { + expect(api.eth.gasPrice).to.have.been.called; + expect(api.parity.gasPriceHistogram).to.have.been.called; + + setImmediate(() => { + expect(store.histogram).not.to.be.null; + done(); + }); + }); + }); + describe('setters', () => { beforeEach(() => { store = new Store(null, { gasLimit: GASLIMIT });