Create substore as function

This commit is contained in:
Matthias 2021-08-28 14:25:31 +02:00
parent fe8ea0afdf
commit 60fe49cbaf
2 changed files with 679 additions and 665 deletions

View File

@ -4,7 +4,7 @@ import Vuex from 'vuex';
import userService from '@/shared/userService'; import userService from '@/shared/userService';
import { getCurrentTheme, getTheme, storeCurrentTheme } from '@/shared/themes'; import { getCurrentTheme, getTheme, storeCurrentTheme } from '@/shared/themes';
import axios, { AxiosInstance } from 'axios'; import axios, { AxiosInstance } from 'axios';
import ftbotModule, { BotStoreGetters } from './modules/ftbot'; import { createBotSubStore, BotStoreGetters } from './modules/ftbot';
import alertsModule from './modules/alerts'; import alertsModule from './modules/alerts';
import layoutModule from './modules/layout'; import layoutModule from './modules/layout';
import settingsModule from './modules/settings'; import settingsModule from './modules/settings';
@ -40,7 +40,7 @@ export default new Vuex.Store({
}, },
}, },
modules: { modules: {
ftbot: ftbotModule, ftbot: createBotSubStore(),
alerts: alertsModule, alerts: alertsModule,
layout: layoutModule, layout: layoutModule,
uiSettings: settingsModule, uiSettings: settingsModule,

View File

@ -84,7 +84,8 @@ export enum BotStoreGetters {
selectedBacktestResultKey = 'selectedBacktestResultKey', selectedBacktestResultKey = 'selectedBacktestResultKey',
} }
export default { export function createBotSubStore() {
return {
namespaced: true, namespaced: true,
state, state,
getters: { getters: {
@ -393,7 +394,10 @@ export default {
async deleteLock({ dispatch, commit }, lockid: string) { async deleteLock({ dispatch, commit }, lockid: string) {
try { try {
const res = await api.delete(`/locks/${lockid}`); const res = await api.delete(`/locks/${lockid}`);
showAlert(dispatch, res.data.result_msg ? res.data.result_msg : `Deleted Lock ${lockid}.`); showAlert(
dispatch,
res.data.result_msg ? res.data.result_msg : `Deleted Lock ${lockid}.`,
);
commit('updateLocks', res.data); commit('updateLocks', res.data);
return Promise.resolve(res); return Promise.resolve(res);
} catch (error) { } catch (error) {
@ -413,7 +417,9 @@ export default {
Array.isArray(state.openTrades) && Array.isArray(state.openTrades) &&
Array.isArray(result.data) && Array.isArray(result.data) &&
(state.openTrades.length !== result.data.length || (state.openTrades.length !== result.data.length ||
!state.openTrades.every((val, index) => val.trade_id === result.data[index].trade_id)) !state.openTrades.every(
(val, index) => val.trade_id === result.data[index].trade_id,
))
) { ) {
// Open trades changed, so we should refresh now. // Open trades changed, so we should refresh now.
commit('updateRefreshRequired', true); commit('updateRefreshRequired', true);
@ -643,7 +649,10 @@ export default {
async deleteTrade({ dispatch }, tradeid: string) { async deleteTrade({ dispatch }, tradeid: string) {
try { try {
const res = await api.delete(`/trades/${tradeid}`); const res = await api.delete(`/trades/${tradeid}`);
showAlert(dispatch, res.data.result_msg ? res.data.result_msg : `Deleted Trade ${tradeid}`); showAlert(
dispatch,
res.data.result_msg ? res.data.result_msg : `Deleted Trade ${tradeid}`,
);
return Promise.resolve(res); return Promise.resolve(res);
} catch (error) { } catch (error) {
if (axios.isAxiosError(error)) { if (axios.isAxiosError(error)) {
@ -691,7 +700,11 @@ export default {
} catch (error) { } catch (error) {
if (axios.isAxiosError(error)) { if (axios.isAxiosError(error)) {
console.error(error.response); console.error(error.response);
showAlert(dispatch, `Error occured buying: '${error.response?.data?.error}'`, 'danger'); showAlert(
dispatch,
`Error occured buying: '${error.response?.data?.error}'`,
'danger',
);
} }
return Promise.reject(error); return Promise.reject(error);
} }
@ -773,3 +786,4 @@ export default {
}, },
}, },
}; };
}