From fc8aab6ce0564129e287388ef920d9e539636ea0 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Thu, 20 Apr 2023 18:44:25 +0800 Subject: [PATCH] add account details --- chains/mainnet/osmosis.json | 2 +- src/libs/api.ts | 3 +- src/libs/client.ts | 5 +- src/libs/registry.ts | 3 +- src/modules/[chain]/account/[address].vue | 216 ++++++++++++++++++++ src/modules/[chain]/staking/[validator].vue | 2 +- src/stores/useFormatter.ts | 16 +- src/types/distribution.ts | 10 +- 8 files changed, 246 insertions(+), 11 deletions(-) create mode 100644 src/modules/[chain]/account/[address].vue diff --git a/chains/mainnet/osmosis.json b/chains/mainnet/osmosis.json index f46d467f..6a521b3c 100644 --- a/chains/mainnet/osmosis.json +++ b/chains/mainnet/osmosis.json @@ -1,7 +1,7 @@ { "chain_name": "osmosis", "coingecko": "osmosis", - "api": ["https://api-osmosis-ia.cosmosia.notional.ventures", "https://osmosis-api.polkachu.com", "https://osmo.api.ping.pub", "https://lcd-osmosis.blockapsis.com"], + "api": ["https://api-osmosis-ia.cosmosia.notional.ventures", "https://osmosis-api.polkachu.com", "https://lcd-osmosis.blockapsis.com"], "rpc": ["https://rpc-osmosis-ia.cosmosia.notional.ventures:443", "https://osmosis-rpc.polkachu.com:443", "https://osmosis.validator.network:443", "https://rpc-osmosis.blockapsis.com:443"], "snapshot_provider": "", "sdk_version": "0.46.1", diff --git a/src/libs/api.ts b/src/libs/api.ts index 90fe3604..05b29ba5 100644 --- a/src/libs/api.ts +++ b/src/libs/api.ts @@ -10,10 +10,11 @@ export const DEFAULT: RequestRegistry = { bank_supply: { url: "/cosmos/bank/v1beta1/supply", adapter }, bank_supply_by_denom: { url: "/cosmos/bank/v1beta1/supply/{denom}", adapter }, distribution_params: { url: "/cosmos/distribution/v1beta1/params", adapter }, - distributino_community_pool: { url: "/cosmos/distribution/v1beta1/community_pool", adapter }, + distribution_community_pool: { url: "/cosmos/distribution/v1beta1/community_pool", adapter }, distribution_validator_commission: { url: "/cosmos/distribution/v1beta1/validators/{validator_address}/commission", adapter }, distribution_validator_outstanding_rewards: { url: "/cosmos/distribution/v1beta1/validators/{validator_address}/outstanding_rewards", adapter }, distribution_validator_slashes: { url: "/cosmos/distribution/v1beta1/validators/{validator_address}/slashes", adapter }, + distribution_delegator_rewards: { url: "/cosmos/distribution/v1beta1/delegators/{delegator_addr}/rewards", adapter }, slashing_params: { url: "/cosmos/slashing/v1beta1/params", adapter }, slashing_signing_info: { url: "/cosmos/slashing/v1beta1/signing_infos", adapter }, gov_params_voting: { url: "/cosmos/gov/v1beta1/params/voting", adapter }, diff --git a/src/libs/client.ts b/src/libs/client.ts index d8084fee..a8e4c829 100644 --- a/src/libs/client.ts +++ b/src/libs/client.ts @@ -44,7 +44,10 @@ export class CosmosRestClient { return this.request(this.registry.distribution_params, {}) } async getDistributionCommunityPool() { - return this.request(this.registry.distributino_community_pool, {}) + return this.request(this.registry.distribution_community_pool, {}) + } + async getDistributionDelegatorRewards(delegator_addr: string) { + return this.request(this.registry.distribution_delegator_rewards, {delegator_addr}) } async getDistributionValidatorCommission(validator_address: string) { return this.request(this.registry.distribution_validator_commission, {validator_address}) diff --git a/src/libs/registry.ts b/src/libs/registry.ts index 6913d0ce..de24181f 100644 --- a/src/libs/registry.ts +++ b/src/libs/registry.ts @@ -29,7 +29,8 @@ export interface RequestRegistry { distribution_validator_commission: Request<{commission?: {commission?: Coin[]}}>; distribution_validator_outstanding_rewards: Request<{rewards?: {rewards?: Coin[]}}>; distribution_validator_slashes: Request; - distributino_community_pool: Request<{pool: Coin[]}>; + distribution_community_pool: Request<{pool: Coin[]}>; + distribution_delegator_rewards: Request; mint_inflation: Request<{inflation: string}>; mint_params: Request<{ diff --git a/src/modules/[chain]/account/[address].vue b/src/modules/[chain]/account/[address].vue new file mode 100644 index 00000000..919d55b5 --- /dev/null +++ b/src/modules/[chain]/account/[address].vue @@ -0,0 +1,216 @@ + + + \ No newline at end of file diff --git a/src/modules/[chain]/staking/[validator].vue b/src/modules/[chain]/staking/[validator].vue index 5351542c..d21436c5 100644 --- a/src/modules/[chain]/staking/[validator].vue +++ b/src/modules/[chain]/staking/[validator].vue @@ -225,7 +225,7 @@ onMounted(()=> { Account - {{ addresses.account }} + {{ addresses.account }} Operator Address diff --git a/src/stores/useFormatter.ts b/src/stores/useFormatter.ts index ecf9818d..de040f03 100644 --- a/src/stores/useFormatter.ts +++ b/src/stores/useFormatter.ts @@ -8,7 +8,7 @@ import updateLocale from 'dayjs/plugin/updateLocale' import utc from 'dayjs/plugin/utc' import localeData from 'dayjs/plugin/localeData' import { useStakingStore } from "./useStakingStore"; -import { fromBase64, toHex } from "@cosmjs/encoding"; +import { fromBase64, fromBech32, toHex } from "@cosmjs/encoding"; import { consensusPubkeyToHexAddress } from "@/libs"; import { useBankStore } from "./useBankStore"; import type { DenomTrace } from "@/types"; @@ -75,7 +75,6 @@ export const useFormatter = defineStore('formatter', { let denom = token.denom if( denom && denom.startsWith("ibc/")) { - console.log(denom) let ibcDenom = this.ibcDenoms[denom.replace("ibc/", "")] if(ibcDenom) { denom = ibcDenom.base_denom @@ -96,7 +95,7 @@ export const useFormatter = defineStore('formatter', { denom = unit.denom.toUpperCase() } } - return `${numeral(amount).format(fmt)} ${withDenom ? denom: ''}` + return `${numeral(amount).format(fmt)} ${withDenom ? denom.substring(0, 10): ''}` } return '-' }, @@ -109,20 +108,27 @@ export const useFormatter = defineStore('formatter', { const b = Number(pool.bonded_tokens) const nb = Number(pool.not_bonded_tokens) const p = b/(b+nb) - console.log(b, nb, p, pool) return numeral(p).format('0.[00]%') } return '-' }, validator(address: string) { + if(!address) return address + const txt = toHex(fromBase64(address)).toUpperCase() const validator = this.staking.validators.find(x => consensusPubkeyToHexAddress(x.consensus_pubkey) === txt) return validator?.description?.moniker }, + validatorFromBech32(address: string) { + if(!address) return address + const validator = this.staking.validators.find(x => x.operator_address === address) + return validator?.description?.moniker + }, calculatePercent(input?: string, total?: string|number ) { if(!input || !total) return '0' const percent = Number(input)/Number(total) - return numeral(percent).format("0.[00]%") + console.log(input, total, percent); + return numeral(percent>0.0001?percent: 0).format("0.[00]%") }, formatDecimalToPercent(decimal: string) { return numeral(decimal).format('0.[00]%') diff --git a/src/types/distribution.ts b/src/types/distribution.ts index 8c22a83a..6e53fa83 100644 --- a/src/types/distribution.ts +++ b/src/types/distribution.ts @@ -1,4 +1,4 @@ -import type { PaginatedResponse } from "./common" +import type { Coin, PaginatedResponse } from "./common" export interface DistributionParams { params: { @@ -9,6 +9,14 @@ export interface DistributionParams { } } +export interface DelegatorRewards { + rewards: { + validator_address: string, + reward: Coin[], + }[], + total: Coin[], +} + export interface PaginatedSlashes extends PaginatedResponse { slashes: any[] } \ No newline at end of file