Skip to content

Commit 67a048a

Browse files
itsrachelfishellemouton
authored andcommitted
store: Create canFetchData getters for loop and pool
1 parent 6fa13bc commit 67a048a

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

app/src/components/pool/PoolPage.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ const PoolPage: React.FC = () => {
3838
const { accountStore, orderStore, batchStore, subServerStore } = useStore();
3939

4040
useEffect(() => {
41-
if (
42-
subServerStore.subServers.pool?.running &&
43-
!subServerStore.subServers.pool?.error
44-
) {
41+
if (batchStore.canFetchData) {
4542
accountStore.fetchAccounts();
4643
orderStore.fetchOrders();
4744
batchStore.fetchNextBatchInfo();

app/src/store/store.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,7 @@ export class Store {
165165
await this.nodeStore.fetchBalances();
166166
await this.sessionStore.fetchSessions();
167167

168-
if (
169-
this.subServerStore.subServers.loop?.running &&
170-
!this.subServerStore.subServers.loop?.error
171-
) {
168+
if (this.swapStore.canFetchData) {
172169
await this.swapStore.fetchSwaps();
173170
}
174171
}

app/src/store/stores/batchStore.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ export default class BatchStore {
111111
return false;
112112
}
113113

114+
/** checks the subserver status to ensure pool is running */
115+
get canFetchData() {
116+
if (
117+
this._store.subServerStore.subServers.pool.running &&
118+
!this._store.subServerStore.subServers.pool.error
119+
) {
120+
return true;
121+
}
122+
123+
return false;
124+
}
125+
114126
/**
115127
* fetches the next set of past batches from the API
116128
*/
@@ -314,10 +326,7 @@ export default class BatchStore {
314326
*/
315327
init() {
316328
// 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-
) {
329+
if (this.canFetchData) {
321330
// when the pubkey is fetched from the API and set in the nodeStore, fetch
322331
// the node's tier
323332
when(

app/src/store/stores/swapStore.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ export default class SwapStore {
5959
);
6060
}
6161

62+
/** checks the subserver status to ensure loop is running */
63+
get canFetchData() {
64+
if (
65+
this._store.subServerStore.subServers.loop.running &&
66+
!this._store.subServerStore.subServers.loop.error
67+
) {
68+
return true;
69+
}
70+
71+
return false;
72+
}
73+
6274
/** stores the id of a dismissed swap */
6375
dismissSwap(swapId: string) {
6476
this.dismissedSwapIds.push(swapId);

0 commit comments

Comments
 (0)