Skip to content

Commit 94b727a

Browse files
committed
pool+batches: display next fee rate in batch stats header
1 parent c2ad201 commit 94b727a

File tree

8 files changed

+44
-21
lines changed

8 files changed

+44
-21
lines changed

app/src/__tests__/components/pool/BatchChart.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('BatchChart', () => {
1717
store = createStore();
1818
await store.orderStore.fetchOrders();
1919
await store.batchStore.fetchBatches();
20-
await store.batchStore.fetchNextBatchTimestamp();
20+
await store.batchStore.fetchNextBatchInfo();
2121
});
2222

2323
const render = () => {

app/src/__tests__/components/pool/BatchSection.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('BatchSection', () => {
1818
store = createStore();
1919
await store.orderStore.fetchOrders();
2020
await store.batchStore.fetchBatches();
21-
await store.batchStore.fetchNextBatchTimestamp();
21+
await store.batchStore.fetchNextBatchInfo();
2222
await store.batchStore.fetchNodeTier();
2323
});
2424

app/src/__tests__/components/pool/BatchStats.spec.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('BatchStats', () => {
1414
store = createStore();
1515
await store.orderStore.fetchOrders();
1616
await store.batchStore.fetchBatches();
17-
await store.batchStore.fetchNextBatchTimestamp();
17+
await store.batchStore.fetchNextBatchInfo();
1818
});
1919

2020
const render = () => {
@@ -41,14 +41,24 @@ describe('BatchStats', () => {
4141
jest.useRealTimers();
4242
});
4343

44+
it('should display the next fee rate', () => {
45+
const { getByText } = render();
46+
expect(getByText('Next Fee')).toBeInTheDocument();
47+
expect(getByText(`${store.batchesView.nextFeeRate}`)).toBeInTheDocument();
48+
runInAction(() => {
49+
store.batchStore.nextFeeRate = 25;
50+
});
51+
expect(getByText('25')).toBeInTheDocument();
52+
});
53+
4454
it('should display the previous rate', () => {
45-
const { getByText, getAllByText } = render();
55+
const { getByText } = render();
4656
expect(getByText('Previous Rate')).toBeInTheDocument();
4757
expect(getByText(`${store.batchesView.currentRate}`)).toBeInTheDocument();
4858
runInAction(() => {
4959
store.batchStore.batches.clear();
5060
});
51-
expect(getAllByText(`0`)).toHaveLength(2);
61+
expect(getByText('0')).toBeInTheDocument();
5262
});
5363

5464
it('should display the percent rate changed', () => {

app/src/components/pool/PoolPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const PoolPage: React.FC = () => {
3939
useEffect(() => {
4040
accountStore.fetchAccounts();
4141
orderStore.fetchOrders();
42-
batchStore.fetchNextBatchTimestamp();
42+
batchStore.fetchNextBatchInfo();
4343
if (!batchStore.batches.size) {
4444
// fetch batches if there aren't any in the store
4545
batchStore.fetchBatches();

app/src/components/pool/batches/BatchStats.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ const BatchStats: React.FC = () => {
6565
tip={l('nextBatchTip')}
6666
/>
6767
<Stat
68-
label={l('prevFee')}
69-
value={`${batchesView.currentFee}`}
70-
tip={l('prevFeeTip')}
68+
label={l('nextFeeRate')}
69+
value={`${batchesView.nextFeeRate}`}
70+
tip={l('nextFeeRateTip')}
7171
{...tipProps}
7272
/>
7373
<Stat

app/src/i18n/locales/en-US.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@
160160
"cmps.pool.batches.BatchRowHeader.clearedRate": "Cleared Rate",
161161
"cmps.pool.batches.BatchStats.nextBatch": "Next Batch",
162162
"cmps.pool.batches.BatchStats.nextBatchTip": "Countdown until the next batch is attempted to be made",
163-
"cmps.pool.batches.BatchStats.prevFee": "Previous Fee",
164-
"cmps.pool.batches.BatchStats.prevFeeTip": "The fee used for the previous batch in sats/vbyte",
163+
"cmps.pool.batches.BatchStats.nextFeeRate": "Next Fee",
164+
"cmps.pool.batches.BatchStats.nextFeeRateTip": "The estimated fee rate (sats/vbyte) to use for the next batch",
165165
"cmps.pool.batches.BatchStats.prevRate": "Previous Rate",
166166
"cmps.pool.batches.BatchStats.prevRateTip": "The rate cleared in the previous batch ({{fixedRate}} per block)",
167167
"cmps.pool.batches.BatchStats.rateChange": "Change",

app/src/store/stores/batchStore.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export default class BatchStore {
3737
/** the timestamp of the next batch in seconds */
3838
nextBatchTimestamp = 0;
3939

40+
/** the fee rate (sats/vbyte) estimated by the auctioneer to use for the next batch */
41+
nextFeeRate = 0;
42+
4043
/** the tier of the current LND node */
4144
nodeTier?: Tier;
4245

@@ -140,7 +143,7 @@ export default class BatchStore {
140143
try {
141144
const poolBatches = await this._store.api.pool.batchSnapshots(1);
142145
// update the timestamp of the next batch when fetching the latest batch
143-
await this.fetchNextBatchTimestamp();
146+
await this.fetchNextBatchInfo();
144147
runInAction(() => {
145148
// update the batches in all markets
146149
this.markets.forEach(m => m.update(poolBatches.batchesList, true));
@@ -156,26 +159,28 @@ export default class BatchStore {
156159
fetchLatestBatchThrottled = debounce(this.fetchLatestBatch, 2000);
157160

158161
/**
159-
* fetches the next batch timestamp from the API
162+
* fetches the next batch info from the API and updates the next timestamp and fee rate
160163
*/
161-
async fetchNextBatchTimestamp() {
164+
async fetchNextBatchInfo() {
162165
this._store.log.info('fetching next batch info');
163166
try {
164-
const { clearTimestamp } = await this._store.api.pool.nextBatchInfo();
167+
const res = await this._store.api.pool.nextBatchInfo();
165168
runInAction(() => {
166-
this.setNextBatchTimestamp(clearTimestamp);
169+
this.setNextBatchTimestamp(res.clearTimestamp);
167170
this._store.log.info(
168171
'updated batchStore.nextBatchTimestamp',
169172
this.nextBatchTimestamp,
170173
);
174+
this.setNextFeeRate(res.feeRateSatPerKw);
175+
this._store.log.info('updated batchStore.nextFeeRate', this.nextFeeRate);
171176
});
172177
} catch (error) {
173-
this._store.appView.handleError(error, 'Unable to fetch the next batch timestamp');
178+
this._store.appView.handleError(error, 'Unable to fetch the next batch info');
174179
}
175180
}
176181

177182
/**
178-
* fetches the next batch timestamp from the API
183+
* fetches the current lnd node's tier from the API
179184
*/
180185
async fetchNodeTier() {
181186
this._store.log.info('fetching node tier');
@@ -263,6 +268,14 @@ export default class BatchStore {
263268
this._nextBatchTimer = setTimeout(this.fetchLatestBatch, ms + 3000);
264269
}
265270

271+
/**
272+
* sets the nextFeeRate by converting the provided sats/kw to sats/vbyte
273+
*/
274+
setNextFeeRate(satsPerKWeight: number) {
275+
const satsPerVbyte = this._store.api.pool.satsPerKWeightToVByte(satsPerKWeight);
276+
this.nextFeeRate = Math.ceil(satsPerVbyte);
277+
}
278+
266279
startPolling() {
267280
if (IS_TEST) return;
268281
if (this._pollingInterval) this.stopPolling();

app/src/store/views/batchesView.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ export default class BatchesView {
4747
return toPercent((currentRate - priorRate) / priorRate);
4848
}
4949

50-
/** the fee used for the last batch */
51-
get currentFee() {
52-
return this.batches.length ? this.batches[0].feeLabel : 0;
50+
/** the fee rate (sats/vbyte) estimated by the auctioneer to use for the next batch */
51+
get nextFeeRate() {
52+
return this._store.batchStore.nextFeeRate;
5353
}
5454

5555
/** the tier of the current LND node as a user-friendly string */

0 commit comments

Comments
 (0)