Add botstorewrapper

This commit is contained in:
Matthias 2021-08-28 17:39:12 +02:00
parent b2f893b9ec
commit a2d8b68abb
4 changed files with 82 additions and 40 deletions

View File

@ -4,7 +4,8 @@ import Vuex from 'vuex';
import userService from '@/shared/userService';
import { getCurrentTheme, getTheme, storeCurrentTheme } from '@/shared/themes';
import axios, { AxiosInstance } from 'axios';
import { createBotSubStore, BotStoreGetters } from './modules/ftbot';
import createBotStore from './modules/botStoreWrapper';
import { BotStoreGetters } from './modules/ftbot';
import alertsModule from './modules/alerts';
import layoutModule from './modules/layout';
import settingsModule from './modules/settings';
@ -16,7 +17,7 @@ const initCurrentTheme = getCurrentTheme();
export default new Vuex.Store({
modules: {
ftbot: createBotSubStore(),
ftbot: createBotStore(),
alerts: alertsModule,
layout: layoutModule,
uiSettings: settingsModule,
@ -122,7 +123,7 @@ export default new Vuex.Store({
commit('setRefreshing', false);
}
},
async refreshSlow({ dispatch, commit, getters, state }, forceUpdate = false) {
async refreshSlow({ dispatch, getters, state }, forceUpdate = false) {
if (state.refreshing && !forceUpdate) {
return;
}
@ -137,7 +138,7 @@ export default new Vuex.Store({
updates.push(dispatch('ftbot/getBlacklist'));
await Promise.all(updates);
commit('ftbot/updateRefreshRequired', false);
dispatch('ftbot/setRefreshRequired', false);
}
},
refreshFrequent({ dispatch }, slow = true) {

View File

@ -0,0 +1,36 @@
import { BotStoreActions, BotStoreGetters, createBotSubStore } from './ftbot';
export default function createBotStore() {
const state = {
selectedBot: 'ftbot.0',
};
const actions = {
// Actions automatically filled below
addBot(context, botName: string) {
//
},
};
const getters = {};
// Autocreate getters
Object.keys(BotStoreGetters).forEach((e) => {
getters[e] = (state, getters) => {
return getters[`${state.selectedBot}/${e}`];
};
});
// Autocreate Actions
Object.keys(BotStoreActions).forEach((e) => {
actions[e] = ({ state, dispatch }, ...args) => {
return dispatch(`${state.selectedBot}/${e}`, ...args);
};
});
return {
namespaced: true,
modules: {
'ftbot.0': createBotSubStore(),
},
state,
getters,
actions,
};
}

View File

@ -87,6 +87,7 @@ export enum BotStoreGetters {
export enum BotStoreActions {
ping = 'ping',
setRefreshRequired = 'setRefreshRequired',
setDetailTrade = 'setDetailTrade',
setSelectedPair = 'setSelectedPair',
getTrades = 'getTrades',
@ -388,6 +389,9 @@ export function createBotSubStore() {
.catch(console.error);
}
},
[BotStoreActions.setRefreshRequired]({ commit }, refreshRequired: boolean) {
commit('setRefreshRequired', refreshRequired);
},
[BotStoreActions.setDetailTrade]({ commit }, trade: Trade) {
commit('setDetailTrade', trade);
},

View File

@ -54,7 +54,8 @@ export interface FtbotStateType {
backtestHistory: Record<string, StrategyBacktestResult>;
}
const state: FtbotStateType = {
const state = (): FtbotStateType => {
return {
version: '',
lastLogs: [],
refreshRequired: true,
@ -90,5 +91,5 @@ const state: FtbotStateType = {
selectedBacktestResultKey: '',
backtestHistory: {},
};
};
export default state;