diff --git a/.eslintrc.js b/.eslintrc.js index 95190bd1..9df31e3e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -46,6 +46,7 @@ module.exports = { // https://eslint.vuejs.org/user-guide/#why-doesn-t-it-work-on-vue-file // required to lint *.vue files 'vue', + 'unused-imports', ], globals: { @@ -145,5 +146,16 @@ module.exports = { 'vue/component-options-name-casing': ['error', 'PascalCase'], 'vue/component-definition-name-casing': ['error', 'PascalCase'], 'vue/component-name-in-template-casing': ['error', 'PascalCase'], + 'no-unused-vars': 'off', + 'unused-imports/no-unused-imports': 'error', + 'unused-imports/no-unused-vars': [ + 'warn', + { + 'vars': 'all', + 'varsIgnorePattern': '^_', + 'args': 'after-used', + 'argsIgnorePattern': '^_' + } + ], } } diff --git a/package.json b/package.json index d4658e1d..6021a9fd 100644 --- a/package.json +++ b/package.json @@ -24,18 +24,18 @@ "highcharts-vue": "^1.4.0", "moment": "^2.29.4", "ol": "^6.14.1", + "pinia": "^2.1.6", "quasar": "^2.6.2", "ual-anchor": "1.3.0", "universal-authenticator-library": "^0.3.0", - "vue": "^3.0.0", - "vue-class-component": "^7.2.6", + "vue": "^3.3.0", "vue-json-viewer": "^3.0.4", "vue-router": "^4.0.0", - "vue3-openlayers": "^0.1.63", - "vuex": "^4.0.1" + "vue3-openlayers": "^0.1.63" }, "devDependencies": { "@babel/eslint-parser": "^7.13.14", + "@pinia/testing": "^0.1.3", "@quasar/app-webpack": "^3.5.3", "@quasar/quasar-app-extension-testing-unit-jest": "^3.0.0-alpha.10", "@types/jest": "^27.4.0", @@ -45,6 +45,7 @@ "dotenv": "^14.3.0", "eslint": "^7.14.0", "eslint-plugin-jest": "^25.2.2", + "eslint-plugin-unused-imports": "^3.0.0", "eslint-plugin-vue": "^9.0.0", "node-polyfill-webpack-plugin": "^1.1.4", "vue-property-decorator": "^9.1.2" diff --git a/quasar.conf.js b/quasar.conf.js index 30c97181..9c5eea74 100644 --- a/quasar.conf.js +++ b/quasar.conf.js @@ -30,7 +30,7 @@ module.exports = configure(function (ctx) { // app boot file (/src/boot) // --> boot files are part of "main.js" // https://quasar.dev/quasar-cli/boot-files - boot: ['config', 'axios', 'fathom', 'api', 'ual', 'fuel'], + boot: ['config', 'fathom', 'api', 'ual', 'fuel'], // https://quasar.dev/quasar-cli/quasar-conf-js#Property%3A-css css: ['app.sass'], diff --git a/src/api/hyperion.ts b/src/api/hyperion.ts index a5e61b7f..ab1e4aa8 100644 --- a/src/api/hyperion.ts +++ b/src/api/hyperion.ts @@ -38,15 +38,6 @@ const name = chain.getName(); const url = `https://raw.githubusercontent.com/telosnetwork/token-list/main/tokens.${name}.json`; -const tokenListPromise = fetch(url) - .then(response => response.text()) - .then((fileContent: string) => JSON.parse(fileContent) as { account: string }[]) - .then(originals => originals.map(token => token as unknown as Token)) - .catch((error) => { - console.error(error); - return []; - }); - const MAX_REQUESTS_COUNT = 5; const INTERVAL_MS = 10; let PENDING_REQUESTS = 0; @@ -97,23 +88,30 @@ export const getCreator = async function (address: string): Promise { - if (address) { - const response = await hyperion.get('v2/state/get_tokens', { - params: { account: address }, - }); - const tokens = await tokenListPromise; - const balances = (response.data as {tokens:Token[]}).tokens; - return balances.map((token:Token) => { - const tk = tokens.find((t:Token) => t.symbol === token.symbol) as Token; - if (tk && tk.logo) { - token.logo = tk?.logo; - } else { - token.logo = DEFAULT_ICON; - } - return token; - }); - } else { - return await tokenListPromise; + try { + const tokens = await axios.get(url).then(response => response.data as Token[]); + + if (address) { + const response = await hyperion.get('v2/state/get_tokens', { + params: { account: address }, + }); + + const balances = (response.data as {tokens:Token[]}).tokens; + // return tokens; + return balances.map((token:Token) => { + const tk = tokens.find((t:Token) => t.symbol === token.symbol); + if (tk && tk.logo) { + token.logo = tk?.logo; + } else { + token.logo = DEFAULT_ICON; + } + return token; + }); + } else { + return tokens; + } + } catch(e) { + console.error(e); } }; diff --git a/src/boot/api.ts b/src/boot/api.ts index f52fee52..3a3bed68 100644 --- a/src/boot/api.ts +++ b/src/boot/api.ts @@ -2,7 +2,7 @@ import { boot } from 'quasar/wrappers'; import { ApiClient } from 'src/types/Api'; import { api } from 'src/api'; -declare module '@vue/runtime-core' { +declare module 'vue' { interface ComponentCustomProperties { $api: ApiClient; } diff --git a/src/boot/axios.ts b/src/boot/axios.ts deleted file mode 100644 index f94375a7..00000000 --- a/src/boot/axios.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { boot } from 'quasar/wrappers'; -import axios, { AxiosInstance } from 'axios'; -declare module '@vue/runtime-core' { - interface ComponentCustomProperties { - $axios: AxiosInstance; - } -} - -export default boot(({ app }) => { - app.config.globalProperties.$axios = axios; -}); diff --git a/src/components/AccountCard.vue b/src/components/AccountCard.vue index 87ec9bd6..0e7d28d4 100644 --- a/src/components/AccountCard.vue +++ b/src/components/AccountCard.vue @@ -1,14 +1,12 @@