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

Commit 0f8bdab

Browse files
authored
Merge pull request #474 from lightninglabs/fix-pending-deposit
Fix pending deposit
2 parents de3ac50 + 21475d7 commit 0f8bdab

File tree

8 files changed

+38
-16
lines changed

8 files changed

+38
-16
lines changed

src/action/wallet.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ class WalletAction {
158158

159159
async getChannelBalance() {
160160
try {
161-
const response = await this._grpc.sendCommand('ChannelBalance');
162-
this._store.channelBalanceSatoshis = parseSat(response.balance);
161+
const r = await this._grpc.sendCommand('ChannelBalance');
162+
this._store.channelBalanceSatoshis = parseSat(r.balance);
163+
this._store.pendingBalanceSatoshis = parseSat(r.pending_open_balance);
163164
} catch (err) {
164165
log.error('Getting channel balance failed', err);
165166
}

src/computed/wallet.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ const ComputedWallet = store => {
77
walletAddressUri: computed(
88
() => (store.walletAddress ? `bitcoin:${store.walletAddress}` : '')
99
),
10-
balanceLabel: computed(() =>
11-
toAmountLabel(store.balanceSatoshis, store.settings)
12-
),
10+
depositLabel: computed(() => {
11+
const { balanceSatoshis, pendingBalanceSatoshis, settings } = store;
12+
return toAmountLabel(balanceSatoshis + pendingBalanceSatoshis, settings);
13+
}),
1314
channelBalanceLabel: computed(() =>
1415
toAmountLabel(store.channelBalanceSatoshis, store.settings)
1516
),

src/store.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class Store {
2424
balanceSatoshis: 0,
2525
confirmedBalanceSatoshis: 0,
2626
unconfirmedBalanceSatoshis: 0,
27+
pendingBalanceSatoshis: 0,
2728
channelBalanceSatoshis: 0,
2829
pubKey: null,
2930
walletAddress: null,

src/view/home.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const HomeView = ({
4545
transaction,
4646
nav,
4747
}) => {
48-
const { balanceLabel, channelBalanceLabel, unitLabel } = store;
48+
const { depositLabel, channelBalanceLabel, unitLabel } = store;
4949
return (
5050
<Background image="purple-gradient-bg">
5151
<HomeHeader
@@ -56,7 +56,7 @@ const HomeView = ({
5656
<QrCodeSeparator goDeposit={() => nav.goDeposit()} />
5757
<MainContent style={styles.content}>
5858
<BalanceDisplay
59-
balanceLabel={balanceLabel}
59+
depositLabel={depositLabel}
6060
channelBalanceLabel={channelBalanceLabel}
6161
unitLabel={unitLabel}
6262
toggleDisplayFiat={() => wallet.toggleDisplayFiat()}
@@ -99,7 +99,7 @@ const balanceStyles = StyleSheet.create({
9999
});
100100

101101
const BalanceDisplay = ({
102-
balanceLabel,
102+
depositLabel,
103103
channelBalanceLabel,
104104
unitLabel,
105105
toggleDisplayFiat,
@@ -111,13 +111,13 @@ const BalanceDisplay = ({
111111
<BalanceLabelUnit>{unitLabel}</BalanceLabelUnit>
112112
</BalanceLabel>
113113
<H4Text style={balanceStyles.smallLabel}>Pending Deposit</H4Text>
114-
<SmallBalanceLabel unit={unitLabel}>{balanceLabel}</SmallBalanceLabel>
114+
<SmallBalanceLabel unit={unitLabel}>{depositLabel}</SmallBalanceLabel>
115115
</Button>
116116
</View>
117117
);
118118

119119
BalanceDisplay.propTypes = {
120-
balanceLabel: PropTypes.string.isRequired,
120+
depositLabel: PropTypes.string.isRequired,
121121
channelBalanceLabel: PropTypes.string.isRequired,
122122
unitLabel: PropTypes.string,
123123
toggleDisplayFiat: PropTypes.func.isRequired,

stories/screen.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ storiesOf('Screens', module)
158158
// set some dummy data
159159
store.walletAddress = 'ra2XT898gWTp9q2DwMgtwMJsUEh3oMeS4K';
160160
store.balanceSatoshis = 798765432;
161+
store.pendingBalanceSatoshis = 100000000;
161162
store.channelBalanceSatoshis = 59876000;
162163
store.settings.exchangeRate.usd = 0.00016341;
163164
store.settings.exchangeRate.eur = 0.0001896;

test/integration/action/action-integration.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ describe('Action Integration Tests', function() {
273273
expect(store2.balanceSatoshis, 'to be positive');
274274
expect(store1.channelBalanceSatoshis, 'to be', 0);
275275
expect(store2.channelBalanceSatoshis, 'to be', 0);
276+
expect(store1.pendingBalanceSatoshis, 'to be', 0);
277+
expect(store2.pendingBalanceSatoshis, 'to be', 0);
276278
});
277279
});
278280

@@ -305,6 +307,14 @@ describe('Action Integration Tests', function() {
305307
expect(store1.computedChannels[0].status, 'to be', 'pending-open');
306308
});
307309

310+
it('should have enough satoshis in pending balance', async () => {
311+
await updateBalances();
312+
expect(store1.pendingBalanceSatoshis, 'to be positive');
313+
expect(store2.pendingBalanceSatoshis, 'to be', 0);
314+
expect(store1.channelBalanceSatoshis, 'to be', 0);
315+
expect(store2.channelBalanceSatoshis, 'to be', 0);
316+
});
317+
308318
it('should list open channel after mining 6 blocks', async () => {
309319
await mineAndSync({ blocks: 6 });
310320
while (store1.pendingChannels.length) await nap(100);
@@ -315,6 +325,8 @@ describe('Action Integration Tests', function() {
315325

316326
it('should have enough satoshis in channel balance', async () => {
317327
await updateBalances();
328+
expect(store1.pendingBalanceSatoshis, 'to be', 0);
329+
expect(store2.pendingBalanceSatoshis, 'to be', 0);
318330
expect(store1.channelBalanceSatoshis, 'to be positive');
319331
expect(store2.channelBalanceSatoshis, 'to be', 0);
320332
});

test/unit/action/wallet.spec.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,13 @@ describe('Action Wallet Unit Tests', () => {
292292

293293
describe('getChannelBalance()', () => {
294294
it('should get channel balance', async () => {
295-
grpc.sendCommand.withArgs('ChannelBalance').resolves({ balance: '1' });
295+
grpc.sendCommand.withArgs('ChannelBalance').resolves({
296+
balance: '1',
297+
pending_open_balance: '2',
298+
});
296299
await wallet.getChannelBalance();
297300
expect(store.channelBalanceSatoshis, 'to equal', 1);
301+
expect(store.pendingBalanceSatoshis, 'to equal', 2);
298302
});
299303

300304
it('should log error on failure', async () => {

test/unit/computed/wallet.spec.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('Computed Wallet Unit Tests', () => {
1212
it('should work with initial store', () => {
1313
ComputedWallet(store);
1414
expect(store.walletAddressUri, 'to equal', '');
15-
expect(store.balanceLabel, 'to equal', '0');
15+
expect(store.depositLabel, 'to equal', '0');
1616
expect(store.channelBalanceLabel, 'to equal', '0');
1717
expect(store.unitFiatLabel, 'to equal', 'BTC');
1818
expect(store.unitLabel, 'to equal', 'BTC');
@@ -32,23 +32,25 @@ describe('Computed Wallet Unit Tests', () => {
3232
it('should display channel balance in usd', () => {
3333
store.settings.displayFiat = true;
3434
store.settings.exchangeRate.usd = 0.00014503;
35-
store.balanceSatoshis = 100000000;
35+
store.balanceSatoshis = 50000000;
36+
store.pendingBalanceSatoshis = 50000000;
3637
store.channelBalanceSatoshis = 10000;
3738
ComputedWallet(store);
38-
expect(store.balanceLabel, 'to match', /6[,.]895[,.]13/);
39+
expect(store.depositLabel, 'to match', /6[,.]895[,.]13/);
3940
expect(store.channelBalanceLabel, 'to match', /0[,.]69/);
4041
expect(store.unitFiatLabel, 'to equal', '$');
4142
expect(store.unitLabel, 'to equal', null);
4243
});
4344

4445
it('should display channel balance in sat', () => {
4546
store.settings.exchangeRate.usd = 0.00014503;
46-
store.balanceSatoshis = 100000001;
47+
store.balanceSatoshis = 50000001;
48+
store.pendingBalanceSatoshis = 50000000;
4749
store.channelBalanceSatoshis = 10000;
4850
store.settings.unit = 'bit';
4951
ComputedWallet(store);
5052
expect(
51-
store.balanceLabel,
53+
store.depositLabel,
5254
'to match',
5355
/^1{1}[,.]0{3}[,.]0{3}[,.]0{1}1{1}$/
5456
);

0 commit comments

Comments
 (0)