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

View File

@ -84,7 +84,8 @@ export enum BotStoreGetters {
selectedBacktestResultKey = 'selectedBacktestResultKey',
}
export default {
export function createBotSubStore() {
return {
namespaced: true,
state,
getters: {
@ -393,7 +394,10 @@ export default {
async deleteLock({ dispatch, commit }, lockid: string) {
try {
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);
return Promise.resolve(res);
} catch (error) {
@ -413,7 +417,9 @@ export default {
Array.isArray(state.openTrades) &&
Array.isArray(result.data) &&
(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.
commit('updateRefreshRequired', true);
@ -643,7 +649,10 @@ export default {
async deleteTrade({ dispatch }, tradeid: string) {
try {
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);
} catch (error) {
if (axios.isAxiosError(error)) {
@ -691,7 +700,11 @@ export default {
} catch (error) {
if (axios.isAxiosError(error)) {
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);
}
@ -772,4 +785,5 @@ export default {
}
},
},
};
};
}