From 542d453f0b0829955e5d35c6554125553c3ddf80 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 18 Sep 2021 15:43:22 +0200 Subject: [PATCH] Store last selected bot --- src/store/modules/botStoreWrapper.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/store/modules/botStoreWrapper.ts b/src/store/modules/botStoreWrapper.ts index d1296c4c..15a39f6d 100644 --- a/src/store/modules/botStoreWrapper.ts +++ b/src/store/modules/botStoreWrapper.ts @@ -2,6 +2,8 @@ import { BotDescriptor, BotDescriptors, Trade } from '@/types'; import { AxiosInstance } from 'axios'; import { BotStoreActions, BotStoreGetters, createBotSubStore } from './ftbot'; +const AUTH_SELECTED_BOT = 'ftSelectedBot'; + interface FTMultiBotState { selectedBot: string; availableBots: BotDescriptors; @@ -173,12 +175,17 @@ export default function createBotStore(store) { }, selectFirstBot({ commit, getters }) { if (getters.hasBots) { + const selBotId = localStorage.getItem(AUTH_SELECTED_BOT); const firstBot = Object.keys(getters.allAvailableBots)[0]; - console.log(firstBot); - commit('selectBot', getters.allAvailableBots[firstBot].botId); + let selBot: string | undefined = firstBot; + if (selBotId) { + selBot = Object.keys(getters.allAvailableBots).find((x) => x === selBotId); + } + commit('selectBot', getters.allAvailableBots[selBot || firstBot].botId); } }, selectBot({ commit }, botId: string) { + localStorage.setItem(AUTH_SELECTED_BOT, botId); commit('selectBot', botId); }, allRefreshFrequent({ dispatch, getters }, slow: boolean) {