From da774768278c46fbf98e17075d7d0cd151b13c0f Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Wed, 24 Aug 2022 21:51:45 +0800 Subject: [PATCH] add new Dashboard --- src/layouts/components/Navbar.vue | 16 +- src/libs/fetch.js | 12 + src/libs/utils.js | 4 +- src/router/index.js | 5 +- src/store/chains/index.js | 2 + src/views/Block.vue | 4 +- src/views/Dashboard.vue | 418 ++++++++++++++++++ src/views/GovernanceProposalView.vue | 2 +- src/views/OsmosisTrade.vue | 2 - src/views/{Summary.vue => Parameters.vue} | 63 +-- src/views/StakingValidator.vue | 130 +++--- src/views/Transaction.vue | 2 +- src/views/WalletAccountDetail.vue | 4 +- src/views/WalletAccounts.vue | 2 +- src/views/WalletVotes.vue | 4 +- .../{ => components}/ArrayFieldComponent.vue | 0 .../{ => components}/ObjectFieldComponent.vue | 0 .../charts}/ChartComponentDoughnut.vue | 2 +- .../charts}/ChartjsComponentBar.vue | 0 .../charts}/ChartjsComponentDoughnutChart.vue | 0 .../dashboard/DashboardAssetsComponent.vue} | 0 .../dashboard/DashboardCardHorizontal.vue | 51 +++ .../dashboard/DashboardCardVertical.vue | 49 ++ .../dashboard/DashboardPriceChart.vue} | 0 .../dashboard/DashboardPriceChart2.vue | 391 ++++++++++++++++ .../parameters/ParametersModuleComponent.vue} | 4 +- .../staking}/StakingAddressComponent.vue | 0 .../staking}/StakingCommissionComponent.vue | 0 .../staking}/StakingRewardComponent.vue | 0 29 files changed, 1022 insertions(+), 145 deletions(-) create mode 100644 src/views/Dashboard.vue rename src/views/{Summary.vue => Parameters.vue} (76%) rename src/views/{ => components}/ArrayFieldComponent.vue (100%) rename src/views/{ => components}/ObjectFieldComponent.vue (100%) rename src/views/{ => components/charts}/ChartComponentDoughnut.vue (99%) rename src/views/{ => components/charts}/ChartjsComponentBar.vue (100%) rename src/views/{ => components/charts}/ChartjsComponentDoughnutChart.vue (100%) rename src/views/{SummaryAssetsComponent.vue => components/dashboard/DashboardAssetsComponent.vue} (100%) create mode 100644 src/views/components/dashboard/DashboardCardHorizontal.vue create mode 100644 src/views/components/dashboard/DashboardCardVertical.vue rename src/views/{SummaryPriceChart.vue => components/dashboard/DashboardPriceChart.vue} (100%) create mode 100644 src/views/components/dashboard/DashboardPriceChart2.vue rename src/views/{SummaryParmetersComponent.vue => components/parameters/ParametersModuleComponent.vue} (95%) rename src/views/{ => components/staking}/StakingAddressComponent.vue (100%) rename src/views/{ => components/staking}/StakingCommissionComponent.vue (100%) rename src/views/{ => components/staking}/StakingRewardComponent.vue (100%) diff --git a/src/layouts/components/Navbar.vue b/src/layouts/components/Navbar.vue index a0303494..1286bb4b 100644 --- a/src/layouts/components/Navbar.vue +++ b/src/layouts/components/Navbar.vue @@ -255,16 +255,20 @@ export default { }, accounts() { let accounts = getLocalAccounts() || {} - accounts = Object.entries(accounts).map(v => ({ wallet: v[0], address: v[1].address.find(x => x.chain === this.selected_chain.chain_name) })) + accounts = Object.entries(accounts) + .map(v => ({ wallet: v[0], address: v[1].address.find(x => x.chain === this.selected_chain.chain_name) })) + .filter(v => v.address) - if (accounts.length > 0) { + // accounts > 0 and wallet not setted, pick the first one as default + if (accounts.length > 0 && accounts.findIndex(x => x.wallet === this.walletName) < 0) { this.updateDefaultWallet(accounts[0].wallet) } - return accounts.filter(x => x.address) - }, - }, - mounted() { + if (accounts.findIndex(x => x.wallet === this.walletName) < 0 && this.walletName !== 'Wallet') { + this.updateDefaultWallet(null) + } + return accounts + }, }, methods: { formatAddr(v) { diff --git a/src/libs/fetch.js b/src/libs/fetch.js index d8d61184..0e0c59c6 100644 --- a/src/libs/fetch.js +++ b/src/libs/fetch.js @@ -416,6 +416,10 @@ export default class ChainFetch { return this.get('/bank/balances/'.concat(address), config).then(data => commonProcess(data)) } + async getCommunityPool(config = null) { + return this.get('/cosmos/distribution/v1beta1/community_pool', config).then(data => commonProcess(data)) + } + async getAllIBCDenoms(config = null) { const conf = config || this.getSelectedConfig() const sdkVersion = conf.sdk_version @@ -470,6 +474,14 @@ export default class ChainFetch { return null } + async getCoinInfo(coin = null) { + const conf = this.getSelectedConfig() + if (conf.assets[0] && conf.assets[0].coingecko_id) { + return ChainFetch.fetch(' https://api.coingecko.com', `/api/v3/coins/${coin || conf.assets[0].coingecko_id}`) + } + return null + } + // CoinMarketCap static async fetchCoinMarketCap(url) { const host = 'https://price.ping.pub' diff --git a/src/libs/utils.js b/src/libs/utils.js index 012d5e1d..52fca449 100644 --- a/src/libs/utils.js +++ b/src/libs/utils.js @@ -439,9 +439,9 @@ export function formatNumber(count, withAbbr = false, decimals = 2) { return result } -export function tokenFormatter(tokens, denoms = {}) { +export function tokenFormatter(tokens, denoms = {}, decimal = 2) { if (Array.isArray(tokens)) { - return tokens.map(t => formatToken(t, denoms, 2)).join(', ') + return tokens.map(t => formatToken(t, denoms, decimal)).join(', ') } return formatToken(tokens, denoms, 2) } diff --git a/src/router/index.js b/src/router/index.js index a2fb44bd..94df354f 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -122,7 +122,7 @@ const router = new VueRouter({ path: '/:chain/', name: 'dashboard', alias: '/:chain', - component: () => import('@/views/Summary.vue'), + component: () => import('@/views/Dashboard.vue'), meta: { pageTitle: 'Home', breadcrumb: [ @@ -136,7 +136,7 @@ const router = new VueRouter({ { path: '/:chain/parameters', name: 'parameters', - component: () => import('@/views/Summary.vue'), + component: () => import('@/views/Parameters.vue'), meta: { pageTitle: 'Parameters', breadcrumb: [ @@ -400,7 +400,6 @@ router.beforeEach((to, from, next) => { const c = to.params.chain if (c) { store.commit('select', { chain_name: String(c).toLowerCase() }) - store.dispatch('chains/getAllIBCDenoms', Vue.prototype) } const config = JSON.parse(localStorage.getItem('chains')) diff --git a/src/store/chains/index.js b/src/store/chains/index.js index 2b2b1238..8d766933 100644 --- a/src/store/chains/index.js +++ b/src/store/chains/index.js @@ -70,6 +70,8 @@ export default { if (defaultWallet && defaultWallet.length > 0) { localStorage.setItem('default-wallet', defaultWallet) state.chains.defaultWallet = defaultWallet + } else { + state.chains.defaultWallet = null } }, setIBCDenoms(state, denoms) { diff --git a/src/views/Block.vue b/src/views/Block.vue index 9f07fac8..d7c2be38 100644 --- a/src/views/Block.vue +++ b/src/views/Block.vue @@ -47,8 +47,8 @@ import { fromBase64 } from '@cosmjs/encoding' import { decodeTxRaw } from '@cosmjs/proto-signing' import Tx from '@/libs/data/tx' import { abbrMessage, tokenFormatter } from '@/libs/utils' -import ObjectFieldComponent from './ObjectFieldComponent.vue' -import ArrayFieldComponent from './ArrayFieldComponent.vue' +import ObjectFieldComponent from './components/ObjectFieldComponent.vue' +import ArrayFieldComponent from './components/ArrayFieldComponent.vue' export default { components: { diff --git a/src/views/Dashboard.vue b/src/views/Dashboard.vue new file mode 100644 index 00000000..92832987 --- /dev/null +++ b/src/views/Dashboard.vue @@ -0,0 +1,418 @@ + + + + + No new blocks have been produced since {{ latestTime }} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Active Proposals + + + + + + + {{ prop.id }} + + + + + {{ prop.title }} + + {{ formatType(prop.contents['@type']) }} {{ formatEnding(prop.voting_end_time) }} + + + + + No active proposal! + + Browse all + + + + + + + + + + + + + + + + + + + + + + + + Connect Wallet + + + + + + + + diff --git a/src/views/GovernanceProposalView.vue b/src/views/GovernanceProposalView.vue index 745f6364..5f2d1ec4 100644 --- a/src/views/GovernanceProposalView.vue +++ b/src/views/GovernanceProposalView.vue @@ -278,7 +278,7 @@ import { import { Proposal, Proposer } from '@/libs/data' import dayjs from 'dayjs' import OperationModal from '@/views/components/OperationModal/index.vue' -import ObjectFieldComponent from './ObjectFieldComponent.vue' +import ObjectFieldComponent from './components/ObjectFieldComponent.vue' // import { formatToken } from '@/libs/data/data' diff --git a/src/views/OsmosisTrade.vue b/src/views/OsmosisTrade.vue index 42bb1576..db599b59 100644 --- a/src/views/OsmosisTrade.vue +++ b/src/views/OsmosisTrade.vue @@ -118,7 +118,6 @@ import { formatTokenDenom } from '@/libs/utils' import FeatherIcon from '@/@core/components/feather-icon/FeatherIcon.vue' import Place from './components/KlineTrade/Place.vue' // import Kline from './components/kline/index.vue' -import SummaryPriceChart from './SummaryPriceChart.vue' export default { components: { @@ -130,7 +129,6 @@ export default { BSpinner, Place, BCard, - SummaryPriceChart, FeatherIcon, }, beforeRouteUpdate(to, from, next) { diff --git a/src/views/Summary.vue b/src/views/Parameters.vue similarity index 76% rename from src/views/Summary.vue rename to src/views/Parameters.vue index 8d804763..67e00162 100644 --- a/src/views/Summary.vue +++ b/src/views/Parameters.vue @@ -10,50 +10,32 @@ - - - - - - - - + - + - - - - - - + - + - + - + @@ -64,12 +46,10 @@ import { BRow, BCol, BAlert, BCard, } from 'bootstrap-vue' import { - formatNumber, formatTokenAmount, getUserCurrency, isToken, percent, timeIn, toDay, toDuration, tokenFormatter, + formatNumber, formatTokenAmount, isToken, percent, timeIn, toDay, toDuration, tokenFormatter, } from '@/libs/utils' -import SummaryParmetersComponent from './SummaryParmetersComponent.vue' -import SummaryAssetsComponent from './SummaryAssetsComponent.vue' -import SummaryPriceChart from './SummaryPriceChart.vue' +import ParametersModuleComponent from './components/parameters/ParametersModuleComponent.vue' export default { components: { @@ -77,9 +57,7 @@ export default { BCol, BAlert, BCard, - SummaryParmetersComponent, - SummaryAssetsComponent, - SummaryPriceChart, + ParametersModuleComponent, }, data() { return { @@ -118,29 +96,6 @@ export default { }, } }, - computed: { - marketChartData() { - if (this.marketData && this.marketData.prices) { - const labels = this.marketData.prices.map(x => x[0]) - const data = this.marketData.prices.map(x => x[1]) - return { - labels, - datasets: [ - { - label: `Price (${getUserCurrency().toUpperCase()})`, - data, - backgroundColor: 'rgba(54, 162, 235, 0.2)', - borderColor: 'rgba(54, 162, 235, 1)', - borderWidth: 1, - pointStyle: 'dash', - barThickness: 15, - }, - ], - } - } - return null - }, - }, created() { this.$http.getLatestBlock().then(res => { const height = this.chain.items.findIndex(x => x.subtitle === 'height') diff --git a/src/views/StakingValidator.vue b/src/views/StakingValidator.vue index 288d461a..34689815 100644 --- a/src/views/StakingValidator.vue +++ b/src/views/StakingValidator.vue @@ -204,70 +204,68 @@ - - - - - - - + + + + + + + + + + + + + + + + + {{ data.item.height }} + + + + + {{ formatHash(data.item.txhash) }} + + + + - - - - - - - - - - - - {{ data.item.height }} - - - - - {{ formatHash(data.item.txhash) }} - - - - - - - - + + + @@ -158,7 +158,7 @@ import { } from '@/libs/utils' import dayjs from 'dayjs' import WalletUpgradeEvents from './WalletUpgradeEvents.vue' -import ObjectFieldComponent from './ObjectFieldComponent.vue' +import ObjectFieldComponent from './components/ObjectFieldComponent.vue' export default { components: { diff --git a/src/views/ArrayFieldComponent.vue b/src/views/components/ArrayFieldComponent.vue similarity index 100% rename from src/views/ArrayFieldComponent.vue rename to src/views/components/ArrayFieldComponent.vue diff --git a/src/views/ObjectFieldComponent.vue b/src/views/components/ObjectFieldComponent.vue similarity index 100% rename from src/views/ObjectFieldComponent.vue rename to src/views/components/ObjectFieldComponent.vue diff --git a/src/views/ChartComponentDoughnut.vue b/src/views/components/charts/ChartComponentDoughnut.vue similarity index 99% rename from src/views/ChartComponentDoughnut.vue rename to src/views/components/charts/ChartComponentDoughnut.vue index d2680cfd..f4d3e2c9 100644 --- a/src/views/ChartComponentDoughnut.vue +++ b/src/views/components/charts/ChartComponentDoughnut.vue @@ -12,7 +12,7 @@ import { percent } from '@/libs/utils' import { $themeColors } from '@themeConfig' -import ChartjsComponentDoughnutChart from './ChartjsComponentDoughnutChart.vue' +import ChartjsComponentDoughnutChart from './ChartjsComponentDoughnutChart' export default { name: 'ChartDoughnut', diff --git a/src/views/ChartjsComponentBar.vue b/src/views/components/charts/ChartjsComponentBar.vue similarity index 100% rename from src/views/ChartjsComponentBar.vue rename to src/views/components/charts/ChartjsComponentBar.vue diff --git a/src/views/ChartjsComponentDoughnutChart.vue b/src/views/components/charts/ChartjsComponentDoughnutChart.vue similarity index 100% rename from src/views/ChartjsComponentDoughnutChart.vue rename to src/views/components/charts/ChartjsComponentDoughnutChart.vue diff --git a/src/views/SummaryAssetsComponent.vue b/src/views/components/dashboard/DashboardAssetsComponent.vue similarity index 100% rename from src/views/SummaryAssetsComponent.vue rename to src/views/components/dashboard/DashboardAssetsComponent.vue diff --git a/src/views/components/dashboard/DashboardCardHorizontal.vue b/src/views/components/dashboard/DashboardCardHorizontal.vue new file mode 100644 index 00000000..477cb341 --- /dev/null +++ b/src/views/components/dashboard/DashboardCardHorizontal.vue @@ -0,0 +1,51 @@ + + + + + + {{ statistic }} + + {{ statisticTitle }} + + + + + + + + + diff --git a/src/views/components/dashboard/DashboardCardVertical.vue b/src/views/components/dashboard/DashboardCardVertical.vue new file mode 100644 index 00000000..8d94ab0b --- /dev/null +++ b/src/views/components/dashboard/DashboardCardVertical.vue @@ -0,0 +1,49 @@ + + + + + + + + {{ statistic }} + + {{ statisticTitle }} + + + + + diff --git a/src/views/SummaryPriceChart.vue b/src/views/components/dashboard/DashboardPriceChart.vue similarity index 100% rename from src/views/SummaryPriceChart.vue rename to src/views/components/dashboard/DashboardPriceChart.vue diff --git a/src/views/components/dashboard/DashboardPriceChart2.vue b/src/views/components/dashboard/DashboardPriceChart2.vue new file mode 100644 index 00000000..40fce8b9 --- /dev/null +++ b/src/views/components/dashboard/DashboardPriceChart2.vue @@ -0,0 +1,391 @@ + + + + + + + {{ coinInfo.name }} ({{ coinInfo.symbol }}) + + Coingecko Rank: + #{{ coinInfo.coingecko_rank }} + + + + + + {{ tag }} + + + + + + + + + + {{ pair.market.name }} + + + {{ coinInfo.symbol }}/{{ pair.target }} + + + ${{ pair.converted_last.usd }} + + + + + + + $ + + + {{ selectedTicker.converted_last.usd }} + + / {{ selectedTicker.target }} + + + + + Buy {{ String(coinInfo.symbol).toUpperCase() }} + + + + + + + + + Price + + + Volumes + + + + + + Daily + + + Weekly + + + Monthly + + + + + + + + + + + + + {{ coinInfo.description.en || '' }} + + + LINKS: + + Webwite + + + Twitter + + + Github + + + Telegram + + + {{ site }} + + + + + + + diff --git a/src/views/SummaryParmetersComponent.vue b/src/views/components/parameters/ParametersModuleComponent.vue similarity index 95% rename from src/views/SummaryParmetersComponent.vue rename to src/views/components/parameters/ParametersModuleComponent.vue index 8b6d37bc..55656c66 100644 --- a/src/views/SummaryParmetersComponent.vue +++ b/src/views/components/parameters/ParametersModuleComponent.vue @@ -85,8 +85,8 @@ import { BCard, BCardHeader, BCardTitle, BCardText, BCardBody, BRow, BCol, BMedia, BMediaAside, BAvatar, BMediaBody, BPopover, BButton, } from 'bootstrap-vue' -import ObjectFieldComponent from './ObjectFieldComponent.vue' -import ArrayFieldComponent from './ArrayFieldComponent.vue' +import ObjectFieldComponent from '../ObjectFieldComponent.vue' +import ArrayFieldComponent from '../ArrayFieldComponent.vue' export default { components: { diff --git a/src/views/StakingAddressComponent.vue b/src/views/components/staking/StakingAddressComponent.vue similarity index 100% rename from src/views/StakingAddressComponent.vue rename to src/views/components/staking/StakingAddressComponent.vue diff --git a/src/views/StakingCommissionComponent.vue b/src/views/components/staking/StakingCommissionComponent.vue similarity index 100% rename from src/views/StakingCommissionComponent.vue rename to src/views/components/staking/StakingCommissionComponent.vue diff --git a/src/views/StakingRewardComponent.vue b/src/views/components/staking/StakingRewardComponent.vue similarity index 100% rename from src/views/StakingRewardComponent.vue rename to src/views/components/staking/StakingRewardComponent.vue