Store last selected bot

This commit is contained in:
Matthias 2021-09-18 15:43:22 +02:00
parent b937fdf07b
commit 542d453f0b

View File

@ -2,6 +2,8 @@ import { BotDescriptor, BotDescriptors, Trade } from '@/types';
import { AxiosInstance } from 'axios'; import { AxiosInstance } from 'axios';
import { BotStoreActions, BotStoreGetters, createBotSubStore } from './ftbot'; import { BotStoreActions, BotStoreGetters, createBotSubStore } from './ftbot';
const AUTH_SELECTED_BOT = 'ftSelectedBot';
interface FTMultiBotState { interface FTMultiBotState {
selectedBot: string; selectedBot: string;
availableBots: BotDescriptors; availableBots: BotDescriptors;
@ -173,12 +175,17 @@ export default function createBotStore(store) {
}, },
selectFirstBot({ commit, getters }) { selectFirstBot({ commit, getters }) {
if (getters.hasBots) { if (getters.hasBots) {
const selBotId = localStorage.getItem(AUTH_SELECTED_BOT);
const firstBot = Object.keys(getters.allAvailableBots)[0]; const firstBot = Object.keys(getters.allAvailableBots)[0];
console.log(firstBot); let selBot: string | undefined = firstBot;
commit('selectBot', getters.allAvailableBots[firstBot].botId); if (selBotId) {
selBot = Object.keys(getters.allAvailableBots).find((x) => x === selBotId);
}
commit('selectBot', getters.allAvailableBots[selBot || firstBot].botId);
} }
}, },
selectBot({ commit }, botId: string) { selectBot({ commit }, botId: string) {
localStorage.setItem(AUTH_SELECTED_BOT, botId);
commit('selectBot', botId); commit('selectBot', botId);
}, },
allRefreshFrequent({ dispatch, getters }, slow: boolean) { allRefreshFrequent({ dispatch, getters }, slow: boolean) {