forked from LaconicNetwork/cosmos-explorer
normalize @/store imports
This commit is contained in:
parent
d1db35c2c1
commit
20325c05bb
@ -1,7 +1,14 @@
|
||||
import { useBlockchain, useCoingecko, useBaseStore, useBankStore, useFormatter, useGovStore } from '@/stores';
|
||||
import { useDistributionStore } from '@/stores/useDistributionStore';
|
||||
import { useMintStore } from '@/stores/useMintStore';
|
||||
import { useStakingStore } from '@/stores/useStakingStore';
|
||||
import {
|
||||
useBlockchain,
|
||||
useCoingecko,
|
||||
useBaseStore,
|
||||
useBankStore,
|
||||
useFormatter,
|
||||
useGovStore,
|
||||
useDistributionStore,
|
||||
useMintStore,
|
||||
useStakingStore,
|
||||
} from '@/stores';
|
||||
import type { Coin, Tally } from '@/types';
|
||||
import numeral from 'numeral';
|
||||
import { defineStore } from 'pinia';
|
||||
@ -157,9 +164,7 @@ export const useIndexModule = defineStore('module-index', {
|
||||
title: 'Validators',
|
||||
color: 'error',
|
||||
icon: 'mdi-human-queue',
|
||||
stats: String(
|
||||
base?.latest?.block?.last_commit?.signatures.length || 0
|
||||
),
|
||||
stats: String(base?.latest?.block?.last_commit?.signatures.length || 0),
|
||||
change: 0,
|
||||
},
|
||||
{
|
||||
@ -256,11 +261,7 @@ export const useIndexModule = defineStore('module-index', {
|
||||
* @param value - The value to set for the parameter.
|
||||
* @returns The new URL with the parameter added or replaced.
|
||||
*/
|
||||
export function addOrReplaceUrlParam(
|
||||
url: string,
|
||||
param: string,
|
||||
value: string
|
||||
): string {
|
||||
export function addOrReplaceUrlParam(url: string, param: string, value: string): string {
|
||||
// Parse the URL
|
||||
const urlObj = new URL(url, window.location.origin);
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { get } from '../libs/http';
|
||||
import type { LoadingStatus } from './useDashboard';
|
||||
import { get } from '@/libs/http';
|
||||
import type { LoadingStatus } from '@/stores';
|
||||
|
||||
export interface PriceMeta {
|
||||
usd?: string;
|
||||
@ -13,6 +13,8 @@ export interface PriceMeta {
|
||||
|
||||
const LocalStoreKey = 'currency';
|
||||
|
||||
export const coingeckoUrl = import.meta.env.VITE_COINGECKO_URL || 'https://api.coingecko.com';
|
||||
|
||||
export const useCoingecko = defineStore('coingecko', {
|
||||
state: () => {
|
||||
const currency = localStorage.getItem(LocalStoreKey);
|
||||
@ -27,11 +29,11 @@ export const useCoingecko = defineStore('coingecko', {
|
||||
|
||||
actions: {
|
||||
getMarketChart(days = 30, coinId = 'cosmos') {
|
||||
return get(`https://api.coingecko.com/api/v3/coins/${coinId}/market_chart?vs_currency=usd&days=${days}`);
|
||||
return get(`${coingeckoUrl}/api/v3/coins/${coinId}/market_chart?vs_currency=usd&days=${days}`);
|
||||
},
|
||||
|
||||
fetchCoinPrice(ids: string[]) {
|
||||
const url = `https://api.coingecko.com/api/v3/simple/price?include_24hr_change=true&vs_currencies=${[
|
||||
const url = `${coingeckoUrl}/api/v3/simple/price?include_24hr_change=true&vs_currencies=${[
|
||||
'usd',
|
||||
this.currency,
|
||||
].join(',')}&ids=${ids.join(',')}`;
|
||||
@ -40,7 +42,7 @@ export const useCoingecko = defineStore('coingecko', {
|
||||
});
|
||||
},
|
||||
getCoinInfo(coinId: string) {
|
||||
return get(`https://api.coingecko.com/api/v3/coins/${coinId}`);
|
||||
return get(`${coingeckoUrl}/api/v3/coins/${coinId}`);
|
||||
},
|
||||
setSecondaryCurrency(currency: string) {
|
||||
if (currency !== 'usd') {
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { get } from '../libs/http';
|
||||
import { get } from '@/libs/http';
|
||||
import type { ChainConfig, DirectoryChainConfig, Endpoint, LocalChainConfig } from '@/types/chaindata';
|
||||
import { ConfigSource, NetworkType } from '@/types/chaindata';
|
||||
import { useBlockchain } from './useBlockchain';
|
||||
|
||||
|
||||
import { coingeckoUrl } from '@/stores';
|
||||
|
||||
function apiConverter(api: any[]) {
|
||||
if (!api) return [];
|
||||
@ -37,15 +36,14 @@ export function convertFromLocal(lc: LocalChainConfig): ChainConfig {
|
||||
{ denom: x.base, exponent: 0 },
|
||||
{ denom: x.symbol.toLowerCase(), exponent: Number(x.exponent) },
|
||||
],
|
||||
type_asset: 'sdk.coin'
|
||||
type_asset: 'sdk.coin',
|
||||
}));
|
||||
}
|
||||
conf.versions = {
|
||||
cosmosSdk: lc.sdk_version,
|
||||
};
|
||||
conf.bech32Prefix = lc.addr_prefix;
|
||||
conf.bech32ConsensusPrefix =
|
||||
lc.consensus_prefix ?? lc.addr_prefix + 'valcons';
|
||||
conf.bech32ConsensusPrefix = lc.consensus_prefix ?? lc.addr_prefix + 'valcons';
|
||||
conf.chainName = lc.chain_name;
|
||||
conf.coinType = lc.coin_type;
|
||||
conf.prettyName = lc.registry_name || lc.chain_name;
|
||||
@ -138,7 +136,6 @@ export enum LoadingStatus {
|
||||
Loaded,
|
||||
}
|
||||
|
||||
|
||||
export const useDashboard = defineStore('dashboard', {
|
||||
state: () => {
|
||||
const favMap = JSON.parse(localStorage.getItem('favoriteMap') || '{"cosmos":true, "osmosis":true}');
|
||||
@ -184,7 +181,7 @@ export const useDashboard = defineStore('dashboard', {
|
||||
|
||||
const currencies = ['usd, cny']; // usd,cny,eur,jpy,krw,sgd,hkd
|
||||
get(
|
||||
`https://api.coingecko.com/api/v3/simple/price?include_24hr_change=true&vs_currencies=${currencies.join(
|
||||
`${coingeckoUrl}/api/v3/simple/price?include_24hr_change=true&vs_currencies=${currencies.join(
|
||||
','
|
||||
)}&ids=${coinIds.join(',')}`
|
||||
).then((x) => {
|
||||
@ -194,7 +191,7 @@ export const useDashboard = defineStore('dashboard', {
|
||||
async loadingFromRegistry() {
|
||||
if (this.status === LoadingStatus.Empty) {
|
||||
this.status = LoadingStatus.Loading;
|
||||
get(this.source).then((res) => {
|
||||
get(this.source).then((res: { chains: DirectoryChainConfig[] }) => {
|
||||
res.chains.forEach((x: DirectoryChainConfig) => {
|
||||
this.chains[x.chain_name] = convertFromDirectory(x);
|
||||
});
|
||||
@ -232,11 +229,7 @@ export const useDashboard = defineStore('dashboard', {
|
||||
const blockchain = useBlockchain();
|
||||
const keys = Object.keys(this.favoriteMap);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
if (
|
||||
!blockchain.chainName &&
|
||||
this.chains[keys[i]] &&
|
||||
this.favoriteMap[keys[i]]
|
||||
) {
|
||||
if (!blockchain.chainName && this.chains[keys[i]] && this.favoriteMap[keys[i]]) {
|
||||
blockchain.setCurrent(keys[i]);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { useBlockchain } from './useBlockchain';
|
||||
import { useBlockchain, useBankStore, useStakingStore, useDashboard } from '@/stores';
|
||||
import numeral from 'numeral';
|
||||
import dayjs from 'dayjs';
|
||||
import duration from 'dayjs/plugin/duration';
|
||||
@ -7,12 +7,9 @@ import relativeTime from 'dayjs/plugin/relativeTime';
|
||||
import updateLocale from 'dayjs/plugin/updateLocale';
|
||||
import utc from 'dayjs/plugin/utc';
|
||||
import localeData from 'dayjs/plugin/localeData';
|
||||
import { useStakingStore } from './useStakingStore';
|
||||
import { fromBase64, fromBech32, fromHex, toHex } from '@cosmjs/encoding';
|
||||
import { fromBase64, fromHex, toHex } from '@cosmjs/encoding';
|
||||
import { consensusPubkeyToHexAddress, get } from '@/libs';
|
||||
import { useBankStore } from './useBankStore';
|
||||
import type { Coin, DenomTrace } from '@/types';
|
||||
import { useDashboard } from './useDashboard';
|
||||
import type { Asset } from '@/types/chaindata';
|
||||
|
||||
dayjs.extend(localeData);
|
||||
@ -131,9 +128,7 @@ export const useFormatter = defineStore('formatter', {
|
||||
// find the symbol
|
||||
const symbol = this.dashboard.coingecko[token.denom]?.symbol || token.denom;
|
||||
// convert denomination to symbol
|
||||
const exponent =
|
||||
this.dashboard.coingecko[symbol?.toLowerCase()]?.exponent ||
|
||||
this.specialDenom(token.denom);
|
||||
const exponent = this.dashboard.coingecko[symbol?.toLowerCase()]?.exponent || this.specialDenom(token.denom);
|
||||
// caculate amount of symbol
|
||||
const amount = Number(token.amount) / 10 ** exponent;
|
||||
return amount;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user