Improve code style

This commit is contained in:
Matthias 2020-05-18 20:49:30 +02:00
parent 253e4964c9
commit 2a95ee1a66
19 changed files with 236 additions and 215 deletions

View File

@ -1,20 +1,19 @@
module.exports = { module.exports = {
root: true, root: true,
env: { env: {
node: true node: true,
}, },
'extends': [ extends: [
'plugin:vue/essential', 'plugin:vue/essential',
// 'plugin:vue/recommended',
'@vue/airbnb', '@vue/airbnb',
"prettier"
], ],
'plugins': ["prettier"],
parserOptions: { parserOptions: {
parser: 'babel-eslint' parser: 'babel-eslint',
}, },
plugins: ['vue'],
rules: { rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
},
} };
}

View File

@ -22,11 +22,6 @@ jobs:
- name: npm install - name: npm install
uses: bahmutov/npm-install@v1 uses: bahmutov/npm-install@v1
- name: run lint - name: Run Lint
run: | run: |
npm run lint npm run lint-ci
# - name: Prettify code
# uses: creyD/prettier_action@v2.2
# with:
# dry: True

View File

@ -1,5 +1,6 @@
{ {
"printWidth": 100, "printWidth": 100,
"singleQuote": true, "singleQuote": true,
"trailingComma": "es5" "trailingComma": "es5",
"files": "./src/**/*.{js,vue,json}"
} }

View File

@ -10,21 +10,25 @@ It will require Freqtrade to be running on the same host with the API enabled un
## Project setup ## Project setup
``` ```
npm install npm install
``` ```
### Compiles and hot-reloads for development ### Compiles and hot-reloads for development
``` ```
npm run serve npm run serve
``` ```
### Compiles and minifies for production ### Compiles and minifies for production
``` ```
npm run build npm run build
``` ```
### Lints and fixes files ### Lints and fixes files
``` ```
npm run lint npm run lint
``` ```

View File

@ -1,5 +1,3 @@
module.exports = { module.exports = {
"presets": [ presets: ['@vue/cli-plugin-babel/preset'],
"@vue/cli-plugin-babel/preset" };
]
}

49
package-lock.json generated
View File

@ -1061,7 +1061,6 @@
"version": "0.3.0", "version": "0.3.0",
"resolved": "https://registry.npmjs.org/@nuxt/opencollective/-/opencollective-0.3.0.tgz", "resolved": "https://registry.npmjs.org/@nuxt/opencollective/-/opencollective-0.3.0.tgz",
"integrity": "sha512-Vf09BxCdj1iT2IRqVwX5snaY2WCTkvM0O4cWWSO1ThCFuc4if0Q/nNwAgCxRU0FeYHJ7DdyMUNSdswCLKlVqeg==", "integrity": "sha512-Vf09BxCdj1iT2IRqVwX5snaY2WCTkvM0O4cWWSO1ThCFuc4if0Q/nNwAgCxRU0FeYHJ7DdyMUNSdswCLKlVqeg==",
"dev": true,
"requires": { "requires": {
"chalk": "^2.4.2", "chalk": "^2.4.2",
"consola": "^2.10.1", "consola": "^2.10.1",
@ -1635,6 +1634,13 @@
"yallist": "^2.1.2" "yallist": "^2.1.2"
} }
}, },
"prettier": {
"version": "1.19.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz",
"integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==",
"dev": true,
"optional": true
},
"source-map": { "source-map": {
"version": "0.6.1", "version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
@ -1973,7 +1979,6 @@
"version": "3.2.1", "version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"requires": { "requires": {
"color-convert": "^1.9.0" "color-convert": "^1.9.0"
} }
@ -2490,14 +2495,12 @@
"bootstrap": { "bootstrap": {
"version": "4.4.1", "version": "4.4.1",
"resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.4.1.tgz", "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.4.1.tgz",
"integrity": "sha512-tbx5cHubwE6e2ZG7nqM3g/FZ5PQEDMWmMGNrCUBVRPHXTJaH7CBDdsLeu3eCh3B1tzAxTnAbtmrzvWEvT2NNEA==", "integrity": "sha512-tbx5cHubwE6e2ZG7nqM3g/FZ5PQEDMWmMGNrCUBVRPHXTJaH7CBDdsLeu3eCh3B1tzAxTnAbtmrzvWEvT2NNEA=="
"dev": true
}, },
"bootstrap-vue": { "bootstrap-vue": {
"version": "2.13.0", "version": "2.13.0",
"resolved": "https://registry.npmjs.org/bootstrap-vue/-/bootstrap-vue-2.13.0.tgz", "resolved": "https://registry.npmjs.org/bootstrap-vue/-/bootstrap-vue-2.13.0.tgz",
"integrity": "sha512-V/q2tgIY+tDxeBGOwqdPC4jk8CWmpwpSVY/1OVGxg4Jg1Jxcs6gQn7chhpI9KuBrO8diG/Nd6JRtnYwyE3b7Qw==", "integrity": "sha512-V/q2tgIY+tDxeBGOwqdPC4jk8CWmpwpSVY/1OVGxg4Jg1Jxcs6gQn7chhpI9KuBrO8diG/Nd6JRtnYwyE3b7Qw==",
"dev": true,
"requires": { "requires": {
"@nuxt/opencollective": "^0.3.0", "@nuxt/opencollective": "^0.3.0",
"bootstrap": ">=4.4.1 <5.0.0", "bootstrap": ">=4.4.1 <5.0.0",
@ -2901,7 +2904,6 @@
"version": "2.4.2", "version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"requires": { "requires": {
"ansi-styles": "^3.2.1", "ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5", "escape-string-regexp": "^1.0.5",
@ -3189,7 +3191,6 @@
"version": "1.9.3", "version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"dev": true,
"requires": { "requires": {
"color-name": "1.1.3" "color-name": "1.1.3"
} }
@ -3197,8 +3198,7 @@
"color-name": { "color-name": {
"version": "1.1.3", "version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
"dev": true
}, },
"color-string": { "color-string": {
"version": "1.5.3", "version": "1.5.3",
@ -3317,8 +3317,7 @@
"consola": { "consola": {
"version": "2.11.3", "version": "2.11.3",
"resolved": "https://registry.npmjs.org/consola/-/consola-2.11.3.tgz", "resolved": "https://registry.npmjs.org/consola/-/consola-2.11.3.tgz",
"integrity": "sha512-aoW0YIIAmeftGR8GSpw6CGQluNdkWMWh3yEFjH/hmynTYnMtibXszii3lxCXmk8YxJtI3FAK5aTiquA5VH68Gw==", "integrity": "sha512-aoW0YIIAmeftGR8GSpw6CGQluNdkWMWh3yEFjH/hmynTYnMtibXszii3lxCXmk8YxJtI3FAK5aTiquA5VH68Gw=="
"dev": true
}, },
"console-browserify": { "console-browserify": {
"version": "1.2.0", "version": "1.2.0",
@ -4450,8 +4449,7 @@
"escape-string-regexp": { "escape-string-regexp": {
"version": "1.0.5", "version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
"dev": true
}, },
"eslint": { "eslint": {
"version": "6.8.0", "version": "6.8.0",
@ -6223,8 +6221,7 @@
"has-flag": { "has-flag": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
"dev": true
}, },
"has-symbols": { "has-symbols": {
"version": "1.0.1", "version": "1.0.1",
@ -8010,8 +8007,7 @@
"node-fetch": { "node-fetch": {
"version": "2.6.0", "version": "2.6.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==", "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
"dev": true
}, },
"node-forge": { "node-forge": {
"version": "0.9.0", "version": "0.9.0",
@ -8711,14 +8707,12 @@
"popper.js": { "popper.js": {
"version": "1.16.1", "version": "1.16.1",
"resolved": "https://registry.npmjs.org/popper.js/-/popper.js-1.16.1.tgz", "resolved": "https://registry.npmjs.org/popper.js/-/popper.js-1.16.1.tgz",
"integrity": "sha512-Wb4p1J4zyFTbM+u6WuO4XstYx4Ky9Cewe4DWrel7B0w6VVICvPwdOpotjzcf6eD8TsckVnIMNONQyPIUFOUbCQ==", "integrity": "sha512-Wb4p1J4zyFTbM+u6WuO4XstYx4Ky9Cewe4DWrel7B0w6VVICvPwdOpotjzcf6eD8TsckVnIMNONQyPIUFOUbCQ=="
"dev": true
}, },
"portal-vue": { "portal-vue": {
"version": "2.1.7", "version": "2.1.7",
"resolved": "https://registry.npmjs.org/portal-vue/-/portal-vue-2.1.7.tgz", "resolved": "https://registry.npmjs.org/portal-vue/-/portal-vue-2.1.7.tgz",
"integrity": "sha512-+yCno2oB3xA7irTt0EU5Ezw22L2J51uKAacE/6hMPMoO/mx3h4rXFkkBkT4GFsMDv/vEe8TNKC3ujJJ0PTwb6g==", "integrity": "sha512-+yCno2oB3xA7irTt0EU5Ezw22L2J51uKAacE/6hMPMoO/mx3h4rXFkkBkT4GFsMDv/vEe8TNKC3ujJJ0PTwb6g=="
"dev": true
}, },
"portfinder": { "portfinder": {
"version": "1.0.26", "version": "1.0.26",
@ -9345,11 +9339,10 @@
"dev": true "dev": true
}, },
"prettier": { "prettier": {
"version": "1.19.1", "version": "2.0.5",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.0.5.tgz",
"integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", "integrity": "sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==",
"dev": true, "dev": true
"optional": true
}, },
"prettier-linter-helpers": { "prettier-linter-helpers": {
"version": "1.0.0", "version": "1.0.0",
@ -10891,7 +10884,6 @@
"version": "5.5.0", "version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"requires": { "requires": {
"has-flag": "^3.0.0" "has-flag": "^3.0.0"
} }
@ -11619,8 +11611,7 @@
"vue-functional-data-merge": { "vue-functional-data-merge": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/vue-functional-data-merge/-/vue-functional-data-merge-3.1.0.tgz", "resolved": "https://registry.npmjs.org/vue-functional-data-merge/-/vue-functional-data-merge-3.1.0.tgz",
"integrity": "sha512-leT4kdJVQyeZNY1kmnS1xiUlQ9z1B/kdBFCILIjYYQDqZgLqCLa0UhjSSeRX6c3mUe6U5qYeM8LrEqkHJ1B4LA==", "integrity": "sha512-leT4kdJVQyeZNY1kmnS1xiUlQ9z1B/kdBFCILIjYYQDqZgLqCLa0UhjSSeRX6c3mUe6U5qYeM8LrEqkHJ1B4LA=="
"dev": true
}, },
"vue-hot-reload-api": { "vue-hot-reload-api": {
"version": "2.3.4", "version": "2.3.4",

View File

@ -5,7 +5,8 @@
"scripts": { "scripts": {
"serve": "vue-cli-service serve", "serve": "vue-cli-service serve",
"build": "vue-cli-service build", "build": "vue-cli-service build",
"lint": "vue-cli-service lint" "lint": "vue-cli-service lint",
"lint-ci": "vue-cli-service lint --no-fix"
}, },
"dependencies": { "dependencies": {
"axios": "^0.19.2", "axios": "^0.19.2",
@ -33,6 +34,7 @@
"mutationobserver-shim": "^0.3.3", "mutationobserver-shim": "^0.3.3",
"popper.js": "^1.16.0", "popper.js": "^1.16.0",
"portal-vue": "^2.1.6", "portal-vue": "^2.1.6",
"prettier": "^2.0.5",
"sass": "^1.19.0", "sass": "^1.19.0",
"sass-loader": "^8.0.0", "sass-loader": "^8.0.0",
"vue-cli-plugin-bootstrap-vue": "~0.6.0", "vue-cli-plugin-bootstrap-vue": "~0.6.0",

View File

@ -70,7 +70,7 @@ export default {
forcesellHandler(item) { forcesellHandler(item) {
this.forcesell(item.trade_id) this.forcesell(item.trade_id)
.then(() => console.log('asdf')) .then(() => console.log('asdf'))
.catch(error => console.log(error.response)); .catch((error) => console.log(error.response));
}, },
handleContextMenuEvent(item, index, event) { handleContextMenuEvent(item, index, event) {
// stop browser context menu from appearing // stop browser context menu from appearing

View File

@ -1,16 +1,16 @@
<template> <template>
<header> <header>
<NavBar/> <NavBar />
</header> </header>
</template> </template>
<script> <script>
import NavBar from "./NavBar.vue" import NavBar from './NavBar.vue';
export default { export default {
name: "Header", name: 'Header',
components: {NavBar}, components: { NavBar },
} };
</script> </script>
<style scoped> <style scoped>

View File

@ -1,16 +1,16 @@
import Vue from 'vue' import Vue from 'vue';
import './plugins/bootstrap-vue' import './plugins/bootstrap-vue';
import App from './App.vue' import App from './App.vue';
import store from './store' import store from './store';
import router from './router' import router from './router';
import { apiStore } from './shared/apiService' import { apiStore } from './shared/apiService';
apiStore.store = store; apiStore.store = store;
Vue.config.productionTip = false Vue.config.productionTip = false;
new Vue({ new Vue({
store, store,
router, router,
render: h => h(App) render: (h) => h(App),
}).$mount('#app') }).$mount('#app');

View File

@ -1,8 +1,8 @@
import Vue from 'vue' import Vue from 'vue';
import BootstrapVue from 'bootstrap-vue' import BootstrapVue from 'bootstrap-vue';
import 'bootstrap/dist/css/bootstrap.min.css' import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap-vue/dist/bootstrap-vue.css' import 'bootstrap-vue/dist/bootstrap-vue.css';
Vue.use(BootstrapVue) Vue.use(BootstrapVue);

View File

@ -1,14 +1,14 @@
import Vue from 'vue' import Vue from 'vue';
import VueRouter from 'vue-router' import VueRouter from 'vue-router';
import Home from '@/views/Home.vue' import Home from '@/views/Home.vue';
Vue.use(VueRouter) Vue.use(VueRouter);
const routes = [ const routes = [
{ {
path: '/', path: '/',
name: 'Home', name: 'Home',
component: Home component: Home,
}, },
{ {
path: '/trade', path: '/trade',
@ -16,7 +16,7 @@ Vue.use(VueRouter)
// route level code-splitting // route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route // this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited. // which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ '@/views/Trade.vue') component: () => import(/* webpackChunkName: "about" */ '@/views/Trade.vue'),
}, },
{ {
path: '/about', path: '/about',
@ -24,14 +24,14 @@ Vue.use(VueRouter)
// route level code-splitting // route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route // this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited. // which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ '@/views/About.vue') component: () => import(/* webpackChunkName: "about" */ '@/views/About.vue'),
} },
] ];
const router = new VueRouter({ const router = new VueRouter({
mode: 'history', mode: 'history',
base: process.env.BASE_URL, base: process.env.BASE_URL,
routes routes,
}) });
export default router export default router;

View File

@ -1,40 +1,39 @@
import axios from 'axios'; import axios from 'axios';
import { apiBase } from '../store/modules/config'; import { apiBase } from '../store/modules/config';
export const apiStore = { store: null };
export const apiStore = {store: null}
export const api = axios.create({ export const api = axios.create({
baseURL: apiBase, baseURL: apiBase,
timeout: 1000, timeout: 1000,
withCredentials: true, withCredentials: true,
} });
)
api.interceptors.request.use((config) => { api.interceptors.request.use(
(config) => {
const custconfig = config; const custconfig = config;
// Merge custconfig dicts // Merge custconfig dicts
custconfig.headers = {...config.headers, ...apiStore.store.getters['user/apiAuth']}; custconfig.headers = { ...config.headers, ...apiStore.store.getters['user/apiAuth'] };
// Do something before request is sent // Do something before request is sent
// console.log(custconfig) // console.log(custconfig)
return custconfig; return custconfig;
}, (error) => Promise.reject(error) },
(error) => Promise.reject(error),
); );
api.interceptors.response.use((response) => { api.interceptors.response.use(
return response; (response) => response,
} (err) => {
,(err) => {
// console.log(err.response.status); // console.log(err.response.status);
console.log(err); console.log(err);
if (err.response && err.response.status === 401) { if (err.response && err.response.status === 401) {
console.log("Dispatching refresh_token...") console.log('Dispatching refresh_token...');
apiStore.store.dispatch('user/refresh_token') apiStore.store.dispatch('user/refresh_token');
// maybe redirect to /login if needed ! // maybe redirect to /login if needed !
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
reject(err); reject(err);
}); });
// // return Promise.reject(err); // // return Promise.reject(err);
} },
); );

View File

@ -1,5 +1,5 @@
import Vue from 'vue' import Vue from 'vue';
import Vuex from 'vuex' import Vuex from 'vuex';
import axios from 'axios'; import axios from 'axios';
import ftbotModule from './modules/ftbot'; import ftbotModule from './modules/ftbot';
@ -8,12 +8,10 @@ import alertsModule from './modules/alerts';
import { apiBase } from './modules/config'; import { apiBase } from './modules/config';
Vue.use(Vuex) Vue.use(Vuex);
export default new Vuex.Store({ export default new Vuex.Store({
state: { state: {},
},
modules: { modules: {
ftbot: ftbotModule, ftbot: ftbotModule,
user: userModule, user: userModule,
@ -23,28 +21,28 @@ export default new Vuex.Store({
setPing(state, ping) { setPing(state, ping) {
console.log(ping); console.log(ping);
const now = Date(Date.now()); const now = Date(Date.now());
state.ping = `${ping.status} ${now.toString()}` ; state.ping = `${ping.status} ${now.toString()}`;
} },
}, },
actions: { actions: {
ping({ commit }) { ping({ commit }) {
axios.get(`${apiBase}/ping`) axios
.get(`${apiBase}/ping`)
.then((result) => commit('setPing', result.data)) .then((result) => commit('setPing', result.data))
.catch(console.error); .catch(console.error);
}, },
refreshAll({dispatch}) { refreshAll({ dispatch }) {
dispatch('refreshFrequent'); dispatch('refreshFrequent');
dispatch('refreshSlow'); dispatch('refreshSlow');
dispatch('ftbot/getDaily'); dispatch('ftbot/getDaily');
dispatch('ftbot/getBalance'); dispatch('ftbot/getBalance');
}, },
refreshSlow({ dispatch }) { refreshSlow({ dispatch }) {
// dispatch('ftbot/getDaily'); // dispatch('ftbot/getDaily');
dispatch('ftbot/getPerformance'); dispatch('ftbot/getPerformance');
dispatch('ftbot/getProfit'); dispatch('ftbot/getProfit');
}, },
refreshFrequent({dispatch}) { refreshFrequent({ dispatch }) {
// Refresh all data // Refresh all data
dispatch('ftbot/getOpentrades'); dispatch('ftbot/getOpentrades');
dispatch('ftbot/getState'); dispatch('ftbot/getState');
@ -52,5 +50,5 @@ export default new Vuex.Store({
dispatch('ftbot/getWhitelist'); dispatch('ftbot/getWhitelist');
dispatch('ftbot/getBlacklist'); dispatch('ftbot/getBlacklist');
}, },
} },
}) });

View File

@ -1,21 +1,20 @@
export default { export default {
namespaced: true, namespaced: true,
state: { state: {
activeMessages: [], activeMessages: [],
}, },
mutations: { mutations: {
addAlert(state, message){ addAlert(state, message) {
console.log(`adding message '${message.message}' to message queue`) console.log(`adding message '${message.message}' to message queue`);
state.activeMessages.push(message) state.activeMessages.push(message);
}, },
removeAlert(state) { removeAlert(state) {
state.activeMessages.shift() state.activeMessages.shift();
} },
}, },
actions: { actions: {
addAlert({commit}, message) { addAlert({ commit }, message) {
commit('addAlert', message) commit('addAlert', message);
} },
} },
} };

View File

@ -1,6 +1,5 @@
const apiBase = '/api/v1'; const apiBase = '/api/v1';
module.exports = { module.exports = {
apiBase apiBase,
} };

View File

@ -21,7 +21,7 @@ export default {
}, },
closedtrades(state) { closedtrades(state) {
return state.trades.filter((item) => !item.is_open); return state.trades.filter((item) => !item.is_open);
} },
}, },
mutations: { mutations: {
updateTrades(state, trades) { updateTrades(state, trades) {
@ -55,87 +55,99 @@ export default {
}, },
actions: { actions: {
getTrades({ commit }) { getTrades({ commit }) {
console.log("fetching trades") console.log('fetching trades');
return api.get('/trades') return api
.get('/trades')
.then((result) => commit('updateTrades', result.data)) .then((result) => commit('updateTrades', result.data))
.catch(console.error); .catch(console.error);
}, },
getOpentrades({ commit }) { getOpentrades({ commit }) {
return api.get(`/status`) return api
.get('/status')
.then((result) => commit('updateOpenTrades', result.data)) .then((result) => commit('updateOpenTrades', result.data))
.catch(console.error); .catch(console.error);
}, },
getPerformance({ commit }) { getPerformance({ commit }) {
return api.get(`/performance`) return api
.get('/performance')
.then((result) => commit('updatePerformance', result.data)) .then((result) => commit('updatePerformance', result.data))
.catch(console.error); .catch(console.error);
}, },
getWhitelist({ commit }) { getWhitelist({ commit }) {
return api.get(`/whitelist`) return api
.get('/whitelist')
.then((result) => commit('updateWhitelist', result.data)) .then((result) => commit('updateWhitelist', result.data))
.catch(console.error); .catch(console.error);
}, },
getBlacklist({ commit }) { getBlacklist({ commit }) {
return api.get(`/blacklist`) return api
.get('/blacklist')
.then((result) => commit('updateBlacklist', result.data)) .then((result) => commit('updateBlacklist', result.data))
.catch(console.error); .catch(console.error);
}, },
getProfit({ commit }) { getProfit({ commit }) {
return api.get(`/profit`) return api
.get('/profit')
.then((result) => commit('updateProfit', result.data)) .then((result) => commit('updateProfit', result.data))
.catch(console.error); .catch(console.error);
}, },
getBalance({ commit }) { getBalance({ commit }) {
return api.get(`/balance`) return api
.get('/balance')
.then((result) => commit('updateBalance', result.data)) .then((result) => commit('updateBalance', result.data))
.catch(console.error); .catch(console.error);
}, },
getDaily({ commit }) { getDaily({ commit }) {
return api.get(`/daily`) return api
.get('/daily')
.then((result) => commit('updateDaily', result.data)) .then((result) => commit('updateDaily', result.data))
.catch(console.error); .catch(console.error);
}, },
getState({ commit }) { getState({ commit }) {
return api.get(`/show_config`) return api
.get('/show_config')
.then((result) => commit('updateState', result.data)) .then((result) => commit('updateState', result.data))
.catch(console.error); .catch(console.error);
}, },
// Post methods // Post methods
// TODO: Migrate calls to API to a seperate module unrelated to vuex? // TODO: Migrate calls to API to a seperate module unrelated to vuex?
startBot() { startBot() {
return api.post(`/start`, {}) return api.post('/start', {}).catch(console.error);
.catch(console.error);
}, },
stopBot() { stopBot() {
return api.post(`/stop`, {}) return api.post('/stop', {}).catch(console.error);
.catch(console.error);
}, },
stopBuy() { stopBuy() {
return api.post(`/stopbuy`, {}) return api.post('/stopbuy', {}).catch(console.error);
.catch(console.error);
}, },
reloadConfig() { reloadConfig() {
return api.post(`/reload_conf`, {}) return api.post('/reload_conf', {}).catch(console.error);
.catch(console.error);
}, },
forcesell({ dispatch }, tradeid) { forcesell({ dispatch }, tradeid) {
console.log(tradeid); console.log(tradeid);
if (tradeid) { if (tradeid) {
const payload = { tradeid }; const payload = { tradeid };
console.log(payload); console.log(payload);
return api.post(`/forcesell`, payload).then(() => { return api
dispatch('alerts/addAlert', { message: `Sell order for ${tradeid} created` }, { root: true }) .post('/forcesell', payload)
}).catch((error) => { .then(() => {
console.error(error.response) dispatch(
dispatch('alerts/addAlert', { message: `Failed to create sell order for ${tradeid}`, severity: 'danger' }, { root: true }) 'alerts/addAlert',
{ message: `Sell order for ${tradeid} created` },
{ root: true },
);
}) })
.catch((error) => {
console.error(error.response);
dispatch(
'alerts/addAlert',
{ message: `Failed to create sell order for ${tradeid}`, severity: 'danger' },
{ root: true },
);
});
} }
// Error branchs // Error branchs
const error = "Tradeid is empty"; const error = 'Tradeid is empty';
console.error(error); console.error(error);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
reject(error); reject(error);
@ -144,22 +156,33 @@ export default {
forcebuy({ dispatch }, payload) { forcebuy({ dispatch }, payload) {
console.log(payload); console.log(payload);
if (payload && payload.pair) { if (payload && payload.pair) {
return api
return api.post(`/forcebuy`, payload).then(() => { .post('/forcebuy', payload)
dispatch('alerts/addAlert', { message: `Buy order for ${payload.pair} created.` }, { root: true }) .then(() => {
}).catch((error) => { dispatch(
console.error(error.response) 'alerts/addAlert',
dispatch('alerts/addAlert', { message: `Error occured buying: '${error.response.data.error}'`, severity: 'danger' }, { root: true }) { message: `Buy order for ${payload.pair} created.` },
{ root: true },
);
}) })
.catch((error) => {
console.error(error.response);
dispatch(
'alerts/addAlert',
{
message: `Error occured buying: '${error.response.data.error}'`,
severity: 'danger',
},
{ root: true },
);
});
} }
// Error branchs // Error branchs
const error = "Pair is empty"; const error = 'Pair is empty';
console.error(error); console.error(error);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
reject(error); reject(error);
}); });
}, },
}, },
}; };

View File

@ -16,14 +16,13 @@ export default {
getters: { getters: {
apiAuth(state) { apiAuth(state) {
// const token = JSON.parse(localStorage.getItem('auth')); // const token = JSON.parse(localStorage.getItem('auth'));
let result = {} let result = {};
if (state.accessToken) { if (state.accessToken) {
result = { result = {
Authorization: `Bearer ${state.accessToken}`, Authorization: `Bearer ${state.accessToken}`,
}; };
} } else {
else { console.log('user not logged in');
console.log("user not logged in");
} }
return result; return result;
}, },
@ -43,21 +42,26 @@ export default {
state.loggedIn = true; state.loggedIn = true;
}, },
logout(state) { logout(state) {
console.log("Logging out"); console.log('Logging out');
localStorage.removeItem(AUTH_REF_TOKEN); localStorage.removeItem(AUTH_REF_TOKEN);
localStorage.removeItem(AUTH_ACCESS_TOKEN); localStorage.removeItem(AUTH_ACCESS_TOKEN);
state.auth = null; state.auth = null;
state.loggedIn = false; state.loggedIn = false;
} },
}, },
actions: { actions: {
login({ commit }, auth) { login({ commit }, auth) {
// Login using username / password // Login using username / password
console.log(auth); console.log(auth);
axios.post(`${apiBase}/token/login`, {}, { axios
auth: { ...auth } .post(
}) `${apiBase}/token/login`,
{},
{
auth: { ...auth },
},
)
.then((result) => { .then((result) => {
console.log(result.data); console.log(result.data);
@ -66,21 +70,25 @@ export default {
// commit('setLogin'); // commit('setLogin');
// } // }
if (result.data.access_token) { if (result.data.access_token) {
commit('setAccessTokens', result.data.access_token) commit('setAccessTokens', result.data.access_token);
} }
if (result.data.refresh_token) { if (result.data.refresh_token) {
commit('setRefreshTokens', result.data.refresh_token) commit('setRefreshTokens', result.data.refresh_token);
} }
}) })
.catch(console.error); .catch(console.error);
}, },
refresh_token({ commit, dispatch }) { refresh_token({ commit, dispatch }) {
console.log("Refreshing token...") console.log('Refreshing token...');
const token = JSON.parse(localStorage.getItem(AUTH_REF_TOKEN)); const token = JSON.parse(localStorage.getItem(AUTH_REF_TOKEN));
axios.post(`${apiBase}/token/refresh`, {}, { axios
.post(
`${apiBase}/token/refresh`,
{},
{
headers: { Authorization: `Bearer ${token}` }, headers: { Authorization: `Bearer ${token}` },
},
}) )
.then((result) => { .then((result) => {
if (result.data.access_token) { if (result.data.access_token) {
commit('setAccessTokens', result.data.access_token); commit('setAccessTokens', result.data.access_token);
@ -95,10 +103,8 @@ export default {
logout({ commit, state }) { logout({ commit, state }) {
if (state.loggedIn) { if (state.loggedIn) {
commit('logout'); commit('logout');
} } else {
else {
console.log('Not logged in'); console.log('Not logged in');
} }
}, },

View File

@ -62,7 +62,14 @@ import DailyStats from '@/components/ftbot/DailyStats.vue';
export default { export default {
name: 'Trade', name: 'Trade',
components: { TradeList, Performance, BotControls, BotStatus, Balance, DailyStats }, components: {
TradeList,
Performance,
BotControls,
BotStatus,
Balance,
DailyStats,
},
created() { created() {
this.refreshAll(); this.refreshAll();
}, },
@ -81,7 +88,7 @@ export default {
...mapActions(['refreshSlow', 'refreshFrequent', 'refreshAll']), ...mapActions(['refreshSlow', 'refreshFrequent', 'refreshAll']),
// ...mapActions('ftbot', ['getTrades', 'getProfit', 'getState']), // ...mapActions('ftbot', ['getTrades', 'getProfit', 'getState']),
startRefresh() { startRefresh() {
console.log(`Starting automatic refresh.`); console.log('Starting automatic refresh.');
this.refreshFrequent(); this.refreshFrequent();
this.refresh_interval = setInterval(() => { this.refresh_interval = setInterval(() => {
this.refreshFrequent(); this.refreshFrequent();
@ -92,7 +99,7 @@ export default {
}, 60000); }, 60000);
}, },
stopRefresh() { stopRefresh() {
console.log(`Stopping automatic refresh.`); console.log('Stopping automatic refresh.');
clearInterval(this.refresh_interval); clearInterval(this.refresh_interval);
clearInterval(this.refresh_interval_slow); clearInterval(this.refresh_interval_slow);
}, },