From 4de3a96faebf8a25fc00ff5c10a0c8173e041600 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 23 Apr 2022 10:43:12 +0200 Subject: [PATCH] Fix small bug in handling invalid responses --- .gitignore | 2 ++ src/components/layout/NavBar.vue | 7 ++++-- src/stores/ftbot.ts | 41 +++++++++++++++++--------------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 824255d1..f8b328c5 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ node_modules package-lock.json /dist +cypress/screenshots/* + # local env files .env.local .env.*.local diff --git a/src/components/layout/NavBar.vue b/src/components/layout/NavBar.vue index 9004eaed..e6e3ee35 100644 --- a/src/components/layout/NavBar.vue +++ b/src/components/layout/NavBar.vue @@ -216,8 +216,11 @@ export default defineComponent({ () => botStore.activeBotorUndefined?.openTradeCount, () => { console.log('openTradeCount changed'); - if (settingsStore.openTradesInTitle === OpenTradeVizOptions.showPill) { - setOpenTradesAsPill(botStore.activeBot.openTradeCount); + if ( + settingsStore.openTradesInTitle === OpenTradeVizOptions.showPill && + botStore.activeBotorUndefined?.openTradeCount + ) { + setOpenTradesAsPill(botStore.activeBotorUndefined.openTradeCount); } else if (settingsStore.openTradesInTitle === OpenTradeVizOptions.asTitle) { setTitle(); } diff --git a/src/stores/ftbot.ts b/src/stores/ftbot.ts index 4a8c12b4..5b1992dd 100644 --- a/src/stores/ftbot.ts +++ b/src/stores/ftbot.ts @@ -262,7 +262,7 @@ export function createBotSubStore(botId: string, botName: string) { const res = await fetchTrades(pageLength, 0); const result: TradeResponse = res.data; let { trades } = result; - if (trades.length !== result.total_trades) { + if (Array.isArray(trades) && trades.length !== result.total_trades) { // Pagination necessary // Don't use Promise.all - this would fire all requests at once, which can // cause problems for big sqlite databases @@ -274,17 +274,18 @@ 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) { if (axios.isAxiosError(error)) { @@ -309,15 +310,17 @@ 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; + const openTrades = result.data.map((t) => ({ + ...t, + botId, + botName, + botTradeId: `${botId}__${t.trade_id}`, + })); + this.openTrades = openTrades; + } else { + this.openTrades = []; + } }) .catch(console.error); },