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

Commit 04fcf70

Browse files
committed
Enabling toggle max to disable it again
1 parent 6b8f39c commit 04fcf70

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/action/payment.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,11 @@ class PaymentAction {
131131
* is useful for people to move their coins off of the app.
132132
* @return {Promise<undefined>}
133133
*/
134-
async setMax() {
134+
async toggleMax() {
135135
const { payment, balanceSatoshis, settings } = this._store;
136+
if (payment.sendAll) {
137+
return this.setAmount({ amount: '0' });
138+
}
136139
let amtSat = Math.floor(0.98 * balanceSatoshis);
137140
payment.amount = toAmount(amtSat, settings);
138141
await this.estimateFee();

src/view/pay-bitcoin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const PayBitcoinView = ({ store, nav, payment }) => (
6666
<MaxButton
6767
style={styles.maxBtn}
6868
active={store.payment.sendAll}
69-
onPress={() => payment.setMax()}
69+
onPress={() => payment.toggleMax()}
7070
/>
7171
<InputField
7272
placeholder="Bitcoin Address"

test/unit/action/payment.spec.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,25 @@ describe('Action Payments Unit Tests', () => {
308308
});
309309
});
310310

311-
describe('setMax()', () => {
311+
describe('toggleMax()', () => {
312312
it('should set the payment amount to the wallet balance minus fee', async () => {
313313
store.payment.address = 'some-address';
314314
store.balanceSatoshis = 100000;
315315
grpc.sendCommand.resolves({ feeSat: 100 });
316-
await payment.setMax();
316+
await payment.toggleMax();
317317
expect(store.payment.amount, 'to match', /^0[,.]0{3}9{3}$/);
318318
expect(store.payment.sendAll, 'to be true');
319319
});
320+
321+
it('should disable sendAll and reset amount', async () => {
322+
store.payment.sendAll = true;
323+
store.payment.amount = 1000;
324+
store.payment.address = 'some-address';
325+
store.balanceSatoshis = 100000;
326+
await payment.toggleMax();
327+
expect(store.payment.amount, 'to be', '0');
328+
expect(store.payment.sendAll, 'to be false');
329+
});
320330
});
321331

322332
describe('payBitcoin()', () => {

0 commit comments

Comments
 (0)