diff options
Diffstat (limited to 'ui/app/components/send')
-rw-r--r-- | ui/app/components/send/send.component.js | 5 | ||||
-rw-r--r-- | ui/app/components/send/send.container.js | 4 | ||||
-rw-r--r-- | ui/app/components/send/tests/send-component.test.js | 38 |
3 files changed, 36 insertions, 11 deletions
diff --git a/ui/app/components/send/send.component.js b/ui/app/components/send/send.component.js index 5c12826ea..301acb1db 100644 --- a/ui/app/components/send/send.component.js +++ b/ui/app/components/send/send.component.js @@ -163,9 +163,10 @@ export default class SendTransactionScreen extends PersistentForm { } componentDidMount () { - this.props.fetchGasEstimates() - .then(() => { + this.props.fetchBasicGasEstimates() + .then(basicEstimates => { this.updateGas() + this.props.fetchGasEstimates(basicEstimates.blockTime) }) } diff --git a/ui/app/components/send/send.container.js b/ui/app/components/send/send.container.js index f240774d4..ac804cf2a 100644 --- a/ui/app/components/send/send.container.js +++ b/ui/app/components/send/send.container.js @@ -37,6 +37,7 @@ import { updateSendErrors, } from '../../ducks/send.duck' import { + fetchBasicGasEstimates, fetchGasEstimates, } from '../../ducks/gas.duck' import { @@ -107,6 +108,7 @@ function mapDispatchToProps (dispatch) { scanQrCode: () => dispatch(showQrScanner(SEND_ROUTE)), qrCodeDetected: (data) => dispatch(qrCodeDetected(data)), updateSendTo: (to, nickname) => dispatch(updateSendTo(to, nickname)), - fetchGasEstimates: () => dispatch(fetchGasEstimates()), + fetchBasicGasEstimates: () => dispatch(fetchBasicGasEstimates()), + fetchGasEstimates: (blockTime) => dispatch(fetchGasEstimates(blockTime)), } } diff --git a/ui/app/components/send/tests/send-component.test.js b/ui/app/components/send/tests/send-component.test.js index 82e84de30..68d2fc47e 100644 --- a/ui/app/components/send/tests/send-component.test.js +++ b/ui/app/components/send/tests/send-component.test.js @@ -8,12 +8,23 @@ import SendHeader from '../send-header/send-header.container' import SendContent from '../send-content/send-content.component' import SendFooter from '../send-footer/send-footer.container' +function timeout (time) { + return new Promise((resolve, reject) => { + setTimeout(resolve, time || 1500) + }) +} + +const mockBasicGasEstimates = { + blockTime: 'mockBlockTime', +} + const propsMethodSpies = { updateAndSetGasLimit: sinon.spy(), updateSendErrors: sinon.spy(), updateSendTokenBalance: sinon.spy(), resetSendState: sinon.spy(), - fetchGasEstimates: sinon.stub().returns(Promise.resolve()), + fetchBasicGasEstimates: sinon.stub().returns(Promise.resolve(mockBasicGasEstimates)), + fetchGasEstimates: sinon.spy(), } const utilsMethodStubs = { getAmountErrorObject: sinon.stub().returns({ amount: 'mockAmountError' }), @@ -38,6 +49,7 @@ describe('Send Component', function () { blockGasLimit={'mockBlockGasLimit'} conversionRate={10} editingTransactionId={'mockEditingTransactionId'} + fetchBasicGasEstimates={propsMethodSpies.fetchBasicGasEstimates} fetchGasEstimates={propsMethodSpies.fetchGasEstimates} from={ { address: 'mockAddress', balance: 'mockBalance' } } gasLimit={'mockGasLimit'} @@ -65,7 +77,7 @@ describe('Send Component', function () { utilsMethodStubs.doesAmountErrorRequireUpdate.resetHistory() utilsMethodStubs.getAmountErrorObject.resetHistory() utilsMethodStubs.getGasFeeErrorObject.resetHistory() - propsMethodSpies.fetchGasEstimates.resetHistory() + propsMethodSpies.fetchBasicGasEstimates.resetHistory() propsMethodSpies.updateAndSetGasLimit.resetHistory() propsMethodSpies.updateSendErrors.resetHistory() propsMethodSpies.updateSendTokenBalance.resetHistory() @@ -76,19 +88,29 @@ describe('Send Component', function () { }) describe('componentDidMount', () => { - it('should call props.fetchGasEstimates', () => { - propsMethodSpies.fetchGasEstimates.resetHistory() - assert.equal(propsMethodSpies.fetchGasEstimates.callCount, 0) + it('should call props.fetchBasicGasEstimates', () => { + propsMethodSpies.fetchBasicGasEstimates.resetHistory() + assert.equal(propsMethodSpies.fetchBasicGasEstimates.callCount, 0) wrapper.instance().componentDidMount() - assert.equal(propsMethodSpies.fetchGasEstimates.callCount, 1) + assert.equal(propsMethodSpies.fetchBasicGasEstimates.callCount, 1) }) - it('should call this.updateGas', () => { + it('should call this.updateGas', async () => { SendTransactionScreen.prototype.updateGas.resetHistory() propsMethodSpies.updateSendErrors.resetHistory() assert.equal(SendTransactionScreen.prototype.updateGas.callCount, 0) wrapper.instance().componentDidMount() - setTimeout(() => assert.equal(SendTransactionScreen.prototype.updateGas.callCount, 1), 250) + await timeout(250) + assert.equal(SendTransactionScreen.prototype.updateGas.callCount, 1) + }) + + it('should call props.fetchGasEstimates with the block time returned by fetchBasicGasEstimates', async () => { + propsMethodSpies.fetchGasEstimates.resetHistory() + assert.equal(propsMethodSpies.fetchGasEstimates.callCount, 0) + wrapper.instance().componentDidMount() + await timeout(250) + assert.equal(propsMethodSpies.fetchGasEstimates.callCount, 1) + assert.equal(propsMethodSpies.fetchGasEstimates.getCall(0).args[0], 'mockBlockTime') }) }) |