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

Commit aa7ee63

Browse files
committed
Check for valid bitcoin address before navigating to pay bitcoin view
1 parent 120bf0d commit aa7ee63

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/action/payment.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { PREFIX_URI } from '../config';
2-
import { toSatoshis, toAmount, parseSat, isValidUri, nap } from '../helper';
2+
import {
3+
toSatoshis,
4+
toAmount,
5+
parseSat,
6+
isLnUri,
7+
isAddress,
8+
nap,
9+
} from '../helper';
310
import * as log from './log';
411

512
class PaymentAction {
@@ -14,7 +21,7 @@ class PaymentAction {
1421
listenForUrl(ipcRenderer) {
1522
ipcRenderer.on('open-url', async (event, url) => {
1623
log.info('open-url', url);
17-
if (!isValidUri(url)) {
24+
if (!isLnUri(url)) {
1825
return;
1926
}
2027
while (!this._store.lndReady) {
@@ -48,8 +55,10 @@ class PaymentAction {
4855
}
4956
if (await this.decodeInvoice({ invoice: this._store.payment.address })) {
5057
this._nav.goPayLightningConfirm();
51-
} else {
58+
} else if (isAddress(this._store.payment.address)) {
5259
this._nav.goPayBitcoin();
60+
} else {
61+
this._notification.display({ msg: 'Invalid invoice or address' });
5362
}
5463
}
5564

test/unit/action/payment.spec.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,18 @@ describe('Action Payments Unit Tests', () => {
118118
expect(nav.goPayLightningConfirm, 'was called once');
119119
});
120120

121-
it('should set response to null on error', async () => {
121+
it('should notify if not bitcoin address', async () => {
122122
store.payment.address = 'some-address';
123123
payment.decodeInvoice.resolves(false);
124124
await payment.checkType();
125+
expect(nav.goPayBitcoin, 'was not called');
126+
expect(notification.display, 'was called once');
127+
});
128+
129+
it('should navigate to bitcoin for valid address', async () => {
130+
store.payment.address = 'rfu4i1Mo2NF7TQsN9bMVLFSojSzcyQCEH5';
131+
payment.decodeInvoice.resolves(false);
132+
await payment.checkType();
125133
expect(nav.goPayBitcoin, 'was called once');
126134
});
127135
});

0 commit comments

Comments
 (0)