Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/action/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ChannelAction {

/**
* List the pending channels by calling the respective grpc api and updating
* the pendingChannels array in the global store.
* the pendingChannels array and limbo balance in the global store.
* @return {Promise<undefined>}
*/
async getPendingChannels() {
Expand Down Expand Up @@ -168,6 +168,7 @@ class ChannelAction {
status: 'waiting-close',
}));
this._store.pendingChannels = [].concat(pocs, pccs, pfccs, wccs);
this._store.limboBalanceSatoshis = response.totalLimboBalance;
} catch (err) {
log.error('Listing pending channels failed', err);
}
Expand Down
8 changes: 7 additions & 1 deletion src/computed/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ const ComputedWallet = store => {
balanceSatoshis,
pendingBalanceSatoshis,
channelBalanceSatoshis,
limboBalanceSatoshis,
} = store;
return balanceSatoshis + pendingBalanceSatoshis + channelBalanceSatoshis;
return (
balanceSatoshis +
pendingBalanceSatoshis +
channelBalanceSatoshis +
limboBalanceSatoshis
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although store.limboBalanceSatoshis is set in channel actions I would also compute this here 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm confused what this means. What is being computed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saying it makes sense to use the ComputedWallet module here. So no changes needed :)

},
get totalBalanceLabel() {
return toAmountLabel(store.totalBalanceSatoshis, store.settings);
Expand Down
1 change: 1 addition & 0 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class Store {
unconfirmedBalanceSatoshis: 0,
pendingBalanceSatoshis: 0,
channelBalanceSatoshis: 0,
limboBalanceSatoshis: 0,
pubKey: null,
walletAddress: null,
displayCopied: false,
Expand Down
2 changes: 2 additions & 0 deletions test/unit/action/channel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,15 @@ describe('Action Channels Unit Tests', () => {
pendingClosingChannels: [{ channel: { ...pendingChannel } }],
pendingForceClosingChannels: [{ channel: { ...pendingChannel } }],
waitingCloseChannels: [{ channel: { ...pendingChannel } }],
totalLimboBalance: 1,
});
await channel.getPendingChannels();
expect(store.pendingChannels.length, 'to equal', 4);
expect(store.pendingChannels[0], 'to satisfy', {
remotePubkey: 'some-key',
fundingTxId: 'FFFF',
});
expect(store.limboBalanceSatoshis, 'to equal', 1);
});

it('should log error on failure', async () => {
Expand Down
10 changes: 6 additions & 4 deletions test/unit/computed/wallet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ describe('Computed Wallet Unit Tests', () => {
store.balanceSatoshis = 50000000;
store.pendingBalanceSatoshis = 50000000;
store.channelBalanceSatoshis = 10000;
store.limboBalanceSatoshis = 100;
ComputedWallet(store);
expect(store.totalBalanceSatoshis, 'to equal', 100010000);
expect(store.totalBalanceLabel, 'to match', /6[,.]895[,.]81/);
expect(store.totalBalanceSatoshis, 'to equal', 100010100);
expect(store.totalBalanceLabel, 'to match', /6[,.]895[,.]82/);
expect(store.unitFiatLabel, 'to equal', '$');
expect(store.unitLabel, 'to equal', null);
expect(store.channelPercentageLabel, 'to equal', '50% on Lightning');
Expand All @@ -51,10 +52,11 @@ describe('Computed Wallet Unit Tests', () => {
store.balanceSatoshis = 50000001;
store.pendingBalanceSatoshis = 50000000;
store.channelBalanceSatoshis = 10000;
store.limboBalanceSatoshis = 100;
store.settings.unit = 'bit';
ComputedWallet(store);
expect(store.totalBalanceSatoshis, 'to equal', 100010001);
expect(store.totalBalanceLabel, 'to match', /1[,.]000[,.]100[,.]01/);
expect(store.totalBalanceSatoshis, 'to equal', 100010101);
expect(store.totalBalanceLabel, 'to match', /1[,.]000[,.]101[,.]01/);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test 👍

expect(store.unitFiatLabel, 'to equal', 'bits');
expect(store.unitLabel, 'to equal', 'bits');
});
Expand Down