mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-23 11:35:14 +00:00
Move autoRefresh to single bot stores
This commit is contained in:
parent
10d13d788e
commit
76eff0dc4b
|
@ -6,6 +6,15 @@
|
|||
<span class="ml-2 align-middle">{{
|
||||
allIsBotOnline[bot.botId] ? '🟢' : '🔴'
|
||||
}}</span>
|
||||
<b-form-checkbox
|
||||
v-model="autoRefreshLoc"
|
||||
class="ml-auto float-right mr-2 my-auto"
|
||||
title="AutoRefresh"
|
||||
variant="secondary"
|
||||
@change="changeEvent"
|
||||
>
|
||||
R
|
||||
</b-form-checkbox>
|
||||
<div v-if="!noButtons" class="d-flex flex-align-cent">
|
||||
<b-button class="ml-1" size="sm" title="Edit bot" @click="clickRemoveBot(bot)">
|
||||
<EditIcon :size="16" title="Edit Button" />
|
||||
|
@ -37,12 +46,27 @@ export default class BotList extends Vue {
|
|||
|
||||
@ftbot.Getter [MultiBotStoreGetters.allIsBotOnline];
|
||||
|
||||
@ftbot.Getter [MultiBotStoreGetters.allAutoRefresh];
|
||||
|
||||
@ftbot.Getter [MultiBotStoreGetters.allAvailableBots]: BotDescriptors;
|
||||
|
||||
@ftbot.Action removeBot;
|
||||
|
||||
@ftbot.Action selectBot;
|
||||
|
||||
get autoRefreshLoc() {
|
||||
return this.allAutoRefresh[this.bot.botId];
|
||||
}
|
||||
|
||||
set autoRefreshLoc(v) {
|
||||
// Dummy setter - Set via change event.
|
||||
}
|
||||
|
||||
changeEvent(v) {
|
||||
console.log('changeEvent', v);
|
||||
this.$store.dispatch(`ftbot/${this.bot.botId}/setAutoRefresh`, v);
|
||||
}
|
||||
|
||||
clickRemoveBot(bot: BotDescriptor) {
|
||||
//
|
||||
this.$bvModal
|
||||
|
|
|
@ -7,7 +7,6 @@ const AUTO_REFRESH = 'ft_auto_refresh';
|
|||
interface FTMultiBotState {
|
||||
selectedBot: string;
|
||||
availableBots: BotDescriptors;
|
||||
autoRefresh: boolean;
|
||||
refreshing: boolean;
|
||||
refreshInterval: number | null;
|
||||
refreshIntervalSlow: number | null;
|
||||
|
@ -22,14 +21,13 @@ export enum MultiBotStoreGetters {
|
|||
allAvailableBotsList = 'allAvailableBotsList',
|
||||
allIsBotOnline = 'allIsBotOnline',
|
||||
nextBotId = 'nextBotId',
|
||||
autoRefresh = 'autoRefresh',
|
||||
allAutoRefresh = 'allAutoRefresh',
|
||||
}
|
||||
|
||||
export default function createBotStore(store) {
|
||||
const state: FTMultiBotState = {
|
||||
selectedBot: '',
|
||||
availableBots: {},
|
||||
autoRefresh: JSON.parse(localStorage.getItem(AUTO_REFRESH) || '{}'),
|
||||
refreshing: false,
|
||||
refreshInterval: null,
|
||||
refreshIntervalSlow: null,
|
||||
|
@ -62,6 +60,13 @@ export default function createBotStore(store) {
|
|||
});
|
||||
return result;
|
||||
},
|
||||
[MultiBotStoreGetters.allAutoRefresh](state: FTMultiBotState, getters): {} {
|
||||
const result = {};
|
||||
getters.allAvailableBotsList.forEach((e) => {
|
||||
result[e] = getters[`${e}/autoRefresh`];
|
||||
});
|
||||
return result;
|
||||
},
|
||||
[MultiBotStoreGetters.nextBotId](state: FTMultiBotState): string {
|
||||
let botCount = Object.keys(state.availableBots).length;
|
||||
|
||||
|
@ -70,9 +75,6 @@ export default function createBotStore(store) {
|
|||
}
|
||||
return `ftbot.${botCount}`;
|
||||
},
|
||||
[MultiBotStoreGetters.autoRefresh](state: FTMultiBotState): boolean {
|
||||
return state.autoRefresh;
|
||||
},
|
||||
};
|
||||
// Autocreate getters from botStores
|
||||
Object.keys(BotStoreGetters).forEach((e) => {
|
||||
|
@ -143,19 +145,6 @@ export default function createBotStore(store) {
|
|||
selectBot({ commit }, botId: string) {
|
||||
commit('selectBot', botId);
|
||||
},
|
||||
setAutoRefresh({ dispatch, commit }, newRefreshValue) {
|
||||
// TODO: global autorefresh, or per subbot?
|
||||
console.log('setAutoRefresh', newRefreshValue);
|
||||
commit('setAutoRefresh', 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');
|
||||
}
|
||||
localStorage.setItem(AUTO_REFRESH, JSON.stringify(newRefreshValue));
|
||||
},
|
||||
async refreshFull({ dispatch, state, commit }, forceUpdate = false) {
|
||||
if (state.refreshing) {
|
||||
return;
|
||||
|
|
|
@ -45,6 +45,7 @@ import { showAlert } from '../alerts';
|
|||
export enum BotStoreGetters {
|
||||
botName = 'botName',
|
||||
isBotOnline = 'isBotOnline',
|
||||
autoRefresh = 'autoRefresh',
|
||||
openTrades = 'openTrades',
|
||||
openTradeCount = 'openTradeCount',
|
||||
tradeDetail = 'tradeDetail',
|
||||
|
@ -89,6 +90,8 @@ export enum BotStoreGetters {
|
|||
|
||||
export enum BotStoreActions {
|
||||
ping = 'ping',
|
||||
setIsBotOnline = 'setIsBotOnline',
|
||||
setAutoRefresh = 'setAutoRefresh',
|
||||
setRefreshRequired = 'setRefreshRequired',
|
||||
refreshSlow = 'refreshSlow',
|
||||
refreshFrequent = 'refreshFrequent',
|
||||
|
@ -146,6 +149,9 @@ export function createBotSubStore(botId: string) {
|
|||
[BotStoreGetters.isBotOnline](state: FtbotStateType): boolean {
|
||||
return state.isBotOnline;
|
||||
},
|
||||
[BotStoreGetters.autoRefresh](state: FtbotStateType): boolean {
|
||||
return state.autoRefresh;
|
||||
},
|
||||
[BotStoreGetters.plotConfig](state: FtbotStateType) {
|
||||
return state.customPlotConfig[state.plotConfigName] || { ...EMPTY_PLOTCONFIG };
|
||||
},
|
||||
|
@ -292,6 +298,9 @@ export function createBotSubStore(botId: string) {
|
|||
setIsBotOnline(state: FtbotStateType, isBotOnline: boolean) {
|
||||
state.isBotOnline = isBotOnline;
|
||||
},
|
||||
setAutoRefresh(state: FtbotStateType, newRefreshValue: boolean) {
|
||||
state.autoRefresh = newRefreshValue;
|
||||
},
|
||||
updateRefreshRequired(state: FtbotStateType, refreshRequired: boolean) {
|
||||
state.refreshRequired = refreshRequired;
|
||||
},
|
||||
|
@ -411,6 +420,17 @@ export function createBotSubStore(botId: string) {
|
|||
[BotStoreActions.setRefreshRequired]({ commit }, refreshRequired: boolean) {
|
||||
commit('updateRefreshRequired', refreshRequired);
|
||||
},
|
||||
[BotStoreActions.setAutoRefresh]({ dispatch, commit }, newRefreshValue) {
|
||||
// commit('setAutoRefresh', 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');
|
||||
}
|
||||
userService.setAutoRefresh(newRefreshValue);
|
||||
},
|
||||
[BotStoreActions.setIsBotOnline]({ commit }, refreshRequired: boolean) {
|
||||
commit('setIsBotOnline', refreshRequired);
|
||||
},
|
||||
|
|
|
@ -19,6 +19,7 @@ import {
|
|||
export interface FtbotStateType {
|
||||
ping: string;
|
||||
isBotOnline: boolean;
|
||||
autoRefresh: boolean;
|
||||
version: string;
|
||||
lastLogs: LogLine[];
|
||||
refreshRequired: boolean;
|
||||
|
@ -60,6 +61,7 @@ const state = (): FtbotStateType => {
|
|||
return {
|
||||
ping: '',
|
||||
isBotOnline: false,
|
||||
autoRefresh: false,
|
||||
version: '',
|
||||
lastLogs: [],
|
||||
refreshRequired: true,
|
||||
|
|
Loading…
Reference in New Issue
Block a user