fix bug in fetch logic

This commit is contained in:
Matthias 2022-04-28 19:38:51 +02:00
parent bc7f21eaff
commit c385d7a097

View File

@ -256,30 +256,31 @@ export function createBotSubStore(botId: string, botName: string) {
const res = await fetchTrades(pageLength, 0);
const result: TradeResponse = res.data;
let { trades } = result;
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
do {
// eslint-disable-next-line no-await-in-loop
const res = await fetchTrades(pageLength, trades.length);
if (Array.isArray(trades)) {
if (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
do {
// eslint-disable-next-line no-await-in-loop
const res = await fetchTrades(pageLength, trades.length);
const result: TradeResponse = res.data;
trades = trades.concat(result.trades);
totalTrades = res.data.total_trades;
} while (trades.length !== totalTrades);
const result: TradeResponse = res.data;
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)) {
@ -305,14 +306,15 @@ export function createBotSubStore(botId: string, botName: string) {
this.refreshRequired = true;
this.refreshSlow(false);
}
const openTrades = result.data.map((t) => ({
...t,
botId,
botName,
botTradeId: `${botId}__${t.trade_id}`,
}));
this.openTrades = openTrades;
if (Array.isArray(result.data)) {
const openTrades = result.data.map((t) => ({
...t,
botId,
botName,
botTradeId: `${botId}__${t.trade_id}`,
}));
this.openTrades = openTrades;
}
})
.catch(console.error);
},