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

Commit 4c58679

Browse files
Include limbo balance in Home screen balance.
1 parent 1cc945e commit 4c58679

File tree

5 files changed

+50
-7
lines changed

5 files changed

+50
-7
lines changed

src/action/wallet.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ class WalletAction {
144144
* @return {Promise<undefined>}
145145
*/
146146
async update() {
147-
await Promise.all([this.getBalance(), this.getChannelBalance()]);
147+
await Promise.all([
148+
this.getBalance(),
149+
this.getChannelBalance(),
150+
this.getLimboBalance(),
151+
]);
148152
}
149153

150154
/**
@@ -449,6 +453,20 @@ class WalletAction {
449453
}
450454
}
451455

456+
/**
457+
* Fetch the limbo balance using the lnd grpc api and set the
458+
* corresponding value on the global store.
459+
* @return {Promise<undefined>}
460+
*/
461+
async getLimboBalance() {
462+
try {
463+
const r = await this._grpc.sendCommand('PendingChannels');
464+
this._store.limboBalanceSatoshis = r.totalLimboBalance;
465+
} catch (err) {
466+
log.error('Getting limbo balance failed', err);
467+
}
468+
}
469+
452470
/**
453471
* Ensure that the wallet address is non-null before navigating to the
454472
* NewAddress view during onboarding.

src/computed/wallet.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@ const ComputedWallet = store => {
2121
balanceSatoshis,
2222
pendingBalanceSatoshis,
2323
channelBalanceSatoshis,
24+
limboBalanceSatoshis,
2425
} = store;
25-
return balanceSatoshis + pendingBalanceSatoshis + channelBalanceSatoshis;
26+
return (
27+
balanceSatoshis +
28+
pendingBalanceSatoshis +
29+
channelBalanceSatoshis +
30+
limboBalanceSatoshis
31+
);
2632
},
2733
get totalBalanceLabel() {
2834
return toAmountLabel(store.totalBalanceSatoshis, store.settings);

src/store.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class Store {
3434
unconfirmedBalanceSatoshis: 0,
3535
pendingBalanceSatoshis: 0,
3636
channelBalanceSatoshis: 0,
37+
limboBalanceSatoshis: 0,
3738
pubKey: null,
3839
walletAddress: null,
3940
displayCopied: false,

test/unit/action/wallet.spec.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ describe('Action Wallet Unit Tests', () => {
138138
it('should refresh wallet balances', async () => {
139139
sandbox.stub(wallet, 'pollExchangeRate');
140140
await wallet.update();
141-
expect(grpc.sendCommand, 'was called twice');
141+
expect(grpc.sendCommand, 'was called thrice');
142142
expect(wallet.pollExchangeRate, 'was not called');
143143
});
144144
});
@@ -571,6 +571,22 @@ describe('Action Wallet Unit Tests', () => {
571571
});
572572
});
573573

574+
describe('getLimboBalance()', () => {
575+
it('should get limbo balance', async () => {
576+
grpc.sendCommand.withArgs('PendingChannels').resolves({
577+
totalLimboBalance: 1,
578+
});
579+
await wallet.getLimboBalance();
580+
expect(store.limboBalanceSatoshis, 'to equal', 1);
581+
});
582+
583+
it('should log error on failure', async () => {
584+
grpc.sendCommand.rejects();
585+
await wallet.getLimboBalance();
586+
expect(logger.error, 'was called once');
587+
});
588+
});
589+
574590
describe('getNewAddress()', () => {
575591
it('should get new address', async () => {
576592
grpc.sendCommand.withArgs('NewAddress').resolves({

test/unit/computed/wallet.spec.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ describe('Computed Wallet Unit Tests', () => {
3737
store.balanceSatoshis = 50000000;
3838
store.pendingBalanceSatoshis = 50000000;
3939
store.channelBalanceSatoshis = 10000;
40+
store.limboBalanceSatoshis = 100;
4041
ComputedWallet(store);
41-
expect(store.totalBalanceSatoshis, 'to equal', 100010000);
42-
expect(store.totalBalanceLabel, 'to match', /6[,.]895[,.]81/);
42+
expect(store.totalBalanceSatoshis, 'to equal', 100010100);
43+
expect(store.totalBalanceLabel, 'to match', /6[,.]895[,.]82/);
4344
expect(store.unitFiatLabel, 'to equal', '$');
4445
expect(store.unitLabel, 'to equal', null);
4546
expect(store.channelPercentageLabel, 'to equal', '50% on Lightning');
@@ -51,10 +52,11 @@ describe('Computed Wallet Unit Tests', () => {
5152
store.balanceSatoshis = 50000001;
5253
store.pendingBalanceSatoshis = 50000000;
5354
store.channelBalanceSatoshis = 10000;
55+
store.limboBalanceSatoshis = 100;
5456
store.settings.unit = 'bit';
5557
ComputedWallet(store);
56-
expect(store.totalBalanceSatoshis, 'to equal', 100010001);
57-
expect(store.totalBalanceLabel, 'to match', /1[,.]000[,.]100[,.]01/);
58+
expect(store.totalBalanceSatoshis, 'to equal', 100010101);
59+
expect(store.totalBalanceLabel, 'to match', /1[,.]000[,.]101[,.]01/);
5860
expect(store.unitFiatLabel, 'to equal', 'bits');
5961
expect(store.unitLabel, 'to equal', 'bits');
6062
});

0 commit comments

Comments
 (0)