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

Commit cda5850

Browse files
committed
Merge branch 'refs/heads/unified-balance' into release/desktop
2 parents f19dc58 + 63a479d commit cda5850

File tree

15 files changed

+162
-149
lines changed

15 files changed

+162
-149
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lightning-app",
3-
"version": "0.4.0-alpha",
3+
"version": "0.4.1-alpha",
44
"description": "Lightning Wallet Application",
55
"author": "Lightning Labs, Inc",
66
"homepage": "./",

src/action/channel.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* call the corresponding GRPC apis for channel management.
44
*/
55

6-
import { toSatoshis } from '../helper';
6+
import { toSatoshis, poll } from '../helper';
77
import * as log from './log';
88

99
class ChannelAction {
@@ -58,7 +58,6 @@ class ChannelAction {
5858
*/
5959
init() {
6060
this._nav.goChannels();
61-
this.update();
6261
}
6362

6463
/**
@@ -70,7 +69,6 @@ class ChannelAction {
7069
select({ item }) {
7170
this._store.selectedChannel = item;
7271
this._nav.goChannelDetail();
73-
this.update();
7472
}
7573

7674
/**
@@ -87,6 +85,14 @@ class ChannelAction {
8785
]);
8886
}
8987

88+
/**
89+
* Poll the channels in the background since there is no streaming grpc api
90+
* @return {Promise<undefined>}
91+
*/
92+
async pollChannels() {
93+
await poll(() => this.update());
94+
}
95+
9096
//
9197
// Generic channel actions
9298
//

src/action/index-mobile.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ when(
100100
wallet.getNewAddress();
101101
wallet.pollBalances();
102102
wallet.pollExchangeRate();
103-
channel.update();
103+
channel.pollChannels();
104104
transaction.update();
105105
info.pollInfo();
106106
}
@@ -123,9 +123,9 @@ setTimeout(
123123
() => (store.walletAddress = 'ra2XT898gWTp9q2DwMgtwMJsUEh3oMeS4K'),
124124
3000
125125
);
126-
store.balanceSatoshis = 798765432;
127-
store.pendingBalanceSatoshis = 100000000;
128-
store.channelBalanceSatoshis = 59876000;
126+
store.balanceSatoshis = 76543;
127+
store.pendingBalanceSatoshis = 800000;
128+
store.channelBalanceSatoshis = 598760;
129129
store.settings.exchangeRate.usd = 0.00016341;
130130
store.settings.exchangeRate.eur = 0.0001896;
131131
store.settings.exchangeRate.gbp = 0.00021405;

src/action/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ when(
9191
wallet.getNewAddress();
9292
wallet.pollBalances();
9393
wallet.pollExchangeRate();
94-
channel.update();
94+
channel.pollChannels();
9595
transaction.update();
9696
transaction.subscribeTransactions();
9797
transaction.subscribeInvoices();

src/action/transaction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class TransactionAction {
6363
amount: transaction.amount,
6464
fee: transaction.totalFees,
6565
confirmations: transaction.numConfirmations,
66-
status: transaction.numConfirmations < 1 ? 'unconfirmed' : 'confirmed',
66+
status: transaction.numConfirmations < 3 ? 'unconfirmed' : 'confirmed',
6767
date: parseDate(transaction.timeStamp),
6868
}));
6969
} catch (err) {

src/computed/channel.js

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,59 @@ const ComputedChannel = store => {
3535
});
3636
return all;
3737
},
38-
get channelBalanceOpenLabel() {
39-
const { channels, settings } = store;
40-
const sum = (channels || [])
38+
get channelBalanceOpenSatoshis() {
39+
return (store.channels || [])
4140
.filter(c => c.active)
4241
.map(c => Number(c.localBalance))
4342
.reduce((a, b) => a + b, 0);
44-
return toAmountLabel(sum, settings);
4543
},
46-
get channelBalanceInactiveLabel() {
47-
const { channels, settings } = store;
48-
const sum = (channels || [])
44+
get channelBalanceOpenLabel() {
45+
const { channelBalanceOpenSatoshis, settings } = store;
46+
return toAmountLabel(channelBalanceOpenSatoshis, settings);
47+
},
48+
get channelBalanceInactiveSatoshis() {
49+
return (store.channels || [])
4950
.filter(c => !c.active)
5051
.map(c => Number(c.localBalance))
5152
.reduce((a, b) => a + b, 0);
52-
return toAmountLabel(sum, settings);
5353
},
54-
get channelBalancePendingLabel() {
55-
const { pendingChannels, settings } = store;
56-
const sum = (pendingChannels || [])
54+
get channelBalanceInactiveLabel() {
55+
const { channelBalanceInactiveSatoshis, settings } = store;
56+
return toAmountLabel(channelBalanceInactiveSatoshis, settings);
57+
},
58+
get channelBalancePendingSatoshis() {
59+
return (store.pendingChannels || [])
5760
.filter(c => c.status.includes('open'))
5861
.map(c => Number(c.localBalance))
5962
.reduce((a, b) => a + b, 0);
60-
return toAmountLabel(sum, settings);
6163
},
62-
get channelBalanceClosingLabel() {
63-
const { pendingChannels, settings } = store;
64-
const sum = (pendingChannels || [])
64+
get channelBalancePendingLabel() {
65+
const { channelBalancePendingSatoshis, settings } = store;
66+
return toAmountLabel(channelBalancePendingSatoshis, settings);
67+
},
68+
get channelBalanceClosingSatoshis() {
69+
return (store.pendingChannels || [])
6570
.filter(c => !c.status.includes('open'))
6671
.map(c => Number(c.localBalance))
6772
.reduce((a, b) => a + b, 0);
68-
return toAmountLabel(sum, settings);
6973
},
70-
get showChannelAlert() {
71-
return (store.channels || []).length === 0;
74+
get channelBalanceClosingLabel() {
75+
const { channelBalanceClosingSatoshis, settings } = store;
76+
return toAmountLabel(channelBalanceClosingSatoshis, settings);
77+
},
78+
get channelStatus() {
79+
const {
80+
channelBalanceOpenSatoshis: opened,
81+
channelBalanceInactiveSatoshis: inactive,
82+
channelBalancePendingSatoshis: pending,
83+
} = store;
84+
return opened
85+
? 'success'
86+
: inactive
87+
? 'inactive'
88+
: pending
89+
? 'info'
90+
: 'error';
7291
},
7392
});
7493
};

src/computed/wallet.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ const ComputedWallet = store => {
1616
get walletAddressUri() {
1717
return store.walletAddress ? `bitcoin:${store.walletAddress}` : '';
1818
},
19-
get depositLabel() {
20-
const { balanceSatoshis, pendingBalanceSatoshis, settings } = store;
21-
return toAmountLabel(balanceSatoshis + pendingBalanceSatoshis, settings);
19+
get totalBalanceSatoshis() {
20+
const {
21+
balanceSatoshis,
22+
pendingBalanceSatoshis,
23+
channelBalanceSatoshis,
24+
} = store;
25+
return balanceSatoshis + pendingBalanceSatoshis + channelBalanceSatoshis;
2226
},
23-
get channelBalanceLabel() {
24-
return toAmountLabel(store.channelBalanceSatoshis, store.settings);
27+
get totalBalanceLabel() {
28+
return toAmountLabel(store.totalBalanceSatoshis, store.settings);
2529
},
2630
get unitFiatLabel() {
2731
const { displayFiat, unit, fiat } = store.settings;
@@ -31,6 +35,15 @@ const ComputedWallet = store => {
3135
const { settings } = store;
3236
return !settings.displayFiat ? UNITS[settings.unit].display : null;
3337
},
38+
get channelPercentageLabel() {
39+
const {
40+
channelBalanceSatoshis: opened,
41+
pendingBalanceSatoshis: pending,
42+
totalBalanceSatoshis: total,
43+
} = store;
44+
const percent = total ? (opened + pending) / total * 100 : 0;
45+
return `${Math.round(percent)}% on Lightning`;
46+
},
3447
get newPasswordCopy() {
3548
const { newPassword } = store.wallet;
3649
return getNewPasswordCopy({ newPassword });

0 commit comments

Comments
 (0)