Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 3b07843

Browse files
committed
Prevent calling feeEstimate a second time if sendAll is set
1 parent 844f131 commit 3b07843

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

src/action/payment.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,10 @@ class PaymentAction {
234234
*/
235235
async initPayBitcoinConfirm() {
236236
try {
237-
await this.estimateFee();
237+
const { payment } = this._store;
238+
if (!payment.fee || !payment.sendAll) {
239+
await this.estimateFee();
240+
}
238241
this._nav.goPayBitcoinConfirm();
239242
} catch (err) {
240243
this._notification.display({ msg: 'Fee estimation failed!', err });

test/unit/action/payment.spec.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,23 +175,54 @@ describe('Action Payments Unit Tests', () => {
175175
});
176176

177177
describe('initPayBitcoinConfirm()', () => {
178-
it('should get estimate and navigate to confirm view', async () => {
178+
beforeEach(() => {
179179
store.payment.address = 'foo';
180180
store.payment.amount = '2000';
181181
grpc.sendCommand.withArgs('estimateFee').resolves({
182182
feeSat: 10000,
183183
});
184+
});
185+
186+
it('should get estimate and navigate to confirm view', async () => {
187+
await payment.initPayBitcoinConfirm();
188+
expect(grpc.sendCommand, 'was called once');
189+
expect(nav.goPayBitcoinConfirm, 'was called once');
190+
expect(notification.display, 'was not called');
191+
expect(store.payment.fee, 'to be', '0.0001');
192+
});
193+
194+
it('should not get estimate and navigate if fee and sendAll are set', async () => {
195+
store.payment.fee = '0.0002';
196+
store.payment.sendAll = true;
197+
await payment.initPayBitcoinConfirm();
198+
expect(grpc.sendCommand, 'was not called');
199+
expect(nav.goPayBitcoinConfirm, 'was called once');
200+
expect(notification.display, 'was not called');
201+
expect(store.payment.fee, 'to be', '0.0002');
202+
});
203+
204+
it('should get estimate and navigate if fee is set', async () => {
205+
store.payment.fee = '0.0002';
184206
await payment.initPayBitcoinConfirm();
207+
expect(grpc.sendCommand, 'was called once');
208+
expect(nav.goPayBitcoinConfirm, 'was called once');
209+
expect(notification.display, 'was not called');
210+
expect(store.payment.fee, 'to be', '0.0001');
211+
});
212+
213+
it('should get estimate and navigate if sendAll is set', async () => {
214+
store.payment.sendAll = true;
215+
await payment.initPayBitcoinConfirm();
216+
expect(grpc.sendCommand, 'was called once');
185217
expect(nav.goPayBitcoinConfirm, 'was called once');
186218
expect(notification.display, 'was not called');
187219
expect(store.payment.fee, 'to be', '0.0001');
188220
});
189221

190222
it('should display notification on error', async () => {
191-
store.payment.address = 'foo';
192-
store.payment.amount = '2000';
193223
grpc.sendCommand.withArgs('estimateFee').rejects();
194224
await payment.initPayBitcoinConfirm();
225+
expect(grpc.sendCommand, 'was called once');
195226
expect(nav.goPayBitcoinConfirm, 'was not called');
196227
expect(notification.display, 'was called once');
197228
expect(store.payment.fee, 'to be', '');

0 commit comments

Comments
 (0)