From 25e0bace6d3119722593be13005c905cf20b9dcd Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 18 Sep 2021 10:40:53 +0200 Subject: [PATCH] Fix error when 2 trade-id's collide in dashboard --- src/components/ftbot/TradeList.vue | 2 +- src/store/modules/botStoreWrapper.ts | 1 - src/store/modules/ftbot/index.ts | 12 +++++++++++- src/store/modules/layout.ts | 4 ++-- src/types/trades.ts | 2 +- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/components/ftbot/TradeList.vue b/src/components/ftbot/TradeList.vue index 1ba63b5b..f814d0f1 100644 --- a/src/components/ftbot/TradeList.vue +++ b/src/components/ftbot/TradeList.vue @@ -11,7 +11,7 @@ :empty-text="emptyText" :per-page="perPage" :current-page="currentPage" - primary-key="trade_id" + primary-key="botTradeId" selectable select-mode="single" :filter="filterText" diff --git a/src/store/modules/botStoreWrapper.ts b/src/store/modules/botStoreWrapper.ts index 9b105941..d1296c4c 100644 --- a/src/store/modules/botStoreWrapper.ts +++ b/src/store/modules/botStoreWrapper.ts @@ -92,7 +92,6 @@ export default function createBotStore(store) { getters.allAvailableBotsList.forEach((botId) => { const trades = getters[`${botId}/${BotStoreGetters.openTrades}`].map((t) => ({ ...t, - botId, })); resp = resp.concat(trades); diff --git a/src/store/modules/ftbot/index.ts b/src/store/modules/ftbot/index.ts index 6facf4e2..187b8419 100644 --- a/src/store/modules/ftbot/index.ts +++ b/src/store/modules/ftbot/index.ts @@ -514,6 +514,11 @@ export function createBotSubStore(botId: string) { } while (trades.length !== totalTrades); } const tradesCount = trades.length; + // Add botId to all trades + trades = trades.map((t) => ({ + ...t, + botTradeId: `${botId}__${t.trade_id}`, + })); commit('updateTrades', { trades, tradesCount }); return Promise.resolve(); } catch (error) { @@ -564,7 +569,12 @@ export function createBotSubStore(botId: string) { // dispatch('refreshSlow', null, { root: true }); } - commit('updateOpenTrades', result.data); + const openTrades = result.data.map((t) => ({ + ...t, + botTradeId: `${botId}__${t.trade_id}`, + })); + + commit('updateOpenTrades', openTrades); }) .catch(console.error); }, diff --git a/src/store/modules/layout.ts b/src/store/modules/layout.ts index eb21203c..8dd51504 100644 --- a/src/store/modules/layout.ts +++ b/src/store/modules/layout.ts @@ -53,8 +53,8 @@ const DEFAULT_TRADING_LAYOUT: GridItemData[] = [ const DEFAULT_DASHBOARD_LAYOUT: GridItemData[] = [ { i: DashboardLayout.KPI, x: 0, y: 0, w: 4, h: 6 }, { i: DashboardLayout.dailyChart, x: 4, y: 0, w: 4, h: 6 }, - { i: DashboardLayout.botComparison, x: 0, y: 6, w: 6, h: 4 } /* Bot Comparison */, - { i: DashboardLayout.allOpenTrades, x: 6, y: 6, w: 6, h: 4 }, + { i: DashboardLayout.botComparison, x: 0, y: 6, w: 6, h: 6 } /* Bot Comparison */, + { i: DashboardLayout.allOpenTrades, x: 6, y: 6, w: 6, h: 6 }, { i: DashboardLayout.cumChartChart, x: 8, y: 0, w: 4, h: 6 }, { i: DashboardLayout.tradesLogChart, x: 0, y: 12, w: 12, h: 4 }, ]; diff --git a/src/types/trades.ts b/src/types/trades.ts index 10423b2b..5987d8df 100644 --- a/src/types/trades.ts +++ b/src/types/trades.ts @@ -3,7 +3,7 @@ export interface Trade { * BotId - only available on "all" methods. * corresponds to the UI (ftbot.1) - does NOT relate to the backend */ - botId: string; + botTradeId: string; trade_id: number; pair: string; is_open: boolean;