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 {
16
16
RouterStore ,
17
17
SessionStore ,
18
18
SettingsStore ,
19
+ SubServerStore ,
19
20
SwapStore ,
20
21
} from './stores' ;
21
22
import {
@@ -49,6 +50,7 @@ export class Store {
49
50
orderStore = new OrderStore ( this ) ;
50
51
settingsStore = new SettingsStore ( this ) ;
51
52
sessionStore = new SessionStore ( this ) ;
53
+ subServerStore = new SubServerStore ( this ) ;
52
54
53
55
/** the store which synchronizes with the browser history */
54
56
router : RouterStore ;
@@ -157,11 +159,18 @@ export class Store {
157
159
* makes the initial API calls to fetch the data we need to display in the app
158
160
*/
159
161
async fetchAllData ( ) {
162
+ await this . subServerStore . fetchStatus ( ) ;
160
163
await this . nodeStore . fetchInfo ( ) ;
161
164
await this . channelStore . fetchChannels ( ) ;
162
- await this . swapStore . fetchSwaps ( ) ;
163
165
await this . nodeStore . fetchBalances ( ) ;
164
166
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
+ }
165
174
}
166
175
167
176
/** 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 {
313
313
* initialize the batch store
314
314
*/
315
315
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
+ }
322
328
}
323
329
}
Original file line number Diff line number Diff line change @@ -8,3 +8,4 @@ export { default as SettingsStore } from './settingsStore';
8
8
export { default as SwapStore } from './swapStore' ;
9
9
export { default as RouterStore } from './routerStore' ;
10
10
export { 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 {
69
69
* duration is not just a random number.
70
70
*/
71
71
export 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