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
5 changes: 3 additions & 2 deletions src/action/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 4 additions & 3 deletions src/computed/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
),
Expand Down
1 change: 1 addition & 0 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class Store {
balanceSatoshis: 0,
confirmedBalanceSatoshis: 0,
unconfirmedBalanceSatoshis: 0,
pendingBalanceSatoshis: 0,
channelBalanceSatoshis: 0,
pubKey: null,
walletAddress: null,
Expand Down
10 changes: 5 additions & 5 deletions src/view/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const HomeView = ({
transaction,
nav,
}) => {
const { balanceLabel, channelBalanceLabel, unitLabel } = store;
const { depositLabel, channelBalanceLabel, unitLabel } = store;
return (
<Background image="purple-gradient-bg">
<HomeHeader
Expand All @@ -56,7 +56,7 @@ const HomeView = ({
<QrCodeSeparator goDeposit={() => nav.goDeposit()} />
<MainContent style={styles.content}>
<BalanceDisplay
balanceLabel={balanceLabel}
depositLabel={depositLabel}
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: depositLabel --> pendingDepositLabel?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there were multiple depositLabels. But short names are good names :)

channelBalanceLabel={channelBalanceLabel}
unitLabel={unitLabel}
toggleDisplayFiat={() => wallet.toggleDisplayFiat()}
Expand Down Expand Up @@ -99,7 +99,7 @@ const balanceStyles = StyleSheet.create({
});

const BalanceDisplay = ({
balanceLabel,
depositLabel,
channelBalanceLabel,
unitLabel,
toggleDisplayFiat,
Expand All @@ -111,13 +111,13 @@ const BalanceDisplay = ({
<BalanceLabelUnit>{unitLabel}</BalanceLabelUnit>
</BalanceLabel>
<H4Text style={balanceStyles.smallLabel}>Pending Deposit</H4Text>
<SmallBalanceLabel unit={unitLabel}>{balanceLabel}</SmallBalanceLabel>
<SmallBalanceLabel unit={unitLabel}>{depositLabel}</SmallBalanceLabel>
</Button>
</View>
);

BalanceDisplay.propTypes = {
balanceLabel: PropTypes.string.isRequired,
depositLabel: PropTypes.string.isRequired,
channelBalanceLabel: PropTypes.string.isRequired,
unitLabel: PropTypes.string,
toggleDisplayFiat: PropTypes.func.isRequired,
Expand Down
1 change: 1 addition & 0 deletions stories/screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions test/integration/action/action-integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

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

it('should have enough satoshis in pending 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);
Expand All @@ -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);
});
Expand Down
6 changes: 5 additions & 1 deletion test/unit/action/wallet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
12 changes: 7 additions & 5 deletions test/unit/computed/wallet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -32,23 +32,25 @@ 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);
});

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}$/
);
Expand Down