convert store methods to async

This commit is contained in:
Matthias 2022-09-10 14:56:21 +02:00
parent 455a15dd00
commit bb83a0702d

View File

@ -424,17 +424,21 @@ export function createBotSubStore(botId: string, botName: string) {
return Promise.reject(data); return Promise.reject(data);
} }
}, },
getStrategyList() { async getStrategyList() {
return api try {
.get<StrategyListResult>('/strategies') const { data } = await api.get<StrategyListResult>('/strategies');
.then((result) => (this.strategyList = result.data.strategies)) this.strategyList = data.strategies;
.catch(console.error); return Promise.resolve(data);
} catch (error) {
console.error(error);
return Promise.reject(error);
}
}, },
async getStrategy(strategy: string) { async getStrategy(strategy: string) {
try { try {
const result = await api.get<StrategyResult>(`/strategy/${strategy}`, {}); const { data } = await api.get<StrategyResult>(`/strategy/${strategy}`, {});
this.strategy = result.data; this.strategy = data;
return Promise.resolve(result.data); return Promise.resolve(data);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
return Promise.reject(error); return Promise.reject(error);
@ -442,13 +446,12 @@ export function createBotSubStore(botId: string, botName: string) {
}, },
async getAvailablePairs(payload: AvailablePairPayload) { async getAvailablePairs(payload: AvailablePairPayload) {
try { try {
const result = await api.get<AvailablePairResult>('/available_pairs', { const { data } = await api.get<AvailablePairResult>('/available_pairs', {
params: { ...payload }, params: { ...payload },
}); });
// result is of type AvailablePairResult // result is of type AvailablePairResult
const { pairs } = result.data; this.pairlist = data.pairs;
this.pairlist = pairs; return Promise.resolve(data);
return Promise.resolve(result.data);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
return Promise.reject(error); return Promise.reject(error);
@ -456,44 +459,48 @@ export function createBotSubStore(botId: string, botName: string) {
}, },
async getPerformance() { async getPerformance() {
try { try {
const result = await api.get<Performance[]>('/performance'); const { data } = await api.get<Performance[]>('/performance');
this.performanceStats = result.data; this.performanceStats = data;
return Promise.resolve(result.data); return Promise.resolve(data);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
return Promise.reject(error); return Promise.reject(error);
} }
}, },
getWhitelist() { async getWhitelist() {
return api try {
.get<WhitelistResponse>('/whitelist') const { data } = await api.get<WhitelistResponse>('/whitelist');
.then((result) => { this.whitelist = data.whitelist;
this.whitelist = result.data.whitelist; this.pairlistMethods = data.method;
this.pairlistMethods = result.data.method; return Promise.resolve(data);
return Promise.resolve(result.data); } catch (error) {
})
.catch((error) => {
// console.error(error);
return Promise.reject(error); return Promise.reject(error);
}); }
}, },
getBlacklist() { async getBlacklist() {
return api try {
.get<BlacklistResponse>('/blacklist') const { data } = await api.get<BlacklistResponse>('/blacklist');
.then((result) => (this.blacklist = result.data.blacklist)) this.blacklist = data.blacklist;
.catch(console.error); return Promise.resolve(data);
} catch (error) {
return Promise.reject(error);
}
}, },
getProfit() { async getProfit() {
return api try {
.get('/profit') const { data } = await api.get('/profit');
.then((result) => (this.profit = result.data)) this.profit = data;
.catch(console.error); return Promise.resolve(data);
} catch (error) {
console.error(error);
return Promise.reject(error);
}
}, },
async getBalance() { async getBalance() {
try { try {
const result = await api.get('/balance'); const { data } = await api.get('/balance');
this.balance = result.data; this.balance = data;
return Promise.resolve(result.data); return Promise.resolve(data);
} catch (error) { } catch (error) {
return Promise.reject(error); return Promise.reject(error);
} }
@ -505,32 +512,39 @@ export function createBotSubStore(botId: string, botName: string) {
this.dailyStats = data; this.dailyStats = data;
return Promise.resolve(data); return Promise.resolve(data);
} catch (error) { } catch (error) {
console.error(error);
return Promise.reject(error); return Promise.reject(error);
} }
}, },
getState() { async getState() {
return api try {
.get('/show_config') const { data } = await api.get('/show_config');
.then((result) => { this.botState = data;
this.botState = result.data;
this.botStatusAvailable = true; this.botStatusAvailable = true;
}) return Promise.resolve(data);
.catch(console.error); } catch (error) {
console.error(error);
return Promise.reject(error);
}
}, },
getLogs() { async getLogs() {
return api try {
.get('/logs') const { data } = await api.get('/logs');
.then((result) => (this.lastLogs = result.data.logs)) this.lastLogs = data.logs;
.catch(console.error); return Promise.resolve(data);
} catch (error) {
console.error(error);
return Promise.reject(error);
}
}, },
// // Post methods // // Post methods
// // TODO: Migrate calls to API to a seperate module unrelated to pinia? // // TODO: Migrate calls to API to a seperate module unrelated to pinia?
async startBot() { async startBot() {
try { try {
const res = await api.post<{}, AxiosResponse<StatusResponse>>('/start', {}); const { data } = await api.post<{}, AxiosResponse<StatusResponse>>('/start', {});
console.log(res.data); console.log(data);
showAlert(res.data.status); showAlert(data.status);
return Promise.resolve(res); return Promise.resolve(data);
} catch (error) { } catch (error) {
if (axios.isAxiosError(error)) { if (axios.isAxiosError(error)) {
console.error(error.response); console.error(error.response);