From e34a82402fed4093d03e91020926f407c21844af Mon Sep 17 00:00:00 2001
From: liangping <18786721@qq.com>
Date: Thu, 7 Oct 2021 21:25:33 +0800
Subject: [PATCH] Optimize quotes loading
---
src/App.vue | 2 +
src/lang/locales/en.json | 5 +-
src/libs/data/data.js | 38 ++++-
src/libs/fetch.js | 10 ++
src/libs/osmos.js | 11 ++
src/navigation/vertical/index.js | 15 +-
src/router/index.js | 20 ++-
src/store/chains/index.js | 12 +-
src/views/ChartComponentDoughnut.vue | 73 +++++++++
src/views/ChartjsComponentBar.vue | 31 ++++
src/views/OsmosisPools.vue | 110 +++++++++++++
src/views/StakingAddressComponent.vue | 2 +-
src/views/WalletAccountDetail.vue | 66 ++------
src/views/WalletAccounts.vue | 225 ++++++++++++++++++++++----
14 files changed, 533 insertions(+), 87 deletions(-)
create mode 100644 src/libs/osmos.js
create mode 100644 src/views/ChartComponentDoughnut.vue
create mode 100644 src/views/ChartjsComponentBar.vue
create mode 100644 src/views/OsmosisPools.vue
diff --git a/src/App.vue b/src/App.vue
index b63ef411..bbe1a1f7 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -94,6 +94,8 @@ export default {
store.commit('app/UPDATE_WINDOW_WIDTH', val)
})
+ store.dispatch('chains/getQuotes')
+
return {
skinClasses,
}
diff --git a/src/lang/locales/en.json b/src/lang/locales/en.json
index 16d5ba6a..0a7c267e 100644
--- a/src/lang/locales/en.json
+++ b/src/lang/locales/en.json
@@ -15,7 +15,7 @@
"regen": "Regen Network",
"secret": "Secret Network",
"desmos": "Desmos",
- "juno": "Juno Hera",
+ "juno": "Juno",
"certik": "Certik",
"sentinel": "Sentinel",
@@ -26,7 +26,8 @@
"blockchains": "Blockchains",
"uptime": "Uptime",
- "gravity": "Gravity",
+ "gravity": "Gravity(WIP)",
+ "pools": "Pools(WIP)",
"proposal_id": "Proposal ID",
"proposal_type": "Proposal Type",
diff --git a/src/libs/data/data.js b/src/libs/data/data.js
index 175194c3..89db9a97 100644
--- a/src/libs/data/data.js
+++ b/src/libs/data/data.js
@@ -13,6 +13,7 @@ import dayjs from 'dayjs'
import duration from 'dayjs/plugin/duration'
import relativeTime from 'dayjs/plugin/relativeTime'
import localeData from 'dayjs/plugin/localeData'
+import { $themeColors } from '@themeConfig'
dayjs.extend(localeData)
dayjs.extend(duration)
@@ -76,6 +77,41 @@ export function addressEnCode(prefix, pubkey) {
return Bech32.encode(prefix, pubkey)
}
+export function getUserCurrency() {
+ const currency = localStorage.getItem('currency')
+ return currency || 'usd'
+}
+
+export function setUserCurrency(currency) {
+ localStorage.setItem('currency', currency)
+}
+
+export function chartColors() {
+ const colors = ['#6610f2', '#20c997', '#000000', '#FF0000',
+ '#800000', '#FFFF00', '#808000', '#00FF00', '#008000', '#00FFFF',
+ '#008080', '#0000FF', '#000080', '#FF00FF', '#800080']
+ return Object.values($themeColors).concat(colors)
+}
+
+export function getUserCurrencySign() {
+ let s = ''
+ switch (getUserCurrency()) {
+ case 'cny':
+ case 'jpy':
+ s = '¥'
+ break
+ case 'krw':
+ s = '₩'
+ break
+ case 'eur':
+ s = '€'
+ break
+ default:
+ s = '$'
+ }
+ return s
+}
+
export function consensusPubkeyToHexAddress(consensusPubkey) {
let raw = null
if (typeof consensusPubkey === 'object') {
@@ -218,7 +254,7 @@ export function isToken(value) {
export function formatTokenDenom(tokenDenom) {
if (tokenDenom) {
- let denom = tokenDenom.toUpperCase()
+ let denom = tokenDenom.denom_trace ? tokenDenom.denom_trace.base_denom.toUpperCase() : tokenDenom.toUpperCase()
if (denom.charAt(0) === 'U') {
denom = denom.substring(1)
} else if (denom === 'BASECRO') {
diff --git a/src/libs/fetch.js b/src/libs/fetch.js
index e42e9ad6..9255ce42 100644
--- a/src/libs/fetch.js
+++ b/src/libs/fetch.js
@@ -328,6 +328,7 @@ const chainAPI = class ChainFetch {
return ChainFetch.fetchCoinMarketCap(`/quote/${symbol}`)
}
+ // Tx Submit
async broadcastTx(bodyBytes, config = null) {
const txString = toBase64(TxRaw.encode(bodyBytes).finish())
const txRaw = {
@@ -365,6 +366,15 @@ const chainAPI = class ChainFetch {
// const response = axios.post((config ? config.api : this.config.api) + url, data)
return response.json() // parses JSON response into native JavaScript objects
}
+
+ // Custom Module
+ async getOsmosisPools() {
+ return this.get('/osmosis/gamm/v1beta1/pools')
+ }
+
+ async getOsmosisIncentivesPools() {
+ return this.get('/osmosis/pool-incentives/v1beta1/incentivized_pools')
+ }
}
export default chainAPI
diff --git a/src/libs/osmos.js b/src/libs/osmos.js
new file mode 100644
index 00000000..84634c1c
--- /dev/null
+++ b/src/libs/osmos.js
@@ -0,0 +1,11 @@
+import fetch from 'node-fetch'
+
+export default class OsmosAPI {
+ static async get(url) {
+ return fetch(url)
+ }
+
+ static async getPools() {
+ return OsmosAPI.get('/osmosis/gamm/v1beta1/pools')
+ }
+}
diff --git a/src/navigation/vertical/index.js b/src/navigation/vertical/index.js
index 922fb012..7a1d8744 100644
--- a/src/navigation/vertical/index.js
+++ b/src/navigation/vertical/index.js
@@ -26,11 +26,16 @@ const modules = [
title: 'uptime',
route: 'uptime',
},
- // {
- // scope: 'cosmos',
- // title: 'gravity',
- // route: 'gravity',
- // },
+ {
+ scope: 'cosmos',
+ title: 'gravity',
+ route: 'gravity',
+ },
+ {
+ scope: 'osmosis',
+ title: 'pools',
+ route: 'osmosis-pool',
+ },
]
function processMenu() {
diff --git a/src/router/index.js b/src/router/index.js
index 39bd09b4..a4a2768f 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -258,8 +258,10 @@ const router = new VueRouter({
],
},
},
+ // custom modules for specified chains
+ // 1. cosmos
{
- path: '/cosmos/gravity',
+ path: '/:chain/cosmos/pools',
name: 'gravity',
component: () => import('@/views/GravityPool.vue'),
meta: {
@@ -272,6 +274,22 @@ const router = new VueRouter({
],
},
},
+ // 2. OSMOSIS
+ {
+ path: '/:chain/osmosis/pools',
+ name: 'osmosis-pool',
+ component: () => import('@/views/OsmosisPools.vue'),
+ meta: {
+ pageTitle: 'Pools',
+ breadcrumb: [
+ {
+ text: 'Pools',
+ active: true,
+ },
+ ],
+ },
+ },
+ // common modules
{
path: '/user/login',
name: 'login',
diff --git a/src/store/chains/index.js b/src/store/chains/index.js
index 09f191c7..66556fd0 100644
--- a/src/store/chains/index.js
+++ b/src/store/chains/index.js
@@ -48,6 +48,7 @@ export default {
avatars: {},
height: 0,
ibcChannels: {},
+ quotes: {},
},
getters: {
getchains: state => state.chains,
@@ -69,6 +70,15 @@ export default {
setChannels(state, { chain, channels }) {
state.chains.ibcChannels[chain] = channels
},
+ setQuotes(state, quotes) {
+ state.quotes = quotes
+ },
+ },
+ actions: {
+ async getQuotes(context) {
+ fetch('https://price.ping.pub/quotes').then(data => data.json()).then(data => {
+ context.commit('setQuotes', data)
+ })
+ },
},
- actions: {},
}
diff --git a/src/views/ChartComponentDoughnut.vue b/src/views/ChartComponentDoughnut.vue
new file mode 100644
index 00000000..172fbdc9
--- /dev/null
+++ b/src/views/ChartComponentDoughnut.vue
@@ -0,0 +1,73 @@
+
+
+ {{ data.height || '0' }}
+
+