From a4aa87aed8247288567a99e842242fa53c38b3bc Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 8 Dec 2022 19:54:43 +0100 Subject: [PATCH] Add "logged out" state to BotEntry --- src/components/BotEntry.vue | 8 ++++++++ src/shared/apiService.ts | 5 +++++ src/shared/userService.ts | 12 ++++++++++-- src/stores/ftbot.ts | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/components/BotEntry.vue b/src/components/BotEntry.vue index d30aab0c..7ab673be 100644 --- a/src/components/BotEntry.vue +++ b/src/components/BotEntry.vue @@ -12,11 +12,17 @@ @change="changeEvent" > +
@@ -44,6 +50,7 @@ import EditIcon from 'vue-material-design-icons/Pencil.vue'; import DeleteIcon from 'vue-material-design-icons/Delete.vue'; import OnlineIcon from 'vue-material-design-icons/Circle.vue'; +import LoggedOutIcon from 'vue-material-design-icons/Cancel.vue'; import { BotDescriptor } from '@/types'; import { defineComponent, computed, ref } from 'vue'; import { useBotStore } from '@/stores/ftbotwrapper'; @@ -54,6 +61,7 @@ export default defineComponent({ DeleteIcon, EditIcon, OnlineIcon, + LoggedOutIcon, }, props: { bot: { required: true, type: Object as () => BotDescriptor }, diff --git a/src/shared/apiService.ts b/src/shared/apiService.ts index e8009e8b..d2630251 100644 --- a/src/shared/apiService.ts +++ b/src/shared/apiService.ts @@ -50,6 +50,11 @@ export function useApi(userService: UserService, botId: string) { .catch((error) => { console.log('No new token received'); console.log(error); + const botStore = useBotStore(); + if (botStore.botStores[botId]) { + botStore.botStores[botId].setIsBotOnline(false); + botStore.botStores[botId].isBotLoggedIn = false; + } }); // maybe redirect to /login if needed ! diff --git a/src/shared/userService.ts b/src/shared/userService.ts index 18ef4dba..3990bcda 100644 --- a/src/shared/userService.ts +++ b/src/shared/userService.ts @@ -80,6 +80,13 @@ export class UserService { }; } + setRefreshTokenExpired(): void { + const loginInfo = this.getLoginInfo(); + loginInfo.refreshToken = ''; + loginInfo.accessToken = ''; + this.storeLoginInfo(loginInfo); + } + public static getAvailableBots(): BotDescriptors { const allInfo = UserService.getAllLoginInfos(); const response: BotDescriptors = {}; @@ -167,8 +174,9 @@ export class UserService { .catch((err) => { console.error(err); if (err.response && err.response.status === 401) { - // in case of errors when using the refresh token - logout. - this.logout(); + // Refresh token did not refresh. + console.log('Refresh token did not refresh.'); + this.setRefreshTokenExpired(); } else if (err.response && (err.response.status === 500 || err.response.status === 404)) { console.log('Bot seems to be offline... - retrying later'); } diff --git a/src/stores/ftbot.ts b/src/stores/ftbot.ts index 445bed1c..0ab22826 100644 --- a/src/stores/ftbot.ts +++ b/src/stores/ftbot.ts @@ -54,6 +54,7 @@ export function createBotSubStore(botId: string, botName: string) { ping: '', botStatusAvailable: false, isBotOnline: false, + isBotLoggedIn: true, autoRefresh: false, refreshing: false, versionState: '', @@ -824,7 +825,6 @@ export function createBotSubStore(botId: string, botName: string) { showNotification(msg, botName); break; case FtWsMessageTypes.newCandle: - console.log('exitFill', msg); const [pair, timeframe] = msg.data; // TODO: check for active bot ... if (pair === this.selectedPair) {