Skip to content

Commit a54fe4d

Browse files
itsrachelfishellemouton
authored andcommitted
store: Create subServerStore
1 parent 51b0d48 commit a54fe4d

File tree

5 files changed

+87
-7
lines changed

5 files changed

+87
-7
lines changed

app/src/store/store.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
RouterStore,
1717
SessionStore,
1818
SettingsStore,
19+
SubServerStore,
1920
SwapStore,
2021
} from './stores';
2122
import {
@@ -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 */

app/src/store/stores/batchStore.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff 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
}

app/src/store/stores/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export { default as SettingsStore } from './settingsStore';
88
export { default as SwapStore } from './swapStore';
99
export { default as RouterStore } from './routerStore';
1010
export { default as SessionStore } from './sessionStore';
11+
export { default as SubServerStore } from './subServerStore';
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
}

app/src/types/state.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@ export enum ChannelStatus {
6969
* duration is not just a random number.
7070
*/
7171
export type LeaseDuration = number;
72+
73+
export interface SubServerStatus {
74+
disabled: boolean;
75+
running: boolean;
76+
error: string;
77+
}

0 commit comments

Comments
 (0)