From b5d52f1d9004cd8c3670db45fef988013f5068be Mon Sep 17 00:00:00 2001
From: liangping <18786721@qq.com>
Date: Mon, 9 Aug 2021 22:18:27 +0800
Subject: [PATCH] add onchain asset and band protocal
---
src/lang/locales/en.json | 1 +
src/libs/data/data.js | 4 +-
src/libs/fetch.js | 24 +++++++--
src/store/chains/band.json | 5 ++
src/store/chains/index.js | 16 ++++--
src/views/Home.vue | 29 ++++++-----
src/views/Staking.vue | 9 ++--
src/views/Summary.vue | 78 ++++++++++++++++++++++++++++
src/views/SummaryAssetsComponent.vue | 52 +++++++++++++++++++
9 files changed, 189 insertions(+), 29 deletions(-)
create mode 100644 src/store/chains/band.json
create mode 100644 src/views/SummaryAssetsComponent.vue
diff --git a/src/lang/locales/en.json b/src/lang/locales/en.json
index 2c931a12..7d87bf06 100644
--- a/src/lang/locales/en.json
+++ b/src/lang/locales/en.json
@@ -9,6 +9,7 @@
"crypto": "Crypto.com",
"osmosis": "Osmosis",
"okexchain": "OKEX Chain",
+ "band": "Band Protocal",
"staking": "Staking",
"governance": "Governance",
diff --git a/src/libs/data/data.js b/src/libs/data/data.js
index bf1cd07d..b07a9c4e 100644
--- a/src/libs/data/data.js
+++ b/src/libs/data/data.js
@@ -92,12 +92,12 @@ export function formatToken(token) {
return token
}
-const COUNT_ABBRS = ['', 'K', 'M', 'B', 'T', 'P', 'E', 'Z', 'Y']
+const COUNT_ABBRS = ['', 'K', 'M', 'B', 't', 'q', 's', 'S', 'o', 'n', 'd', 'U', 'D', 'T', 'Qt', 'Qd', 'Sd', 'St']
export function formatNumber(count, withAbbr = false, decimals = 2) {
const i = count === 0 ? count : Math.floor(Math.log(count) / Math.log(1000))
let result = parseFloat((count / (1000 ** i)).toFixed(decimals))
- if (withAbbr) {
+ if (withAbbr && COUNT_ABBRS[i]) {
result += `${COUNT_ABBRS[i]}`
}
return result
diff --git a/src/libs/fetch.js b/src/libs/fetch.js
index 9b5aadc1..f6b5386e 100644
--- a/src/libs/fetch.js
+++ b/src/libs/fetch.js
@@ -23,10 +23,16 @@ async function refetchVersion(chain) {
await fetch(`${chain.api}/node_info`)
.then(res => res.json())
.then(json => {
- const sdk = json.application_version.build_deps.find(e => e.startsWith('github.com/cosmos/cosmos-sdk'))
- const re = /(\d+(\.\d+)*)/i
- const version = sdk.match(re)
- return version[0]
+ const { build_deps } = json.application_version
+ // eslint-disable-next-line camelcase
+ if (build_deps) {
+ const sdk = build_deps.find(e => e.startsWith('github.com/cosmos/cosmos-sdk'))
+ const re = /(\d+(\.\d+)*)/i
+ const version = sdk.match(re)
+ // eslint-disable-next-line prefer-destructuring
+ return version[0]
+ }
+ return json.node_info.version
}).catch(() => null)
}
@@ -40,6 +46,9 @@ const chainAPI = class ChainFetch {
if (!chain.sdk_version) {
chain.sdk_version = refetchVersion(chain)
}
+ if (!chain.sdk_version) {
+ chain.sdk_version = '0.33'
+ }
this.config = chain
return this.config
}
@@ -87,6 +96,13 @@ const chainAPI = class ChainFetch {
return this.get(`/bank/total/${denom}`).then(data => commonProcess(data))
}
+ async getBankTotals() {
+ if (compareVersions(this.config.sdk_version, '0.40') < 0) {
+ return this.get('/supply/total').then(data => commonProcess(data))
+ }
+ return this.get('/cosmos/bank/v1beta1/supply').then(data => data.supply)
+ }
+
async getStakingPool() {
return this.get('/staking/pool').then(data => new StakingPool().init(commonProcess(data)))
}
diff --git a/src/store/chains/band.json b/src/store/chains/band.json
new file mode 100644
index 00000000..537bfa81
--- /dev/null
+++ b/src/store/chains/band.json
@@ -0,0 +1,5 @@
+{
+ "chain_name": "band",
+ "api": "https://api-gm-lb.bandchain.org",
+ "logo": "https://dl.airtable.com/.attachments/472ae99a508e32b4439b416beddd4eb9/c5166f62/band-symbol-blue-bg.75a3ad91.svg"
+}
\ No newline at end of file
diff --git a/src/store/chains/index.js b/src/store/chains/index.js
index 7a263a43..de696148 100644
--- a/src/store/chains/index.js
+++ b/src/store/chains/index.js
@@ -20,11 +20,17 @@ Object.keys(update).forEach(key => {
fetch(`${chain.api}/node_info`)
.then(res => res.json())
.then(json => {
- const sdk = json.application_version.build_deps.find(e => e.startsWith('github.com/cosmos/cosmos-sdk'))
- const re = /(\d+(\.\d+)*)/i
- const version = sdk.match(re)
- // eslint-disable-next-line prefer-destructuring
- chain.sdk_version = version[0]
+ const { build_deps } = json.application_version
+ // eslint-disable-next-line camelcase
+ if (build_deps) {
+ const sdk = build_deps.find(e => e.startsWith('github.com/cosmos/cosmos-sdk'))
+ const re = /(\d+(\.\d+)*)/i
+ const version = sdk.match(re)
+ // eslint-disable-next-line prefer-destructuring
+ chain.sdk_version = version[0]
+ } else {
+ chain.sdk_version = json.node_info.version
+ }
localStorage.setItem('chains', JSON.stringify(update))
})
})
diff --git a/src/views/Home.vue b/src/views/Home.vue
index 3842ec22..208ae296 100644
--- a/src/views/Home.vue
+++ b/src/views/Home.vue
@@ -10,7 +10,7 @@
@@ -18,14 +18,14 @@
+ Ping explorer is not just an explorer but also a wallet and more ... 🛠+
+- It's not just an explorer but also a wallet and more ... 🛠-
-