fix all build checks

This commit is contained in:
liangping 2023-06-08 10:02:47 +08:00
parent e2782c1e00
commit a25dde89f5
18 changed files with 123 additions and 80 deletions

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ping Dashboard</title>
<title>Ping Dashboard - Cosmos Blockchain Explorer And Web Wallet</title>
<meta name="description" content="Ping Dashboard is a block explorer/web wallet for blockchains built on Cosmos SDK, Cosmoshub, Osmosis, Juno, Evmos, Injective, Canto and 70+ blockchains listed on ping.pub" />
<link rel="stylesheet" type="text/css" href="/loader.css" />
</head>

View File

@ -55,6 +55,7 @@
"@types/marked": "^4.0.8",
"@types/node": "^18.11.12",
"@types/numeral": "^2.0.2",
"@types/semver": "7.5.0",
"@vitejs/plugin-vue": "^4.0.0",
"@vue/tsconfig": "^0.1.3",
"npm-run-all": "^4.1.5",

View File

@ -1,5 +1,6 @@
<script setup lang="ts">
import { Icon } from '@iconify/vue';
import { controlledComputed } from '@vueuse/core'
interface Props {
title: string;

View File

@ -2,7 +2,7 @@
import { computed, ref } from 'vue';
const props = defineProps({
total: { type: Number },
total: { type: String },
limit: { type: Number },
callback: { type: Function, required: true },
});
@ -10,12 +10,13 @@ const current = ref(1)
const showSize = 3
const pages = computed(() => {
const pages: { color: string, page: number }[] = []
if (props.total && props.limit && props.total > props.limit) {
const total = Number(props.total || 0)
if (total > 0 && props.limit && total > props.limit) {
let page = 0
while (true) {
if (page * props.limit > props.total) break
if (page * props.limit > total) break
page += 1
if (props.total / props.limit > 10 && page > showSize && page < (props.total / props.limit - showSize + 1)) {
if (total / props.limit > 10 && page > showSize && page < (total / props.limit - showSize + 1)) {
if (!(page >= current.value - 1 && page <= current.value + 1)) {
continue
}

View File

@ -1,6 +1,7 @@
<script lang="ts" setup>
import { toBase64, toHex } from '@cosmjs/encoding';
import { computed } from '@vue/reactivity';
import { ref } from 'vue';
const props = defineProps(['value']);
const format = ref('base64');

View File

@ -1,4 +1,6 @@
<script lang="ts">
import { defineComponent, resolveComponent, h } from 'vue'
export default defineComponent({
setup() {
const routerView = resolveComponent('router-view');

View File

@ -13,6 +13,7 @@ import { useBlockchain } from '@/stores';
import NavBarI18n from './NavBarI18n.vue';
import NavBarWallet from './NavBarWallet.vue';
import type { NavGroup, NavLink, NavSectionTitle } from '../types';
const dashboard = useDashboard();
dashboard.initial();
@ -35,6 +36,16 @@ const changeOpen = (index: Number) => {
}
};
const showDiscord = window.location.host.search('ping.pub') > -1;
function isNavGroup(nav: NavGroup | NavLink | NavSectionTitle | any): nav is NavGroup {
return (<NavGroup>nav).children !== undefined;
}
function isNavLink(nav: NavGroup | NavLink | NavSectionTitle | any): nav is NavLink {
return (<NavLink>nav).to !== undefined;
}
function isNavTitle(nav: NavGroup | NavLink | NavSectionTitle | any): nav is NavSectionTitle {
return (<NavSectionTitle>nav).heading !== undefined;
}
</script>
<template>
@ -62,7 +73,7 @@ const showDiscord = window.location.host.search('ping.pub') > -1;
class="px-2"
>
<div
v-if="item?.title && item?.children?.length"
v-if="isNavGroup(item)"
:tabindex="index"
class="collapse"
:class="{
@ -151,7 +162,7 @@ const showDiscord = window.location.host.search('ping.pub') > -1;
<RouterLink
:to="item?.to"
v-if="item?.title && !item?.children?.length && item?.to"
v-if="isNavGroup(item)"
@click="sidebarShow = false"
class="cursor-pointer rounded-lg px-4 flex items-center py-2 hover:bg-gray-100 dark:hover:bg-[#373f59]"
>
@ -183,7 +194,7 @@ const showDiscord = window.location.host.search('ping.pub') > -1;
</div>
</RouterLink>
<div
v-if="item?.heading"
v-if="isNavTitle(item)"
class="px-4 text-sm text-gray-400 pb-2 uppercase"
>
{{ item?.heading }}

View File

@ -1,6 +1,8 @@
<script lang="ts" setup>
import { ref, watch } from 'vue';
import { Icon } from '@iconify/vue';
import { useI18n } from 'vue-i18n';
const i18nLangs: Array<{ label: string; i18nLang: string }> = [
{
label: 'English',
@ -13,7 +15,7 @@ const i18nLangs: Array<{ label: string; i18nLang: string }> = [
];
let locale = ref(useI18n({ useScope: 'global' }).locale);
watch(locale, (val: string) => {
watch(locale, (val) => {
document.documentElement.setAttribute('lang', val as string);
});

58
src/layouts/types.d.ts vendored Normal file
View File

@ -0,0 +1,58 @@
// 👉 Vertical nav section title
export interface NavSectionTitle extends Partial<AclProperties> {
heading: string
}
// 👉 Vertical nav link
declare type ATagTargetAttrValues = '_blank' | '_self' | '_parent' | '_top' | 'framename'
declare type ATagRelAttrValues =
| 'alternate'
| 'author'
| 'bookmark'
| 'external'
| 'help'
| 'license'
| 'next'
| 'nofollow'
| 'noopener'
| 'noreferrer'
| 'prev'
| 'search'
| 'tag'
export interface NavLinkProps {
to?: RouteLocationRaw | string | null
href?: string
target?: ATagTargetAttrValues
rel?: ATagRelAttrValues
i18n?: boolean
}
export interface Icon {
icon?: string,
image?: string,
size: string,
}
export interface NavLink extends NavLinkProps {
title: string
icon?: Icon
badgeContent?: string
badgeClass?: string
disable?: boolean
order?: number
}
// 👉 Vertical nav group
export interface NavGroup extends NavLinkProps {
title: string
icon?: Icon
badgeContent?: string
badgeClass?: string
children: (NavLink | NavGroup)[]
disable?: boolean
order?: number
}
export declare type VerticalNavItems = (NavLink | NavGroup | NavSectionTitle)[]
export declare type HorizontalNavItems = (NavLink | NavGroup)[]

View File

@ -51,9 +51,10 @@ export function formatTokenAmount(
tokenDenom = 'uatom',
format = true
) {
const denom = tokenDenom?.denom_trace
? tokenDenom?.denom_trace?.base_denom
: tokenDenom;
const denom = typeof tokenDenom === 'string'
? tokenDenom
// @ts-ignore
: tokenDenom?.denom_trace?.base_denom;
let amount = 0;
const asset = assets.find((a: any) => a.base === denom);
let exp = asset
@ -79,60 +80,6 @@ export function numberWithCommas(x: any) {
return parts.join('.');
}
export function tokenFormatter(tokens: any, denoms = {}, decimal = 2) {
if (Array.isArray(tokens)) {
return tokens.map((t) => formatToken(t, denoms, decimal)).join(', ');
}
return formatToken(tokens, denoms, 2);
}
export function formatToken(
token: any,
IBCDenom = {},
decimals = 2,
withDenom = true
) {
if (token) {
const denom = IBCDenom[token.denom] || token.denom;
if (withDenom) {
return `${formatTokenAmount(
token.amount,
decimals,
denom
)} ${formatTokenDenom(denom)}`;
}
return formatTokenAmount(token.amount, decimals, denom);
}
return token;
}
export function formatTokenDenom(tokenDenom: any) {
if (tokenDenom && tokenDenom.code === undefined) {
let denom = tokenDenom.denom_trace
? tokenDenom.denom_trace.base_denom
: tokenDenom;
const chains = getLocalChains();
const selected = localStorage.getItem('selected_chain');
const selChain = chains[selected];
const nativeAsset = selChain.assets.find((a) => a.base === denom);
if (nativeAsset) {
denom = nativeAsset.symbol;
} else {
const config = Object.values(chains);
config.forEach((x) => {
if (x.assets) {
const asset = x.assets.find((a) => a.base === denom);
if (asset) denom = asset.symbol;
}
});
}
return denom.length > 10
? `${denom.substring(0, 7).toUpperCase()}..${denom.substring(
denom.length - 3
)}`
: denom.toUpperCase();
}
return '';
}
export function isToken(value: string) {
let is = false;
if (Array.isArray(value)) {

View File

@ -7,11 +7,12 @@ import {
useDashboard,
useStakingStore,
} from '@/stores';
import { consensusPubkeyToHexAddress } from '@/libs';
const format = useFormatter();
const chainStore = useBlockchain();
const dashboard = useDashboard();
const stakingStore = useStakingStore();
import { consensusPubkeyToHexAddress } from '@/libs';
const rpcList = ref(
chainStore.current?.endpoints?.rpc || [{ address: '', provider: '' }]
);
@ -42,21 +43,24 @@ onUnmounted(() => {
});
const newTime = computed(() => {
return format.toDay(updatetime.value || '', 'time');
return format.toDay(updatetime.value?.toDateString(), 'time');
});
const vals = computed(() => {
return validators.value.map((x) => {
const x2 = x;
// @ts-ignore
x2.hex = consensusPubkeyToHexAddress(x.consensus_pubkey);
return x2;
});
});
function showName(i, text) {
function showName(i:number, text: string) {
if (text === 'nil-Vote') {
// @ts-ignore
if (positions.value?.[i]?.address) {
const val = vals.value.find(
// @ts-ignore
(x) => x.hex === positions.value?.[i]?.address
);
return val?.description?.moniker || i;
@ -65,10 +69,11 @@ function showName(i, text) {
}
const txt = text.substring(text.indexOf(':') + 1, text.indexOf(' '));
const sig = text.split(' ');
// @ts-ignore
const val = validators.value.find((x) => x?.hex?.startsWith(txt));
return `${val?.description?.moniker || txt} - ${sig[2]}`;
}
function color(i, txt) {
function color(i: number, txt: string) {
if (i === roundState.value?.proposer?.index) {
return txt === 'nil-Vote' ? 'warning' : 'primary';
}
@ -99,7 +104,9 @@ async function fetchPosition() {
const data = await response.json();
positions.value = data.result.round_state.validators.validators;
} catch (error) {
// @ts-ignore
httpstatus.value = error?.status || 500;
// @ts-ignore
httpStatusText.value = error?.message || 'Error';
}
}
@ -125,7 +132,7 @@ async function update() {
step.value = raw[2];
// find the highest onboard rate
roundState.value?.height_vote_set?.forEach((element) => {
roundState.value?.height_vote_set?.forEach((element: any) => {
const rates = Number(
element.prevotes_bit_array.substring(
element.prevotes_bit_array.length - 4

View File

@ -9,7 +9,7 @@ import {
import { useDistributionStore } from '@/stores/useDistributionStore';
import { useMintStore } from '@/stores/useMintStore';
import { useStakingStore } from '@/stores/useStakingStore';
import type { Tally } from '@/types';
import type { Coin, Tally } from '@/types';
import numeral from 'numeral';
import { defineStore } from 'pinia';
@ -175,6 +175,7 @@ export const useIndexModule = defineStore('module-index', {
color: 'warning',
icon: 'mdi-lock',
stats: formatter.formatTokenAmount({
// @ts-ignore
amount: this.pool.bonded_tokens,
denom: staking.params.bond_denom,
}),
@ -192,8 +193,9 @@ export const useIndexModule = defineStore('module-index', {
color: 'primary',
icon: 'mdi-bank',
stats: formatter.formatTokens(
// @ts-ignore
this.communityPool?.filter(
(x) => x.denom === staking.params.bond_denom
(x: Coin) => x.denom === staking.params.bond_denom
)
),
change: 0,
@ -203,6 +205,7 @@ export const useIndexModule = defineStore('module-index', {
coingeckoId() {
this.tickerIndex = 0;
// @ts-ignore
const [firstAsset] = this.blockchain?.assets || [];
return firstAsset.coingecko_id
}

View File

@ -1,6 +1,8 @@
import { useBlockchain } from "@/stores";
import { setupLayouts } from "virtual:generated-layouts";
import { createRouter, createWebHistory } from "vue-router";
// @ts-ignore
import { setupLayouts } from "virtual:generated-layouts";
// @ts-ignore
import routes from "~pages";
const router = createRouter({

View File

@ -10,6 +10,7 @@ export const useBankStore = defineStore('bankstore', {
supply: {} as Coin,
balances: {} as Record<string, Coin[]>,
totalSupply: { supply: [] as Coin[] },
ibcDenoms: {} as Record<string, DenomTrace>
};
},
getters: {

View File

@ -5,7 +5,7 @@ import {
type Endpoint,
EndpointType,
} from './useDashboard';
import type { VerticalNavItems } from '@/@layouts/types';
import type { VerticalNavItems } from '@/layouts/types';
import { useRouter } from 'vue-router';
import { CosmosRestClient } from '@/libs/client';
import {

View File

@ -147,6 +147,7 @@ export const useFormatter = defineStore('formatter', {
}
const conf = mode === 'local'? this.blockchain.current?.assets?.find(
// @ts-ignore
(x) => x.base === token.denom || x.base.denom === token.denom
): this.findGlobalAssetConfig(token.denom)
@ -226,7 +227,7 @@ export const useFormatter = defineStore('formatter', {
numberAndSign(input: number, fmt = '+0,0') {
return numeral(input).format(fmt);
},
toDay(time?: string, format = 'long') {
toDay(time?: string | number, format = 'long') {
if (!time) return '';
if (format === 'long') {
return dayjs(time).format('YYYY-MM-DD HH:mm');

View File

@ -17,7 +17,7 @@ export const useWalletStore = defineStore('walletStore', {
balances: [] as Coin[],
delegations: [] as Delegation[],
unbonding: [] as UnbondingResponses[],
rewards: {} as DelegatorRewards,
rewards: {total: [], rewards: []} as DelegatorRewards,
walletIsConnected: {} as WalletConnected
};
},
@ -28,7 +28,7 @@ export const useWalletStore = defineStore('walletStore', {
connectedWallet() {
const chainStore = useBlockchain();
const key = chainStore.defaultHDPath;
let connected = this.walletIsConnected
let connected = {} as WalletConnected
if (!this.walletIsConnected?.cosmosAddress){
connected = JSON.parse(localStorage.getItem(key) || '{}');
}
@ -54,8 +54,9 @@ export const useWalletStore = defineStore('walletStore', {
},
rewardAmount() {
const stakingStore = useStakingStore();
// @ts-ignore
const reward = this.rewards.total?.find(
(x) => x.denom === stakingStore.params.bond_denom
(x: Coin) => x.denom === stakingStore.params.bond_denom
);
return reward || { amount: '0', denom: stakingStore.params.bond_denom };
},
@ -125,7 +126,6 @@ export const useWalletStore = defineStore('walletStore', {
console.log(key, 'key')
console.log(localStorage.getItem(key))
localStorage.removeItem(key);
this.walletIsConnected = null
this.$reset()
},
setConnectedWallet(value: any) {

View File

@ -2623,6 +2623,11 @@
resolved "https://registry.npmjs.org/@types/prettier/-/prettier-2.7.2.tgz"
integrity sha512-KufADq8uQqo1pYKVIYzfKbJfBAc0sOeXqGbFaSpv8MRmC/zXgowNZmFcbngndGk922QDmOASEXUZCaY48gs4cg==
"@types/semver@7.5.0":
version "7.5.0"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.0.tgz#591c1ce3a702c45ee15f47a42ade72c2fd78978a"
integrity sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw==
"@types/web-bluetooth@^0.0.16":
version "0.0.16"
resolved "https://registry.npmjs.org/@types/web-bluetooth/-/web-bluetooth-0.0.16.tgz"