diff --git a/src/libs/client.ts b/src/libs/client.ts index fd76ed4b..51bf6d1b 100644 --- a/src/libs/client.ts +++ b/src/libs/client.ts @@ -1,5 +1,5 @@ import { DEFAULT, fetchData } from '@/libs'; -import { PageRequest } from '@/types'; +import type { PageRequest } from '@/types'; import { setupWasmExtension, type WasmExtension, @@ -380,9 +380,13 @@ export class CosmosRestClient extends BaseRestClient { return res; } async getBankSupplyByDenom(denom: string) { - const res = await this.queryClient.bank.supplyOf(denom); - console.log(res); - return res; + try { + const res = await this.queryClient.bank.supplyOf(denom); + console.log(res); + return res; + } catch (ex) { + console.log(ex); + } } // Distribution Module async getDistributionParams() { @@ -489,31 +493,35 @@ export class CosmosRestClient extends BaseRestClient { status: ProposalStatus, page?: PageRequest ): Promise { - if (!page) page = new PageRequest(); - page.reverse = true; + try { + // v1 for sdk version > 0.45 + if (semver.gt(this.version, DEFAULT_SDK_VERSION)) { + const resV1 = await this.queryClient.extra.proposalsV1(status, page); + return { + // @ts-ignore + proposals: resV1.proposals.map((v) => { + return { + ...v, + proposalId: v.id, + }; + }), + pagination: resV1.pagination, + }; + } else { + const res = await this.queryClient.extra.proposals(status, page); + res?.proposals.forEach((item) => { + if (item.content) { + Object.assign(item, TextProposal.decode(item.content.value)); + } + }); - // v1 for sdk version > 0.45 - if (semver.gt(this.version, DEFAULT_SDK_VERSION)) { - const resV1 = await this.queryClient.extra.proposalsV1(status, page); + return res as ExtraQueryProposalsResponse; + } + } catch (ex) { + console.log(ex); return { - // @ts-ignore - proposals: resV1.proposals.map((v) => { - return { - ...v, - proposalId: v.id, - }; - }), - pagination: resV1.pagination, + proposals: [], }; - } else { - const res = await this.queryClient.extra.proposals(status, page); - res?.proposals.forEach((item) => { - if (item.content) { - Object.assign(item, TextProposal.decode(item.content.value)); - } - }); - - return res as ExtraQueryProposalsResponse; } } async getGovProposal(proposal_id: string) { @@ -613,9 +621,13 @@ export class CosmosRestClient extends BaseRestClient { return res; } async getStakingParams() { - const res = await this.queryClient.staking.params(); - console.log(res); - return res; + try { + const res = await this.queryClient.staking.params(); + console.log(res); + return res; + } catch (ex) { + console.log(ex); + } // return this.request(this.registry.staking_params, {}); } async getStakingPool() { @@ -630,9 +642,13 @@ export class CosmosRestClient extends BaseRestClient { // return this.request(this.registry.staking_pool, {}); } async getStakingValidators(status: BondStatusString, limit = 200) { - const res = await this.queryClient.staking.validators(status); - console.log(status, res); - return res; + try { + const res = await this.queryClient.staking.validators(status); + console.log(status, res); + return res; + } catch (ex) { + console.log(ex); + } // return this.request(this.registry.staking_validators, { status, limit }); } async getStakingValidator(validator_addr: string) { diff --git a/src/modules/[chain]/uptime/customize.vue b/src/modules/[chain]/uptime/customize.vue index baf49cd8..7d90a4c0 100644 --- a/src/modules/[chain]/uptime/customize.vue +++ b/src/modules/[chain]/uptime/customize.vue @@ -14,6 +14,7 @@ import type { Block, Commit } from '@/types'; import { consensusPubkeyToHexAddress, valconsToBase64 } from '@/libs'; import type { SigningInfo } from '@/types/slashing'; import { CosmosRestClient } from '@/libs/client'; +import type { ValidatorSigningInfo } from 'cosmjs-types/cosmos/slashing/v1beta1/slashing'; const props = defineProps(['chain']); @@ -28,7 +29,7 @@ const local = ref( { name: string; address: string }[] > ); -const signingInfo = ref({} as Record); +const signingInfo = ref({} as Record); const selected = ref([] as string[]); const selectChain = ref(chainStore.chainName); const validators = ref(stakingStore.validators); @@ -93,7 +94,7 @@ function add() { const newList = [] as { name: string; address: string }[]; selected.value.forEach((x) => { const validator = validators.value.find( - (v) => consensusPubkeyToHexAddress(v.consensus_pubkey) === x + (v) => consensusPubkeyToHexAddress(v.consensusPubkey) === x ); if (validator) newList.push({ @@ -115,6 +116,7 @@ async function changeChain() { const client = CosmosRestClient.newDefault(endpoint); const x = await client.getStakingValidators('BOND_STATUS_BONDED'); + if (!x) return; validators.value = x.validators; const vals = local.value[selectChain.value]; @@ -283,7 +285,7 @@ function color(v: string) { - diff --git a/src/stores/useParamsStore.ts b/src/stores/useParamsStore.ts index a479f194..937289a1 100644 --- a/src/stores/useParamsStore.ts +++ b/src/stores/useParamsStore.ts @@ -109,6 +109,7 @@ export const useParamStore = defineStore('paramstore', { }, async handleStakingParams() { const res = await this.getStakingParams(); + if (!res) return; const bond_denom = res?.params.bondDenom; this.staking.items = Object.entries(res.params) .map(([key, value]) => ({ subtitle: key, value: value })) diff --git a/src/stores/useStakingStore.ts b/src/stores/useStakingStore.ts index 59b2312d..ef6c252d 100644 --- a/src/stores/useStakingStore.ts +++ b/src/stores/useStakingStore.ts @@ -169,6 +169,7 @@ export const useStakingStore = defineStore('stakingStore', { ); // provider validators const validatorsRes = await client.getStakingValidators(status); + if (!validatorsRes) return []; const proVals = validatorsRes.validators.sort( (a, b) => Number(b.delegatorShares) - Number(a.delegatorShares) ); @@ -182,6 +183,7 @@ export const useStakingStore = defineStore('stakingStore', { const validatorsRes = await this.blockchain.rpc?.getStakingValidators( status ); + if (!validatorsRes) return []; const vals = validatorsRes.validators.sort( (a, b) => Number(b.delegatorShares) - Number(a.delegatorShares) );