1- import { makeAutoObservable , observable , ObservableMap , runInAction , toJS } from 'mobx' ;
1+ import {
2+ makeAutoObservable ,
3+ observable ,
4+ ObservableMap ,
5+ runInAction ,
6+ toJS ,
7+ when ,
8+ } from 'mobx' ;
9+ import { NodeTier } from 'types/generated/auctioneer_pb' ;
210import { IS_DEV , IS_TEST } from 'config' ;
311import debounce from 'lodash/debounce' ;
12+ import { hex } from 'util/strings' ;
413import { Store } from 'store' ;
514import { Batch } from 'store/models' ;
15+ import { Tier } from 'store/models/order' ;
616
717export const BATCH_QUERY_LIMIT = 20 ;
818const ZERO_BATCH_ID =
@@ -25,6 +35,9 @@ export default class BatchStore {
2535 /** the timestamp of the next batch in seconds */
2636 nextBatchTimestamp = 0 ;
2737
38+ /** the tier of the current LND node */
39+ nodeTier ?: Tier ;
40+
2841 /** indicates when batches are being fetched from the backend */
2942 loading = false ;
3043
@@ -148,6 +161,28 @@ export default class BatchStore {
148161 }
149162 }
150163
164+ /**
165+ * fetches the next batch timestamp from the API
166+ */
167+ async fetchNodeTier ( ) {
168+ this . _store . log . info ( 'fetching node tier' ) ;
169+ try {
170+ const pubkey = this . _store . nodeStore . pubkey ;
171+ const { nodeRatingsList } = await this . _store . api . pool . nodeRatings ( pubkey ) ;
172+ runInAction ( ( ) => {
173+ const rating = nodeRatingsList . find ( r => hex ( r . nodePubkey ) === pubkey ) ;
174+ if ( rating ) {
175+ this . nodeTier = rating . nodeTier ;
176+ } else {
177+ this . nodeTier = NodeTier . TIER_0 ;
178+ }
179+ this . _store . log . info ( 'updated batchStore.nodeTier' , this . nodeTier ) ;
180+ } ) ;
181+ } catch ( error ) {
182+ this . _store . appView . handleError ( error , 'Unable to fetch the node tier' ) ;
183+ }
184+ }
185+
151186 /**
152187 * sets the nextBatchTimestamp and creates a timer to fetch the latest batch, which
153188 * will trigger 3 seconds after the next batch timestamp to allow some time for the
@@ -191,4 +226,16 @@ export default class BatchStore {
191226 this . _store . log . info ( 'polling was already stopped' ) ;
192227 }
193228 }
229+
230+ /**
231+ * initialize the batch store
232+ */
233+ init ( ) {
234+ // when the pubkey is fetched from the API and set in the nodeStore, fetch
235+ // the node's tier
236+ when (
237+ ( ) => ! ! this . _store . nodeStore . pubkey && ! this . nodeTier ,
238+ ( ) => this . fetchNodeTier ( ) ,
239+ ) ;
240+ }
194241}
0 commit comments