From 6d37cf4df53e0dd6e094fc0b829d62e87a0a96b0 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Tue, 16 Nov 2021 11:26:27 +0800 Subject: [PATCH] add injective --- src/lang/locales/en.json | 1 + src/libs/data/data.js | 6 +++++- src/libs/fetch.js | 9 +++++++++ src/store/chains/injective.json | 8 ++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/store/chains/injective.json diff --git a/src/lang/locales/en.json b/src/lang/locales/en.json index c90fa2f5..d9cb564b 100644 --- a/src/lang/locales/en.json +++ b/src/lang/locales/en.json @@ -25,6 +25,7 @@ "omniflix": "OmniFlix", "likecoin": "LikeCoin", "stargaze": "Stargaze", + "injective": "Injective Protocal", "staking": "Staking", "governance": "Governance", diff --git a/src/libs/data/data.js b/src/libs/data/data.js index a095afb6..88ce163a 100644 --- a/src/libs/data/data.js +++ b/src/libs/data/data.js @@ -300,7 +300,11 @@ export function getUnitAmount(amount, denom) { export function formatTokenAmount(tokenAmount, fraction = 2, denom = 'uatom') { let amount - if (denom.startsWith('rowan')) { + if (denom.startsWith('inj')) { + // eslint-disable-next-line no-undef + amount = Number(BigInt(Number(tokenAmount)) / 1000000000000000000n) + // } + } else if (denom.startsWith('rowan')) { // eslint-disable-next-line no-undef amount = Number(BigInt(Number(tokenAmount)) / 1000000000000000000n) // } diff --git a/src/libs/fetch.js b/src/libs/fetch.js index 3cb6a0b8..48c3d904 100644 --- a/src/libs/fetch.js +++ b/src/libs/fetch.js @@ -49,10 +49,19 @@ export default class ChainFetch { } async getLatestBlock(config = null) { + const conf = config || this.getSelectedConfig() + console.log('config: ', conf) + if (conf.chain_name === 'injective') { + return ChainFetch.fetch('https://tm.injective.network', '/block').then(data => Block.create(commonProcess(data))) + } return this.get('/blocks/latest', config).then(data => Block.create(data)) } async getBlockByHeight(height, config = null) { + const conf = config || this.getSelectedConfig() + if (conf.chain_name === 'injective') { + return ChainFetch.fetch('https://tm.injective.network', `/block?height=${height}`).then(data => Block.create(commonProcess(data))) + } return this.get(`/blocks/${height}`, config).then(data => Block.create(data)) } diff --git a/src/store/chains/injective.json b/src/store/chains/injective.json new file mode 100644 index 00000000..e066086f --- /dev/null +++ b/src/store/chains/injective.json @@ -0,0 +1,8 @@ +{ + "chain_name": "injective", + "api": "https://lcd.injective.network", + "sdk_version": "0.42.4", + "addr_prefix": "inj", + "excludes": "", + "logo": "https://dl.airtable.com/.attachments/e024faae112ae873d301f9e1e17a921c/3f3671f7/9pOKAlQ5_400x400.jpg" +} \ No newline at end of file