Skip to content

Commit c6b3806

Browse files
committed
channel: round fee rate % to two decimals and display tooltip with exact value
1 parent 90f0008 commit c6b3806

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

app/src/__tests__/components/loop/ChannelRow.spec.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ describe('ChannelRow component', () => {
5050
expect(getByText(channel.uptime.toString())).toBeInTheDocument();
5151
});
5252

53+
it('should display the fee rate', () => {
54+
const { getByText } = render();
55+
channel.remoteFeeRate = 500;
56+
expect(getByText(channel.remoteFeePct)).toBeInTheDocument();
57+
fireEvent.mouseEnter(getByText(channel.remoteFeePct));
58+
expect(getByText(`${channel.remoteFeeRate} ppm`)).toBeInTheDocument();
59+
});
60+
5361
it('should display the peer pubkey or alias', () => {
5462
const { getByText } = render();
5563
expect(getByText(channel.aliasLabel)).toBeInTheDocument();

app/src/__tests__/store/channelStore.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,7 @@ describe('ChannelStore', () => {
164164
expect(channel.remoteFeeRate).toBe(0);
165165
// the alias is fetched from the API and should be updated after a few ticks
166166
await waitFor(() => {
167-
const rate = +Big(lndGetChanInfo.node1Policy.feeRateMilliMsat)
168-
.div(1000000)
169-
.mul(100);
170-
expect(channel.remoteFeeRate).toBe(rate);
167+
expect(channel.remoteFeeRate).toBe(lndGetChanInfo.node1Policy.feeRateMilliMsat);
171168
});
172169
});
173170

app/src/components/loop/ChannelRow.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ const ChannelRow: React.FC<Props> = ({ channel, style }) => {
155155
<Column>
156156
<Unit sats={channel.localBalance} suffix={false} />
157157
</Column>
158-
<Column cols={1}>{channel.remoteFeeRate}</Column>
158+
<Column cols={1}>
159+
<Tip overlay={`${channel.remoteFeeRate} ppm`} placement="left" capitalize={false}>
160+
<span>{channel.remoteFeePct}</span>
161+
</Tip>
162+
</Column>
159163
<Column cols={1}>{channel.uptimePercent}</Column>
160164
<WideColumn cols={2}>
161165
<Tip

app/src/store/models/channel.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ export default class Channel {
7171
return percentage(this.localBalance, this.capacity);
7272
}
7373

74+
/**
75+
* The remote peer's fee as a percentage
76+
*/
77+
@computed get remoteFeePct(): string {
78+
// the fee returned from the RPC is a number representing the amount of
79+
// msats charged as a fee per one million msats to forward. To convert to
80+
// a percentage, the value must be divided by 1M
81+
return Big(this.remoteFeeRate).div(1000000).mul(100).round(2).toFixed(2);
82+
}
83+
7484
/**
7585
* The order to sort this channel based on the current mode
7686
*/

app/src/store/stores/channelStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export default class ChannelStore {
162162
const localPubkey = this._store.nodeStore.pubkey;
163163
const policy = node1Pub === localPubkey ? node2Policy : node1Policy;
164164
if (policy) {
165-
acc[channelId] = +Big(policy.feeRateMilliMsat).div(1000000).mul(100);
165+
acc[channelId] = policy.feeRateMilliMsat;
166166
}
167167
return acc;
168168
}, data);

0 commit comments

Comments
 (0)