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

Commit b8884f8

Browse files
Merge pull request #1032 from lightninglabs/inbound-capacity-error
Show warning ntfn when generating an invoice that's too big to receive.
2 parents b86c822 + 8010fb6 commit b8884f8

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

src/action/invoice.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ class InvoiceAction {
6161
async generateUri() {
6262
try {
6363
const { invoice, settings } = this._store;
64+
const satAmount = toSatoshis(invoice.amount, settings);
65+
this.checkAmount({ satAmount });
6466
const response = await this._grpc.sendCommand('addInvoice', {
65-
value: toSatoshis(invoice.amount, settings),
67+
value: satAmount,
6668
memo: invoice.note,
6769
expiry: 172800,
6870
private: true,
@@ -75,6 +77,23 @@ class InvoiceAction {
7577
}
7678
}
7779

80+
/**
81+
* Verify that the user has a channel with enough receive capacity to
82+
* receive the given amount.
83+
* @param {number} options.satAmount The amount to receive.
84+
* @return {undefined}
85+
*/
86+
checkAmount({ satAmount }) {
87+
const { channels } = this._store;
88+
const hasInbound = channels.find(c => c.remoteBalance >= satAmount);
89+
if (hasInbound) {
90+
return;
91+
}
92+
this._notification.display({
93+
msg: "You don't have enough inbound capacity to receive this payment.",
94+
});
95+
}
96+
7897
/**
7998
* A simple wrapper around the react native clipboard api. This can
8099
* be called when a string like a payment request or address should be

test/unit/action/invoice.spec.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('Action Invoice Unit Tests', () => {
7777
grpc.sendCommand.rejects(new Error('Boom!'));
7878
await invoice.generateUri();
7979
expect(nav.goInvoiceQR, 'was not called');
80-
expect(notification.display, 'was called once');
80+
expect(notification.display, 'was called twice');
8181
});
8282
});
8383

@@ -87,4 +87,29 @@ describe('Action Invoice Unit Tests', () => {
8787
expect(clipboard.setString, 'was called with', 'foo');
8888
});
8989
});
90+
91+
describe('checkAmount()', () => {
92+
beforeEach(() => {
93+
store.channels = [
94+
{
95+
chanId: 42,
96+
active: true,
97+
capacity: 100,
98+
localBalance: 10,
99+
remoteBalance: 90,
100+
channelPoint: 'FFFF:1',
101+
},
102+
];
103+
});
104+
105+
it('should show a notification if the amount is too big to receive', () => {
106+
invoice.checkAmount({ satAmount: 91 });
107+
expect(notification.display, 'was called once');
108+
});
109+
110+
it('should not show a notification if the amount is below the max', () => {
111+
invoice.checkAmount({ satAmount: 90 });
112+
expect(notification.display, 'was not called');
113+
});
114+
});
90115
});

0 commit comments

Comments
 (0)