Unverified Commit 2ba21fda authored by Tankred Hase's avatar Tankred Hase Committed by GitHub

Merge pull request #1082 from lightninglabs/dev/commit-fee

Dev/commit fee
parents 9946311f 6e15b94c
......@@ -111,6 +111,7 @@ class ChannelAction {
capacity: channel.capacity,
localBalance: channel.localBalance,
remoteBalance: channel.remoteBalance,
commitFee: channel.commitFee,
channelPoint: channel.channelPoint,
fundingTxId: this._parseChannelPoint(channel.channelPoint)
.fundingTxidStr,
......@@ -136,6 +137,7 @@ class ChannelAction {
capacity: channel.capacity,
localBalance: channel.localBalance,
remoteBalance: channel.remoteBalance,
commitFee: channel.commitFee || 0,
channelPoint: channel.channelPoint,
fundingTxId: this._parseChannelPoint(channel.channelPoint)
.fundingTxidStr,
......@@ -144,8 +146,6 @@ class ChannelAction {
...mapPendingAttributes(poc.channel),
confirmationHeight: poc.confirmationHeight,
blocksTillOpen: poc.blocksTillOpen,
commitFee: poc.commitFee,
commitWeight: poc.commitWeight,
feePerKw: poc.feePerKw,
status: 'pending-open',
}));
......
......@@ -38,7 +38,7 @@ const ComputedChannel = store => {
get channelBalanceOpenSatoshis() {
return (store.channels || [])
.filter(c => c.active)
.map(c => c.localBalance)
.map(c => c.localBalance + c.commitFee)
.reduce((a, b) => a + b, 0);
},
get channelBalanceOpenLabel() {
......@@ -48,7 +48,7 @@ const ComputedChannel = store => {
get channelBalanceInactiveSatoshis() {
return (store.channels || [])
.filter(c => !c.active)
.map(c => c.localBalance)
.map(c => c.localBalance + c.commitFee)
.reduce((a, b) => a + b, 0);
},
get channelBalanceInactiveLabel() {
......@@ -58,7 +58,7 @@ const ComputedChannel = store => {
get channelBalancePendingSatoshis() {
return (store.pendingChannels || [])
.filter(c => c.status.includes('open'))
.map(c => c.localBalance)
.map(c => c.localBalance + c.commitFee)
.reduce((a, b) => a + b, 0);
},
get channelBalancePendingLabel() {
......@@ -68,7 +68,7 @@ const ComputedChannel = store => {
get channelBalanceClosingSatoshis() {
return (store.pendingChannels || [])
.filter(c => !c.status.includes('open'))
.map(c => c.localBalance)
.map(c => c.localBalance + c.commitFee)
.reduce((a, b) => a + b, 0);
},
get channelBalanceClosingLabel() {
......@@ -78,7 +78,7 @@ const ComputedChannel = store => {
get channelBalanceForceClosingSatoshis() {
return (store.pendingChannels || [])
.filter(c => c.status === 'pending-force-closing')
.map(c => c.localBalance)
.map(c => c.localBalance + c.commitFee)
.reduce((a, b) => a + b, 0);
},
get channelBalanceForceClosingLabel() {
......
......@@ -21,15 +21,17 @@ const ComputedWallet = store => {
},
get totalBalanceSatoshis() {
const {
balanceSatoshis,
pendingBalanceSatoshis,
channelBalanceSatoshis,
balanceSatoshis: onChainBalanceSatoshis,
channelBalancePendingSatoshis,
channelBalanceOpenSatoshis,
channelBalanceInactiveSatoshis,
channelBalanceForceClosingSatoshis,
} = store;
return (
balanceSatoshis +
pendingBalanceSatoshis +
channelBalanceSatoshis +
onChainBalanceSatoshis +
channelBalancePendingSatoshis +
channelBalanceOpenSatoshis +
channelBalanceInactiveSatoshis +
channelBalanceForceClosingSatoshis
);
},
......
......@@ -101,6 +101,7 @@ describe('Action Channels Unit Tests', () => {
capacity: 100,
localBalance: 10,
remoteBalance: 90,
commitFee: 15,
channelPoint: 'FFFF:1',
},
{
......@@ -109,6 +110,7 @@ describe('Action Channels Unit Tests', () => {
capacity: 102,
localBalance: 11,
remoteBalance: 91,
commitFee: 16,
channelPoint: 'FFFF:2',
},
],
......@@ -118,11 +120,13 @@ describe('Action Channels Unit Tests', () => {
id: 42,
fundingTxId: 'FFFF',
status: 'open',
commitFee: 15,
});
expect(store.channels[1], 'to satisfy', {
id: 43,
fundingTxId: 'FFFF',
status: 'open',
commitFee: 16,
});
});
......@@ -139,6 +143,7 @@ describe('Action Channels Unit Tests', () => {
capacity: 100,
localBalance: 10,
remoteBalance: 90,
commitFee: 15,
channelPoint: 'FFFF:1',
};
......@@ -160,6 +165,7 @@ describe('Action Channels Unit Tests', () => {
expect(store.pendingChannels[0], 'to satisfy', {
remotePubkey: 'some-key',
fundingTxId: 'FFFF',
commitFee: 15,
});
expect(store.pendingChannels[2], 'to satisfy', {
timeTilAvailable: '3 days and 5 hours',
......
......@@ -14,6 +14,7 @@ describe('Computed Channels Unit Tests', () => {
capacity: 2005000,
localBalance: 1990000,
remoteBalance: 10000,
commitFee: 500,
channelPoint: 'some-channel-point',
active: true,
status: 'open',
......@@ -24,6 +25,7 @@ describe('Computed Channels Unit Tests', () => {
capacity: 2005000,
localBalance: 1990000,
remoteBalance: 10000,
commitFee: 400,
channelPoint: 'some-channel-point',
active: false,
status: 'open',
......@@ -34,6 +36,7 @@ describe('Computed Channels Unit Tests', () => {
capacity: 1005000,
localBalance: 600000,
remoteBalance: 400000,
commitFee: 300,
channelPoint: 'some-channel-point',
status: 'pending-open',
});
......@@ -43,6 +46,7 @@ describe('Computed Channels Unit Tests', () => {
capacity: 805000,
localBalance: 500000,
remoteBalance: 300000,
commitFee: 200,
channelPoint: 'some-channel-point',
status: 'pending-closing',
});
......@@ -52,6 +56,7 @@ describe('Computed Channels Unit Tests', () => {
capacity: 705000,
localBalance: 400000,
remoteBalance: 300000,
commitFee: 100,
channelPoint: 'some-channel-point',
status: 'pending-force-closing',
});
......@@ -94,11 +99,15 @@ describe('Computed Channels Unit Tests', () => {
expect(pendingCloseCh.statusLabel, 'to equal', 'Pending Closing');
expect(pendingCloseCh.statusType, 'to equal', 'error');
expect(store.channelBalanceOpenLabel, 'to match', /0[,.]0199/);
expect(store.channelBalanceInactiveLabel, 'to match', /0[,.]0199/);
expect(store.channelBalancePendingLabel, 'to match', /0[,.]006/);
expect(store.channelBalanceClosingLabel, 'to match', /0[,.]009/);
expect(store.channelBalanceForceClosingLabel, 'to match', /0[,.]004/);
expect(store.channelBalanceOpenLabel, 'to match', /^0[,.]019905$/);
expect(store.channelBalanceInactiveLabel, 'to match', /^0[,.]019904$/);
expect(store.channelBalancePendingLabel, 'to match', /^0[,.]006003$/);
expect(store.channelBalanceClosingLabel, 'to match', /^0[,.]009003$/);
expect(
store.channelBalanceForceClosingLabel,
'to match',
/^0[,.]004001$/
);
expect(store.channelStatus, 'to equal', 'success');
});
......@@ -111,11 +120,11 @@ describe('Computed Channels Unit Tests', () => {
expect(ch.capacityLabel, 'to match', /138[,.]25/);
expect(ch.localBalanceLabel, 'to match', /137[,.]21/);
expect(ch.remoteBalanceLabel, 'to match', /0[,.]69/);
expect(store.channelBalanceOpenLabel, 'to match', /137[,.]21/);
expect(store.channelBalanceInactiveLabel, 'to match', /137[,.]21/);
expect(store.channelBalancePendingLabel, 'to match', /41[,.]37/);
expect(store.channelBalanceClosingLabel, 'to match', /62[,.]06/);
expect(store.channelBalanceForceClosingLabel, 'to match', /27[,.]58/);
expect(store.channelBalanceOpenLabel, 'to match', /137[,.]25/);
expect(store.channelBalanceInactiveLabel, 'to match', /137[,.]24/);
expect(store.channelBalancePendingLabel, 'to match', /41[,.]39/);
expect(store.channelBalanceClosingLabel, 'to match', /62[,.]08/);
expect(store.channelBalanceForceClosingLabel, 'to match', /27[,.]59/);
});
it('should display pending status', () => {
......
......@@ -10,6 +10,9 @@ describe('Computed Wallet Unit Tests', () => {
describe('ComputedWallet()', () => {
it('should work with initial store', () => {
store.channelBalancePendingSatoshis = 0;
store.channelBalanceOpenSatoshis = 0;
store.channelBalanceInactiveSatoshis = 0;
store.channelBalanceForceClosingSatoshis = 0;
ComputedWallet(store);
expect(store.walletAddressUri, 'to equal', '');
......@@ -37,8 +40,9 @@ describe('Computed Wallet Unit Tests', () => {
store.settings.displayFiat = true;
store.settings.exchangeRate.usd = 0.00014503;
store.balanceSatoshis = 50000000;
store.pendingBalanceSatoshis = 50000000;
store.channelBalanceSatoshis = 10000;
store.channelBalancePendingSatoshis = 50000000;
store.channelBalanceOpenSatoshis = 5000;
store.channelBalanceInactiveSatoshis = 5000;
store.channelBalanceForceClosingSatoshis = 100;
ComputedWallet(store);
expect(store.balanceLabel, 'to match', /3[,.]447[,.]56/);
......@@ -53,8 +57,9 @@ describe('Computed Wallet Unit Tests', () => {
store.settings.displayFiat = false;
store.settings.exchangeRate.usd = 0.00014503;
store.balanceSatoshis = 50000001;
store.pendingBalanceSatoshis = 50000000;
store.channelBalanceSatoshis = 10000;
store.channelBalancePendingSatoshis = 50000000;
store.channelBalanceOpenSatoshis = 5000;
store.channelBalanceInactiveSatoshis = 5000;
store.channelBalanceForceClosingSatoshis = 100;
store.settings.unit = 'bit';
ComputedWallet(store);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment