Improve sync behaviour

This commit is contained in:
Matthias 2022-04-28 06:46:22 +02:00
parent b477a9dddd
commit 43676179dc
4 changed files with 23 additions and 30 deletions

View File

@ -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) => {

View File

@ -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);
},

View File

@ -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();
}

View File

@ -60,7 +60,6 @@ export const useSettingsStore = defineStore('uiSettings', {
const result = await axios.get<UiVersion>('/ui_version');
const { version } = result.data;
this.uiVersion = version;
// commit('setUIVersion', version);
} catch (error) {
//
}