File tree Expand file tree Collapse file tree 5 files changed +87
-7
lines changed
Expand file tree Collapse file tree 5 files changed +87
-7
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import {
1616 RouterStore ,
1717 SessionStore ,
1818 SettingsStore ,
19+ SubServerStore ,
1920 SwapStore ,
2021} from './stores' ;
2122import {
@@ -49,6 +50,7 @@ export class Store {
4950 orderStore = new OrderStore ( this ) ;
5051 settingsStore = new SettingsStore ( this ) ;
5152 sessionStore = new SessionStore ( this ) ;
53+ subServerStore = new SubServerStore ( this ) ;
5254
5355 /** the store which synchronizes with the browser history */
5456 router : RouterStore ;
@@ -157,11 +159,18 @@ export class Store {
157159 * makes the initial API calls to fetch the data we need to display in the app
158160 */
159161 async fetchAllData ( ) {
162+ await this . subServerStore . fetchStatus ( ) ;
160163 await this . nodeStore . fetchInfo ( ) ;
161164 await this . channelStore . fetchChannels ( ) ;
162- await this . swapStore . fetchSwaps ( ) ;
163165 await this . nodeStore . fetchBalances ( ) ;
164166 await this . sessionStore . fetchSessions ( ) ;
167+
168+ if (
169+ this . subServerStore . subServers . loop ?. running &&
170+ ! this . subServerStore . subServers . loop ?. error
171+ ) {
172+ await this . swapStore . fetchSwaps ( ) ;
173+ }
165174 }
166175
167176 /** connects to the LND and Loop websocket streams if not already connected */
Original file line number Diff line number Diff line change @@ -313,11 +313,17 @@ export default class BatchStore {
313313 * initialize the batch store
314314 */
315315 init ( ) {
316- // when the pubkey is fetched from the API and set in the nodeStore, fetch
317- // the node's tier
318- when (
319- ( ) => ! ! this . _store . nodeStore . pubkey && ! this . nodeTier ,
320- ( ) => this . fetchNodeTier ( ) ,
321- ) ;
316+ // make sure the pool subserver is running before initializing
317+ if (
318+ this . _store . subServerStore . subServers . pool ?. running &&
319+ ! this . _store . subServerStore . subServers . pool ?. error
320+ ) {
321+ // when the pubkey is fetched from the API and set in the nodeStore, fetch
322+ // the node's tier
323+ when (
324+ ( ) => ! ! this . _store . nodeStore . pubkey && ! this . nodeTier ,
325+ ( ) => this . fetchNodeTier ( ) ,
326+ ) ;
327+ }
322328 }
323329}
Original file line number Diff line number Diff line change @@ -8,3 +8,4 @@ export { default as SettingsStore } from './settingsStore';
88export { default as SwapStore } from './swapStore' ;
99export { default as RouterStore } from './routerStore' ;
1010export { default as SessionStore } from './sessionStore' ;
11+ export { default as SubServerStore } from './subServerStore' ;
Original file line number Diff line number Diff line change 1+ import { makeAutoObservable , runInAction } from 'mobx' ;
2+ import { Store } from 'store' ;
3+ import { SubServerStatus } from 'types/state' ;
4+
5+ /** processed data for specific subservices we need to display in the UI */
6+ interface SubServers {
7+ loop : SubServerStatus ;
8+ pool : SubServerStatus ;
9+ }
10+
11+ export default class SubServerStore {
12+ private _store : Store ;
13+
14+ loading = false ;
15+
16+ subServers : SubServers = {
17+ loop : {
18+ disabled : false ,
19+ running : true ,
20+ error : '' ,
21+ } ,
22+ pool : {
23+ disabled : false ,
24+ running : true ,
25+ error : '' ,
26+ } ,
27+ } ;
28+
29+ constructor ( store : Store ) {
30+ makeAutoObservable ( this , { } , { deep : false , autoBind : true } ) ;
31+
32+ this . _store = store ;
33+ }
34+
35+ /** fetch subserver statuses from the lit API */
36+ async fetchStatus ( ) {
37+ try {
38+ this . loading = true ;
39+ const serverStatus = await this . _store . api . lit . listSubServerStatus ( ) ;
40+
41+ serverStatus . subServersMap . map ( ( [ serverName , serverStatus ] ) => {
42+ runInAction ( ( ) => {
43+ if ( serverName === 'pool' ) {
44+ this . subServers . pool = serverStatus ;
45+ } else if ( serverName === 'loop' ) {
46+ this . subServers . loop = serverStatus ;
47+ }
48+ } ) ;
49+ } ) ;
50+ } catch ( error ) {
51+ this . _store . appView . handleError ( error , 'Unable to fetch SubServer Status' ) ;
52+ } finally {
53+ runInAction ( ( ) => {
54+ this . loading = false ;
55+ } ) ;
56+ }
57+ }
58+ }
Original file line number Diff line number Diff line change @@ -69,3 +69,9 @@ export enum ChannelStatus {
6969 * duration is not just a random number.
7070 */
7171export type LeaseDuration = number ;
72+
73+ export interface SubServerStatus {
74+ disabled : boolean ;
75+ running : boolean ;
76+ error : string ;
77+ }
You can’t perform that action at this time.
0 commit comments