From a7c644bcbdc64a8c0d10edefec8ca35018668f36 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Fri, 27 Jul 2018 07:19:31 +0200 Subject: [PATCH 1/5] Parse pending_open_balance for ChannelBalance grape call --- src/action/wallet.js | 5 +++-- src/store.js | 1 + test/unit/action/wallet.spec.js | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/action/wallet.js b/src/action/wallet.js index e0abdd19b..0a03f763c 100644 --- a/src/action/wallet.js +++ b/src/action/wallet.js @@ -158,8 +158,9 @@ class WalletAction { async getChannelBalance() { try { - const response = await this._grpc.sendCommand('ChannelBalance'); - this._store.channelBalanceSatoshis = parseSat(response.balance); + const r = await this._grpc.sendCommand('ChannelBalance'); + this._store.channelBalanceSatoshis = parseSat(r.balance); + this._store.pendingBalanceSatoshis = parseSat(r.pending_open_balance); } catch (err) { log.error('Getting channel balance failed', err); } diff --git a/src/store.js b/src/store.js index 1a199d520..59f0173f6 100644 --- a/src/store.js +++ b/src/store.js @@ -24,6 +24,7 @@ export class Store { balanceSatoshis: 0, confirmedBalanceSatoshis: 0, unconfirmedBalanceSatoshis: 0, + pendingBalanceSatoshis: 0, channelBalanceSatoshis: 0, pubKey: null, walletAddress: null, diff --git a/test/unit/action/wallet.spec.js b/test/unit/action/wallet.spec.js index 6727b7986..c9851aa64 100644 --- a/test/unit/action/wallet.spec.js +++ b/test/unit/action/wallet.spec.js @@ -292,9 +292,13 @@ describe('Action Wallet Unit Tests', () => { describe('getChannelBalance()', () => { it('should get channel balance', async () => { - grpc.sendCommand.withArgs('ChannelBalance').resolves({ balance: '1' }); + grpc.sendCommand.withArgs('ChannelBalance').resolves({ + balance: '1', + pending_open_balance: '2', + }); await wallet.getChannelBalance(); expect(store.channelBalanceSatoshis, 'to equal', 1); + expect(store.pendingBalanceSatoshis, 'to equal', 2); }); it('should log error on failure', async () => { From 5faec96623673bb8e7f887126a386a0805519d88 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Fri, 27 Jul 2018 07:22:12 +0200 Subject: [PATCH 2/5] Add integration test for store.pendingBalanceSatoshis --- test/integration/action/action-integration.spec.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/integration/action/action-integration.spec.js b/test/integration/action/action-integration.spec.js index 5a04ad794..cc615e7c1 100644 --- a/test/integration/action/action-integration.spec.js +++ b/test/integration/action/action-integration.spec.js @@ -273,6 +273,8 @@ describe('Action Integration Tests', function() { expect(store2.balanceSatoshis, 'to be positive'); expect(store1.channelBalanceSatoshis, 'to be', 0); expect(store2.channelBalanceSatoshis, 'to be', 0); + expect(store1.pendingBalanceSatoshis, 'to be', 0); + expect(store2.pendingBalanceSatoshis, 'to be', 0); }); }); @@ -305,6 +307,14 @@ describe('Action Integration Tests', function() { expect(store1.computedChannels[0].status, 'to be', 'pending-open'); }); + it('should have enough satoshis in channel balance', async () => { + await updateBalances(); + expect(store1.pendingBalanceSatoshis, 'to be positive'); + expect(store2.pendingBalanceSatoshis, 'to be', 0); + expect(store1.channelBalanceSatoshis, 'to be', 0); + expect(store2.channelBalanceSatoshis, 'to be', 0); + }); + it('should list open channel after mining 6 blocks', async () => { await mineAndSync({ blocks: 6 }); while (store1.pendingChannels.length) await nap(100); @@ -315,6 +325,8 @@ describe('Action Integration Tests', function() { it('should have enough satoshis in channel balance', async () => { await updateBalances(); + expect(store1.pendingBalanceSatoshis, 'to be', 0); + expect(store2.pendingBalanceSatoshis, 'to be', 0); expect(store1.channelBalanceSatoshis, 'to be positive'); expect(store2.channelBalanceSatoshis, 'to be', 0); }); From 03fce61584b543d9d389472e20064a23571b43da Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Fri, 27 Jul 2018 07:23:01 +0200 Subject: [PATCH 3/5] Add on-chain balance and pending-channel balances in depositLabel --- src/computed/wallet.js | 7 ++++--- test/unit/computed/wallet.spec.js | 12 +++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/computed/wallet.js b/src/computed/wallet.js index 6303f6d4d..624e800bc 100644 --- a/src/computed/wallet.js +++ b/src/computed/wallet.js @@ -7,9 +7,10 @@ const ComputedWallet = store => { walletAddressUri: computed( () => (store.walletAddress ? `bitcoin:${store.walletAddress}` : '') ), - balanceLabel: computed(() => - toAmountLabel(store.balanceSatoshis, store.settings) - ), + depositLabel: computed(() => { + const { balanceSatoshis, pendingBalanceSatoshis, settings } = store; + return toAmountLabel(balanceSatoshis + pendingBalanceSatoshis, settings); + }), channelBalanceLabel: computed(() => toAmountLabel(store.channelBalanceSatoshis, store.settings) ), diff --git a/test/unit/computed/wallet.spec.js b/test/unit/computed/wallet.spec.js index 24ada1f79..d136b84c3 100644 --- a/test/unit/computed/wallet.spec.js +++ b/test/unit/computed/wallet.spec.js @@ -12,7 +12,7 @@ describe('Computed Wallet Unit Tests', () => { it('should work with initial store', () => { ComputedWallet(store); expect(store.walletAddressUri, 'to equal', ''); - expect(store.balanceLabel, 'to equal', '0'); + expect(store.depositLabel, 'to equal', '0'); expect(store.channelBalanceLabel, 'to equal', '0'); expect(store.unitFiatLabel, 'to equal', 'BTC'); expect(store.unitLabel, 'to equal', 'BTC'); @@ -32,10 +32,11 @@ describe('Computed Wallet Unit Tests', () => { it('should display channel balance in usd', () => { store.settings.displayFiat = true; store.settings.exchangeRate.usd = 0.00014503; - store.balanceSatoshis = 100000000; + store.balanceSatoshis = 50000000; + store.pendingBalanceSatoshis = 50000000; store.channelBalanceSatoshis = 10000; ComputedWallet(store); - expect(store.balanceLabel, 'to match', /6[,.]895[,.]13/); + expect(store.depositLabel, 'to match', /6[,.]895[,.]13/); expect(store.channelBalanceLabel, 'to match', /0[,.]69/); expect(store.unitFiatLabel, 'to equal', '$'); expect(store.unitLabel, 'to equal', null); @@ -43,12 +44,13 @@ describe('Computed Wallet Unit Tests', () => { it('should display channel balance in sat', () => { store.settings.exchangeRate.usd = 0.00014503; - store.balanceSatoshis = 100000001; + store.balanceSatoshis = 50000001; + store.pendingBalanceSatoshis = 50000000; store.channelBalanceSatoshis = 10000; store.settings.unit = 'bit'; ComputedWallet(store); expect( - store.balanceLabel, + store.depositLabel, 'to match', /^1{1}[,.]0{3}[,.]0{3}[,.]0{1}1{1}$/ ); From 89a2c0beec4f2d3f547fd67f8afc4e6f6b255c86 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Fri, 27 Jul 2018 07:23:23 +0200 Subject: [PATCH 4/5] Update home screen label --- src/view/home.js | 10 +++++----- stories/screen.js | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/view/home.js b/src/view/home.js index dec2c02e2..8d97fddfb 100644 --- a/src/view/home.js +++ b/src/view/home.js @@ -45,7 +45,7 @@ const HomeView = ({ transaction, nav, }) => { - const { balanceLabel, channelBalanceLabel, unitLabel } = store; + const { depositLabel, channelBalanceLabel, unitLabel } = store; return ( nav.goDeposit()} /> wallet.toggleDisplayFiat()} @@ -99,7 +99,7 @@ const balanceStyles = StyleSheet.create({ }); const BalanceDisplay = ({ - balanceLabel, + depositLabel, channelBalanceLabel, unitLabel, toggleDisplayFiat, @@ -111,13 +111,13 @@ const BalanceDisplay = ({ {unitLabel} Pending Deposit - {balanceLabel} + {depositLabel} ); BalanceDisplay.propTypes = { - balanceLabel: PropTypes.string.isRequired, + depositLabel: PropTypes.string.isRequired, channelBalanceLabel: PropTypes.string.isRequired, unitLabel: PropTypes.string, toggleDisplayFiat: PropTypes.func.isRequired, diff --git a/stories/screen.js b/stories/screen.js index 691faf99a..b7eaf5151 100644 --- a/stories/screen.js +++ b/stories/screen.js @@ -158,6 +158,7 @@ storiesOf('Screens', module) // set some dummy data store.walletAddress = 'ra2XT898gWTp9q2DwMgtwMJsUEh3oMeS4K'; store.balanceSatoshis = 798765432; +store.pendingBalanceSatoshis = 100000000; store.channelBalanceSatoshis = 59876000; store.settings.exchangeRate.usd = 0.00016341; store.settings.exchangeRate.eur = 0.0001896; From 21475d7881e6372df96b9aa2b2135aa885ab37b6 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Mon, 30 Jul 2018 09:21:13 +0200 Subject: [PATCH 5/5] Fix typo in tests --- test/integration/action/action-integration.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/action/action-integration.spec.js b/test/integration/action/action-integration.spec.js index cc615e7c1..0d306b558 100644 --- a/test/integration/action/action-integration.spec.js +++ b/test/integration/action/action-integration.spec.js @@ -307,7 +307,7 @@ describe('Action Integration Tests', function() { expect(store1.computedChannels[0].status, 'to be', 'pending-open'); }); - it('should have enough satoshis in channel balance', async () => { + it('should have enough satoshis in pending balance', async () => { await updateBalances(); expect(store1.pendingBalanceSatoshis, 'to be positive'); expect(store2.pendingBalanceSatoshis, 'to be', 0);