From 43676179dcaaddf956b99cd4e695b04e59a9239f Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 28 Apr 2022 06:46:22 +0200 Subject: [PATCH] Improve sync behaviour --- src/shared/apiService.ts | 2 +- src/stores/ftbot.ts | 48 +++++++++++++++++--------------------- src/stores/ftbotwrapper.ts | 2 +- src/stores/settings.ts | 1 - 4 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/shared/apiService.ts b/src/shared/apiService.ts index ec54f3a9..918f7dcf 100644 --- a/src/shared/apiService.ts +++ b/src/shared/apiService.ts @@ -28,7 +28,7 @@ export function useApi(userService: UserService, botId: string) { (err) => { // console.log(err); if (err.response && err.response.status === 401) { - console.log('Dispatching refresh_token...'); + console.log('Fetching refresh_token...'); return userService .refreshToken() .then((token) => { diff --git a/src/stores/ftbot.ts b/src/stores/ftbot.ts index 5b1992dd..f72e58fa 100644 --- a/src/stores/ftbot.ts +++ b/src/stores/ftbot.ts @@ -184,17 +184,13 @@ export function createBotSubStore(botId: string, botName: string) { rename(name: string) { userService.renameBot(name); }, - setRefreshRequired(refreshRequired: boolean) { - this.refreshRequired = refreshRequired; - }, setAutoRefresh(newRefreshValue) { this.autoRefresh = newRefreshValue; // TODO: Investigate this - // this ONLY works if ReloadControl is only visible once,otherwise it triggers twice if (newRefreshValue) { - // dispatch('startRefresh', true); - } else { - // dispatch('stopRefresh'); + this.refreshFrequent(); + this.refreshSlow(true); } userService.setAutoRefresh(newRefreshValue); }, @@ -274,17 +270,17 @@ export function createBotSubStore(botId: string, botName: string) { trades = trades.concat(result.trades); totalTrades = res.data.total_trades; } while (trades.length !== totalTrades); - const tradesCount = trades.length; - // Add botId to all trades - trades = trades.map((t) => ({ - ...t, - botId, - botName, - botTradeId: `${botId}__${t.trade_id}`, - })); - this.trades = trades; - this.tradeCount = tradesCount; } + const tradesCount = trades.length; + // Add botId to all trades + trades = trades.map((t) => ({ + ...t, + botId, + botName, + botTradeId: `${botId}__${t.trade_id}`, + })); + this.trades = trades; + this.tradeCount = tradesCount; return Promise.resolve(); } catch (error) { @@ -309,18 +305,16 @@ export function createBotSubStore(botId: string, botName: string) { ) { // Open trades changed, so we should refresh now. this.refreshRequired = true; - // dispatch('refreshSlow', null, { root: true }); - - const openTrades = result.data.map((t) => ({ - ...t, - botId, - botName, - botTradeId: `${botId}__${t.trade_id}`, - })); - this.openTrades = openTrades; - } else { - this.openTrades = []; + this.refreshSlow(false); } + + const openTrades = result.data.map((t) => ({ + ...t, + botId, + botName, + botTradeId: `${botId}__${t.trade_id}`, + })); + this.openTrades = openTrades; }) .catch(console.error); }, diff --git a/src/stores/ftbotwrapper.ts b/src/stores/ftbotwrapper.ts index 53a4c396..e820a4b7 100644 --- a/src/stores/ftbotwrapper.ts +++ b/src/stores/ftbotwrapper.ts @@ -172,7 +172,6 @@ export const useBotStore = defineStore('wrapper', { delete this.availableBots[botId]; this.botStores = { ...this.botStores }; this.availableBots = { ...this.availableBots }; - // commit('removeBot', botId); } else { console.warn(`bot ${botId} not found! could not remove`); } @@ -314,4 +313,5 @@ export function initBots() { botStore.addBot(v); }); botStore.selectFirstBot(); + botStore.startRefresh(); } diff --git a/src/stores/settings.ts b/src/stores/settings.ts index 1719a5e9..1c623c1e 100644 --- a/src/stores/settings.ts +++ b/src/stores/settings.ts @@ -60,7 +60,6 @@ export const useSettingsStore = defineStore('uiSettings', { const result = await axios.get('/ui_version'); const { version } = result.data; this.uiVersion = version; - // commit('setUIVersion', version); } catch (error) { // }