diff --git a/chains/mainnet/nibiru-testnet-1.json b/chains/mainnet/nibiru-testnet-2.json similarity index 71% rename from chains/mainnet/nibiru-testnet-1.json rename to chains/mainnet/nibiru-testnet-2.json index f5c63ed274..7e36b6919d 100644 --- a/chains/mainnet/nibiru-testnet-1.json +++ b/chains/mainnet/nibiru-testnet-2.json @@ -1,15 +1,15 @@ { - "chain_name": "nibiru-testnet-1", - "registry_name": "nibiru-testnet-1", + "chain_name": "nibiru-testnet-2", + "registry_name": "nibiru-testnet-2", "api": [ { - "address": "https://lcd.testnet-1.nibiru.fi", + "address": "https://lcd.testnet-2.nibiru.fi", "provider": "Nibiru Foundation" } ], "rpc": [ { - "address": "https://rpc.testnet-1.nibiru.fi", + "address": "https://rpc.testnet-2.nibiru.fi", "provider": "Nibiru Foundation" } ], diff --git a/src/stores/useDashboard.ts b/src/stores/useDashboard.ts index a84101075b..09acbe15f3 100644 --- a/src/stores/useDashboard.ts +++ b/src/stores/useDashboard.ts @@ -2,6 +2,7 @@ import { defineStore } from 'pinia'; import { get } from '../libs/http'; import type { Chain, Asset } from '@ping-pub/chain-registry-client/dist/types'; import { useBlockchain } from './useBlockchain'; +import { getNibiruChains } from '@/nibiru'; export enum EndpointType { rpc, @@ -34,11 +35,11 @@ export interface DirectoryChain { display: string; explorers: | { - name?: string | undefined; - kind?: string | undefined; - url?: string | undefined; - tx_page?: string | undefined; - account_page?: string | undefined; + name?: string; + kind?: string; + url?: string; + tx_page?: string; + account_page?: string; }[] | undefined; height: number; @@ -57,17 +58,17 @@ export interface ChainConfig { chainName: string; prettyName: string; bech32Prefix: string; - bech32ConsensusPrefix: string; chainId: string; coinType: string; assets: Asset[]; themeColor?: string; - features?: string[] + features?: string[]; endpoints: { rest?: Endpoint[]; rpc?: Endpoint[]; grpc?: Endpoint[]; }; + bech32ConsensusPrefix: string; logo: string; versions: { application?: string; @@ -77,25 +78,25 @@ export interface ChainConfig { exponent: string; excludes?: string; providerChain: { - api: Endpoint[] + api: Endpoint[]; }; // keplr config - keplrFeatures?: string[], + keplrFeatures?: string[]; keplrPriceStep?: { - low: number, - average: number, - high: number, - }, + low: number; + average: number; + high: number; + }; } export interface LocalConfig { addr_prefix: string; - consensus_prefix?: string; alias: string; api: string[] | Endpoint[]; provider_chain: { - api: string[] | Endpoint[] - } + api: string[] | Endpoint[]; + }; + consensus_prefix?: string; assets: { base: string; coingecko_id: string; @@ -113,11 +114,11 @@ export interface LocalConfig { registry_name?: string; features?: string[]; keplr_price_step?: { - low: number, - average: number, - high: number, - }, - keplr_features: string[], + low: number; + average: number; + high: number; + }; + keplr_features: string[]; } function apiConverter(api: any[]) { @@ -138,39 +139,38 @@ function apiConverter(api: any[]) { export function fromLocal(lc: LocalConfig): ChainConfig { const conf = {} as ChainConfig; - if(lc.assets && Array.isArray(lc.assets)) { - conf.assets = lc.assets.map((x) => ({ - name: x.base, - base: x.base, - display: x.symbol, - symbol: x.symbol, - logo_URIs: { svg: x.logo }, - coingecko_id: x.coingecko_id, - exponent: x.exponent, - denom_units: [ - { denom: x.base, exponent: 0 }, - { denom: x.symbol.toLowerCase(), exponent: Number(x.exponent) }, - ], - })); - } + conf.assets = lc.assets.map((x) => ({ + name: x.base, + base: x.base, + display: x.symbol, + symbol: x.symbol, + logo_URIs: { svg: x.logo }, + coingecko_id: x.coingecko_id, + exponent: x.exponent, + denom_units: [ + { denom: x.base, exponent: 0 }, + { denom: x.symbol.toLowerCase(), exponent: Number(x.exponent) }, + ], + })); conf.versions = { - cosmosSdk: lc.sdk_version - } + cosmosSdk: lc.sdk_version, + }; conf.bech32Prefix = lc.addr_prefix; - 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; + conf.prettyName = lc.registry_name ?? lc.chain_name; + conf.bech32ConsensusPrefix = + lc.consensus_prefix ?? lc.addr_prefix + 'valcons'; conf.endpoints = { rest: apiConverter(lc.api), rpc: apiConverter(lc.rpc), }; - if(lc.provider_chain) { + if (lc.provider_chain) { conf.providerChain = { - api: apiConverter(lc.provider_chain.api) - } + api: apiConverter(lc.provider_chain.api), + }; } - conf.features = lc.features + conf.features = lc.features; conf.logo = lc.logo; conf.keplrFeatures = lc.keplr_features; conf.keplrPriceStep = lc.keplr_price_step; @@ -187,9 +187,9 @@ export function fromDirectory(source: DirectoryChain): ChainConfig { (conf.chainName = source.chain_name), (conf.prettyName = source.pretty_name), (conf.versions = { - application: source.versions?.application_version || '', - cosmosSdk: source.versions?.cosmos_sdk_version || '', - tendermint: source.versions?.tendermint_version || '', + application: source.versions?.application_version ?? '', + cosmosSdk: source.versions?.cosmos_sdk_version ?? '', + tendermint: source.versions?.tendermint_version ?? '', }), (conf.logo = pathConvert(source.image)); conf.endpoints = source.best_apis; @@ -203,7 +203,7 @@ function pathConvert(path: string | undefined) { 'https://registry.ping.pub' ); } - return path || ''; + return path ?? ''; } export function getLogo( @@ -216,7 +216,7 @@ export function getLogo( | undefined ) { if (conf) { - return pathConvert(conf.svg || conf.png || conf.jpeg); + return pathConvert(conf.svg ?? conf.png ?? conf.jpeg); } return undefined; } @@ -262,8 +262,8 @@ export enum ConfigSource { export const useDashboard = defineStore('dashboard', { state: () => { const favMap = JSON.parse( - localStorage.getItem('favoriteMap') || - '{"cosmos":true, "osmosis":true}' + localStorage.getItem('favoriteMap') ?? + '{"nibiru":true,"nibiru-testnet-1":false}' ); return { status: LoadingStatus.Empty, @@ -272,7 +272,10 @@ export const useDashboard = defineStore('dashboard', { favoriteMap: favMap as Record, chains: {} as Record, prices: {} as Record, - coingecko: {} as Record, + coingecko: {} as Record< + string, + { coinId: string; exponent: number; symbol: string } + >, }; }, getters: { @@ -281,33 +284,38 @@ export const useDashboard = defineStore('dashboard', { }, }, actions: { - async initial() { - await this.loadingFromLocal(); - // await this.loadingFromRegistry() + initial() { + this.loadingFromLocal(); + // this.loadingFromRegistry() }, loadingPrices() { - const coinIds = [] as string[] - const keys = Object.keys(this.chains) // load all blockchain + const coinIds = [] as string[]; + const keys = Object.keys(this.chains); // load all blockchain // Object.keys(this.favoriteMap) //only load favorite once it has too many chains - keys.forEach(k => { - if(Array.isArray(this.chains[k]?.assets)) this.chains[k].assets.forEach(a => { - if(a.coingecko_id !== undefined && a.coingecko_id.length > 0) { - coinIds.push(a.coingecko_id) - a.denom_units.forEach(u => { - this.coingecko[u.denom] = { - coinId: a.coingecko_id || '', - exponent: u.exponent, - symbol: a.symbol - } - }) - } - }) - }) + keys.forEach((k) => { + if (this.chains[k]) + this.chains[k].assets.forEach((a) => { + if (a.coingecko_id !== undefined && a.coingecko_id.length > 0) { + coinIds.push(a.coingecko_id); + a.denom_units.forEach((u) => { + this.coingecko[u.denom] = { + coinId: a.coingecko_id ?? '', + exponent: u.exponent, + symbol: a.symbol, + }; + }); + } + }); + }); - 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(',')}&ids=${coinIds.join(",")}`).then(x => { - this.prices = x - }) + const currencies = ['usd, cny', 'eur', 'jpy', 'krw', 'sgd', 'hkd']; + get( + `https://api.coingecko.com/api/v3/simple/price?include_24hr_change=true&vs_currencies=${currencies.join( + ',' + )}&ids=${coinIds.join(',')}` + ).then((x) => { + this.prices = x; + }); }, async loadingFromRegistry() { if (this.status === LoadingStatus.Empty) { @@ -321,13 +329,25 @@ export const useDashboard = defineStore('dashboard', { } }, async loadingFromLocal() { - if(window.location.hostname.search("testnet") > -1) { - this.networkType = NetworkType.Testnet + if (window.location.hostname.search('testnet') > -1) { + this.networkType = NetworkType.Testnet; } + const nibiruChains = await getNibiruChains(); + const source: Record = this.networkType === NetworkType.Mainnet - ? import.meta.glob('../../chains/mainnet/*.json', { eager: true }) - : import.meta.glob('../../chains/testnet/*.json', { eager: true }); + ? { + // ...import.meta.glob('../../chains/mainnet/*.json', { + // eager: true, + // }), + ...nibiruChains, + } + : { + ...import.meta.glob('../../chains/testnet/*.json', { + eager: true, + }), + ...nibiruChains, + }; Object.values(source).forEach((x: LocalConfig) => { this.chains[x.chain_name] = fromLocal(x); }); @@ -335,31 +355,47 @@ export const useDashboard = defineStore('dashboard', { this.status = LoadingStatus.Loaded; }, async loadLocalConfig(network: NetworkType) { - const config: Record = {} + const config: Record = {}; + + const nibiruChains = await getNibiruChains(); const source: Record = - network === NetworkType.Mainnet - ? import.meta.glob('../../chains/mainnet/*.json', { eager: true }) - : import.meta.glob('../../chains/testnet/*.json', { eager: true }); + this.networkType === NetworkType.Mainnet + ? { + // ...import.meta.glob('../../chains/mainnet/*.json', { + // eager: true, + // }), + ...nibiruChains, + } + : { + ...import.meta.glob('../../chains/testnet/*.json', { + eager: true, + }), + ...nibiruChains, + }; Object.values(source).forEach((x: LocalConfig) => { config[x.chain_name] = fromLocal(x); }); - return config + return config; }, setupDefault() { if (this.length > 0) { 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]]) { - blockchain.setCurrent(keys[i]); - break + const keys = Object.keys(this.favoriteMap); + for (const element of keys) { + if ( + !blockchain.chainName && + this.chains[element] && + this.favoriteMap[element] + ) { + blockchain.setCurrent(element); + break; } } if (!blockchain.chainName) { const [first] = Object.keys(this.chains); blockchain.setCurrent(first); } - this.loadingPrices() + this.loadingPrices(); } }, setConfigSource(newSource: ConfigSource) {