diff --git a/src/libs/client.ts b/src/libs/client.ts index 798d676a..33428a9b 100644 --- a/src/libs/client.ts +++ b/src/libs/client.ts @@ -1,23 +1,10 @@ -import { - consensusPubkeyToHexAddress, - DEFAULT, - fetchData, - operatorAddressToAccount, - pubKeyToValcons, -} from '@/libs'; +import { DEFAULT, fetchData } from '@/libs'; import { PageRequest } from '@/types'; import { setupWasmExtension, type WasmExtension, } from '@cosmjs/cosmwasm-stargate'; -import { - fromBase64, - fromBech32, - fromHex, - toBase64, - toBech32, - toHex, -} from '@cosmjs/encoding'; +import { fromBase64, fromHex, toBase64, toHex } from '@cosmjs/encoding'; import type { DecodedTxRaw } from '@cosmjs/proto-signing'; import { decodeTxRaw } from '@cosmjs/proto-signing'; import { @@ -64,33 +51,38 @@ import { QueryParamsResponse as QueryBankParamsResponse, QueryTotalSupplyResponse, } from 'cosmjs-types/cosmos/bank/v1beta1/query'; +import { + GetNodeInfoResponse, + ServiceClientImpl as TmQueryClientImpl, +} from 'cosmjs-types/cosmos/base/tendermint/v1beta1/query'; import { Proposal, TextProposal, VoteOption, type ProposalStatus, } from 'cosmjs-types/cosmos/gov/v1beta1/gov'; -import { - GetNodeInfoResponse, - ServiceClientImpl as TmQueryClientImpl, -} from 'cosmjs-types/cosmos/base/tendermint/v1beta1/query'; -import { Proposal as ProposalV1 } from 'cosmjs-types/cosmos/gov/v1/gov'; +import { useBlockchain, type ChainConfig } from '@/stores'; +import type { PageResponse } from 'cosmjs-types/cosmos/base/query/v1beta1/pagination'; +import type { QueryValidatorOutstandingRewardsResponse } from 'cosmjs-types/cosmos/distribution/v1beta1/query'; +import { + QueryClientImpl as GovQueryClientImplV1, + QueryProposalsResponse as QueryProposalsResponseV1, +} from 'cosmjs-types/cosmos/gov/v1/query'; import { QueryClientImpl as GovQueryClientImpl, QueryProposalsResponse, QueryVotesResponse, } from 'cosmjs-types/cosmos/gov/v1beta1/query'; -import { - QueryClientImpl as GovQueryClientImplV1, - QueryProposalsResponse as QueryProposalsResponseV1, -} from 'cosmjs-types/cosmos/gov/v1/query'; import type { QueryDelegationResponse, QueryValidatorDelegationsResponse, QueryValidatorResponse, } from 'cosmjs-types/cosmos/staking/v1beta1/query'; import { QueryClientImpl as StakingQueryClientImpl } from 'cosmjs-types/cosmos/staking/v1beta1/query'; +import { bondStatusFromJSON } from 'cosmjs-types/cosmos/staking/v1beta1/staking'; +import type { GetTxResponse } from 'cosmjs-types/cosmos/tx/v1beta1/service'; +import { Tx } from 'cosmjs-types/cosmos/tx/v1beta1/tx'; import { QueryAllContractStateResponse, QueryClientImpl as WasmQueryClientImpl, @@ -98,6 +90,9 @@ import { QueryContractsByCreatorResponse, QueryParamsResponse as QueryWasmParamsResponse, } from 'cosmjs-types/cosmwasm/wasm/v1/query'; +import { toTimestamp } from 'cosmjs-types/helpers'; +import type { Event, EventAttribute } from 'cosmjs-types/tendermint/abci/types'; +import semver from 'semver'; import type { Request } from './registry'; import { findApiProfileByChain, @@ -108,15 +103,9 @@ import { type AbstractRegistry, type RequestRegistry, } from './registry'; -import semver from 'semver'; -import { useBlockchain, type ChainConfig } from '@/stores'; -import type { PageResponse } from 'cosmjs-types/cosmos/base/query/v1beta1/pagination'; -import type { GetTxResponse } from 'cosmjs-types/cosmos/tx/v1beta1/service'; -import { Tx } from 'cosmjs-types/cosmos/tx/v1beta1/tx'; -import type { Event, EventAttribute } from 'cosmjs-types/tendermint/abci/types'; -import { PubKey as Ed25519PubKey } from 'cosmjs-types/cosmos/crypto/ed25519/keys'; export const DEFAULT_SDK_VERSION = '0.45.16'; +export const LCD_FALLBACK_CHAINS = ['OraiBtcMainnet']; export type ExtraTxResponse = TxResponse & { txRaw: DecodedTxRaw; @@ -461,18 +450,34 @@ export class CosmosRestClient extends BaseRestClient { console.log(ex); } } - async getDistributionValidatorOutstandingRewards(validator_address: string) { - // return this.request( - // this.registry.distribution_validator_outstanding_rewards, - // { validator_address } - // ); + async getDistributionValidatorOutstandingRewards( + validator_address: string + ): Promise { try { - const res = - await this.queryClient.distribution.validatorOutstandingRewards( - validator_address + const blockchain = useBlockchain(); + if (LCD_FALLBACK_CHAINS.includes(blockchain.chainName)) { + const { rewards } = await this.request( + this.registry.distribution_validator_outstanding_rewards, + { validator_address } ); - console.log(res); - return res; + + const res = { + rewards: { + rewards: + rewards?.rewards?.map((r) => { + return r; + }) ?? [], + }, + }; + return res; + } else { + const res = + await this.queryClient.distribution.validatorOutstandingRewards( + validator_address + ); + + return res; + } } catch (ex) { console.log(ex); } @@ -695,22 +700,55 @@ export class CosmosRestClient extends BaseRestClient { console.log(ex); } } - async getStakingValidator(validator_addr: string) { - // return this.request(this.registry.staking_validators_address, { - // validator_addr, - // }); + async getStakingValidator( + validator_addr: string + ): Promise { try { const blockchain = useBlockchain(); // TODO:// hardcode for nomic sdk - if (blockchain.chainName === 'OraiBtcMainnet') { - const validators = await this.getStakingValidators( - 'BOND_STATUS_BONDED' + if (LCD_FALLBACK_CHAINS.includes(blockchain.chainName)) { + const { validator } = await this.request( + this.registry.staking_validators_address, + { + validator_addr, + } ); - const validator = validators?.validators.find((v) => { - return operatorAddressToAccount(v.operatorAddress) === validator_addr; - }); + return { - validator, + validator: { + operatorAddress: validator.operator_address, + commission: { + commissionRates: { + maxChangeRate: + validator.commission.commission_rates.max_change_rate, + maxRate: validator.commission.commission_rates.max_rate, + rate: validator.commission.commission_rates.rate, + }, + updateTime: toTimestamp( + new Date(validator.commission.update_time) + ), + }, + consensusPubkey: { + typeUrl: validator.consensus_pubkey['@type'], + value: fromBase64(validator.consensus_pubkey.key), + }, + delegatorShares: validator.delegator_shares, + description: { + details: validator.description.details ?? '', + identity: validator.description.identity ?? '', + moniker: validator.description.moniker ?? '', + securityContact: validator.description.security_contact ?? '', + website: validator.description.website ?? '', + }, + minSelfDelegation: validator.min_self_delegation, + unbondingHeight: BigInt(validator.unbonding_height), + unbondingTime: toTimestamp(new Date(validator.unbonding_time)), + tokens: validator.tokens, + status: bondStatusFromJSON(validator.status), + jailed: validator.jailed, + unbondingOnHoldRefCount: 0n, + unbondingIds: [], + }, }; } else { const res = await this.queryClient.staking.validator(validator_addr); @@ -754,7 +792,7 @@ export class CosmosRestClient extends BaseRestClient { try { const blockchain = useBlockchain(); // TODO:// hardcode for nomic sdk - if (blockchain.chainName === 'OraiBtcMainnet') { + if (LCD_FALLBACK_CHAINS.includes(blockchain.chainName)) { const { delegation_responses } = await this.request( this.registry.staking_deletations, { @@ -828,7 +866,7 @@ export class CosmosRestClient extends BaseRestClient { try { const blockchain = useBlockchain(); // TODO:// hardcode for nomic sdk - if (blockchain.chainName === 'OraiBtcMainnet') { + if (LCD_FALLBACK_CHAINS.includes(blockchain.chainName)) { const res = await this.tmClient.status(); return GetNodeInfoResponse.fromPartial({ // @ts-ignore @@ -947,7 +985,7 @@ export class CosmosRestClient extends BaseRestClient { try { const blockchain = useBlockchain(); // TODO:// hardcode for nomic sdk - if (blockchain.chainName === 'OraiBtcMainnet') { + if (LCD_FALLBACK_CHAINS.includes(blockchain.chainName)) { const tmRes = await this.tmClient.tx({ hash: fromHex(hash) }); const tx = Tx.decode(tmRes.tx); const block = await this.tmClient.block(tmRes.height); diff --git a/src/modules/[chain]/gov/[proposal_id].vue b/src/modules/[chain]/gov/[proposal_id].vue index 4bb6c6cb..854c01bb 100644 --- a/src/modules/[chain]/gov/[proposal_id].vue +++ b/src/modules/[chain]/gov/[proposal_id].vue @@ -434,7 +434,13 @@ function metaItem(metadata: string | undefined): { item.option === VoteOption.VOTE_OPTION_ABSTAIN, }" > - {{ String(item.option).replace('VOTE_OPTION_', '') }} + {{ + voteOptionToJSON(item.option) + .toLowerCase() + .replace(/^vote_option/, '') + .replaceAll(/_(.)/g, (m, g) => ' ' + g.toUpperCase()) + .trim() + }} {{ diff --git a/src/modules/[chain]/staking/[validator].vue b/src/modules/[chain]/staking/[validator].vue index f7ddc309..5c8fd4c3 100644 --- a/src/modules/[chain]/staking/[validator].vue +++ b/src/modules/[chain]/staking/[validator].vue @@ -22,9 +22,10 @@ import { fromAscii, toBase64, toHex } from '@cosmjs/encoding'; import type { Event } from '@cosmjs/tendermint-rpc'; import { Icon } from '@iconify/vue'; import type { QueryValidatorDelegationsResponse } from 'cosmjs-types/cosmos/staking/v1beta1/query'; -import type { - DelegationResponse, - Validator, +import { + bondStatusToJSON, + type DelegationResponse, + type Validator, } from 'cosmjs-types/cosmos/staking/v1beta1/staking'; import { fromTimestamp } from 'cosmjs-types/helpers'; import { computed, onMounted, ref } from 'vue'; @@ -403,13 +404,19 @@ function mapDelegators(messages: any[]) { {{ $t('staking.status') }}: - {{ String(v.status).replace('BOND_STATUS_', '') }} + {{ + bondStatusToJSON(v.status) + .toLowerCase() + .replace(/^bond_status/, '') + .replaceAll(/_(.)/g, (m, g) => ' ' + g.toUpperCase()) + .trim() + }}
{{ $t('staking.jailed') }}: - {{ v.jailed || '-' }} + {{ v.jailed ?? '-' }}

diff --git a/src/types/staking.ts b/src/types/staking.ts index 751a41cc..eee5bb49 100644 --- a/src/types/staking.ts +++ b/src/types/staking.ts @@ -23,15 +23,12 @@ export interface Validator { } export interface CommissionRate { - commissionRates: { + commission_rates: { rate: string; - maxRate: string; - maxChangeRate: string; - }; - updateTime: { - seconds: BigInt; - nanos: number; + max_rate: string; + max_change_rate: string; }; + update_time: string; } export interface UnbondingResponses {