Move refresh actions to subBotStore

This commit is contained in:
Matthias 2021-08-29 15:56:54 +02:00
parent ea71dcc190
commit b23c122629
2 changed files with 50 additions and 44 deletions

View File

@ -165,36 +165,7 @@ export default function createBotStore(store) {
commit('setRefreshing', false);
}
},
async refreshSlow({ dispatch, getters, state }, forceUpdate = false) {
if (state.refreshing && !forceUpdate) {
return;
}
// Refresh data only when needed
if (forceUpdate || getters[`${BotStoreGetters.refreshRequired}`]) {
const updates: Promise<AxiosInstance>[] = [];
updates.push(dispatch('getPerformance'));
updates.push(dispatch('getProfit'));
updates.push(dispatch('getTrades'));
/* white/blacklist might be refreshed more often as they are not expensive on the backend */
updates.push(dispatch('getWhitelist'));
updates.push(dispatch('getBlacklist'));
await Promise.all(updates);
dispatch('setRefreshRequired', false);
}
},
refreshFrequent({ dispatch }, slow = true) {
if (slow) {
dispatch('refreshSlow', false);
}
// Refresh data that's needed in near realtime
dispatch('getOpenTrades');
dispatch('getState');
dispatch('getLocks');
},
refreshOnce({ dispatch }) {
dispatch('getVersion');
},
startRefresh({ getters, state, dispatch, commit }, runNow: boolean) {
console.log('starting refresh');
// Start refresh timer
@ -205,23 +176,23 @@ export default function createBotStore(store) {
console.log('Starting automatic refresh.');
if (runNow) {
dispatch('refreshFrequent', false);
dispatch('refreshSlow', true);
}
if (state.autoRefresh && !state.refreshInterval) {
if (state.autoRefresh) {
if (!state.refreshInterval) {
// Set interval for refresh
const refreshInterval = window.setInterval(() => {
dispatch('refreshFrequent');
}, 5000);
commit('setRefreshInterval', refreshInterval);
}
if (runNow) {
dispatch('refreshSlow', true);
}
if (state.autoRefresh && !state.refreshIntervalSlow) {
if (!state.refreshIntervalSlow) {
const refreshIntervalSlow = window.setInterval(() => {
dispatch('refreshSlow', false);
}, 60000);
commit('setRefreshIntervalSlow', refreshIntervalSlow);
}
}
},
stopRefresh({ state, commit }: { state: FTMultiBotState; commit: any }) {
console.log('Stopping automatic refresh.');

View File

@ -37,7 +37,8 @@ import {
getAllPlotConfigNames,
storePlotConfigName,
} from '@/shared/storage';
import axios from 'axios';
import axios, { AxiosInstance } from 'axios';
import state, { FtbotStateType } from './state';
import { showAlert } from '../alerts';
@ -89,6 +90,9 @@ export enum BotStoreGetters {
export enum BotStoreActions {
ping = 'ping',
setRefreshRequired = 'setRefreshRequired',
refreshSlow = 'refreshSlow',
refreshFrequent = 'refreshFrequent',
refreshOnce = 'refreshOnce',
setDetailTrade = 'setDetailTrade',
setSelectedPair = 'setSelectedPair',
getTrades = 'getTrades',
@ -406,6 +410,37 @@ export function createBotSubStore(botId: string) {
[BotStoreActions.setRefreshRequired]({ commit }, refreshRequired: boolean) {
commit('updateRefreshRequired', refreshRequired);
},
[BotStoreActions.refreshOnce]({ dispatch }) {
dispatch('getVersion');
},
async [BotStoreActions.refreshSlow]({ dispatch, getters, state }, forceUpdate = false) {
if (state.refreshing && !forceUpdate) {
return;
}
// Refresh data only when needed
if (forceUpdate || getters[`${BotStoreGetters.refreshRequired}`]) {
const updates: Promise<AxiosInstance>[] = [];
updates.push(dispatch('getPerformance'));
updates.push(dispatch('getProfit'));
updates.push(dispatch('getTrades'));
/* white/blacklist might be refreshed more often as they are not expensive on the backend */
updates.push(dispatch('getWhitelist'));
updates.push(dispatch('getBlacklist'));
await Promise.all(updates);
dispatch('setRefreshRequired', false);
}
},
[BotStoreActions.refreshFrequent]({ dispatch }, slow = true) {
if (slow) {
dispatch('refreshSlow', false);
}
// Refresh data that's needed in near realtime
dispatch('getOpenTrades');
dispatch('getState');
dispatch('getLocks');
},
[BotStoreActions.setDetailTrade]({ commit }, trade: Trade) {
commit('setDetailTrade', trade);
},