diff --git a/package.json b/package.json index 08c20a26..943b1f98 100644 --- a/package.json +++ b/package.json @@ -76,5 +76,8 @@ "vite-plugin-pages": "^0.28.0", "vue-json-viewer": "3", "vue-tsc": "^1.0.12" + }, + "resolutions": { + "cosmjs-types": "^0.9.0" } } diff --git a/src/components/ProposalListItem.vue b/src/components/ProposalListItem.vue index 36e5aa2f..fa8745ba 100644 --- a/src/components/ProposalListItem.vue +++ b/src/components/ProposalListItem.vue @@ -10,7 +10,6 @@ import type { PaginatedProposals } from '@/types'; import ProposalProcess from './ProposalProcess.vue'; import type { PropType } from 'vue'; import { computed, ref } from 'vue'; -import { fromTimestamp } from 'cosmjs-types/helpers'; import type { QueryProposalsResponse } from 'cosmjs-types/cosmos/gov/v1beta1/query'; const dialog = useTxDialog(); defineProps({ @@ -117,7 +116,7 @@ function metaItem(metadata: string | undefined): {
- {{ format.toDay(fromTimestamp(item.votingEndTime), 'from') }} + {{ format.toDay(item.votingEndTime, 'from') }}
@@ -185,7 +184,7 @@ function metaItem(metadata: string | undefined): {
- {{ format.toDay(fromTimestamp(item.votingEndTime), 'from') }} + {{ format.toDay(item.votingEndTime, 'from') }}
diff --git a/src/components/ValidatorCommissionRate.vue b/src/components/ValidatorCommissionRate.vue index a84ebd3e..b42692d1 100644 --- a/src/components/ValidatorCommissionRate.vue +++ b/src/components/ValidatorCommissionRate.vue @@ -2,8 +2,6 @@ import ApexCharts from 'vue3-apexcharts'; import { computed, type PropType } from 'vue'; import { useFormatter } from '@/stores'; -import { fromTimestamp } from 'cosmjs-types/helpers'; -import type { CommissionRate } from '@/types'; import type { Commission } from 'cosmjs-types/cosmos/staking/v1beta1/staking'; const props = defineProps({ @@ -128,12 +126,7 @@ const chartConfig = computed(() => {
Commission Rate
- {{ - `Updated at ${format.toDay( - fromTimestamp(props.commission?.updateTime!), - 'short' - )}` - }} + {{ `Updated at ${format.toDay(props.commission?.updateTime, 'short')}` }}
diff --git a/src/components/dynamic/index.ts b/src/components/dynamic/index.ts index 3b39a53f..e3687673 100644 --- a/src/components/dynamic/index.ts +++ b/src/components/dynamic/index.ts @@ -51,7 +51,9 @@ const typeMap = Object.fromEntries( Object.entries(MsgType).map(([k, v]) => ['/' + v, k]) ); -type TxType = keyof typeof MsgType; +Object.assign(typeMap, { + '/cosmos.params.v1beta1.ParameterChangeProposal': 'ParameterChangeProposal', +}); const findType = (obj: any, type: string): any => { if (typeof obj !== 'object') return; diff --git a/src/libs/client.ts b/src/libs/client.ts index de64f779..7471391f 100644 --- a/src/libs/client.ts +++ b/src/libs/client.ts @@ -13,10 +13,13 @@ import { setupGovExtension, type GovProposalId, type IbcExtension, + type AuthExtension, + type DistributionExtension, setupIbcExtension, setupSlashingExtension, setupDistributionExtension, createProtobufRpcClient, + setupAuthExtension, } from '@cosmjs/stargate'; import { HttpClient, @@ -40,38 +43,72 @@ import { withCustomRequest, } from './registry'; import { buildQuery } from '@cosmjs/tendermint-rpc/build/tendermint37/requests'; -import { PageRequest, type Coin } from '@/types'; -import type { - DistributionExtension, - SlashingExtension, -} from '@cosmjs/stargate/build/modules'; +import { PageRequest } from '@/types'; +import { PageRequest as CosmosPageRequest } from 'cosmjs-types/cosmos/base/query/v1beta1/pagination'; import type { BondStatusString } from '@cosmjs/stargate/build/modules/staking/queries'; import type { ProposalStatus } from 'cosmjs-types/cosmos/gov/v1beta1/gov'; import { fromBase64 } from '@cosmjs/encoding'; import { QueryAccountsResponse, - QueryClientImpl, + QueryClientImpl as AuthQueryClientImpl, } from 'cosmjs-types/cosmos/auth/v1beta1/query'; +import { + QueryVotesResponse, + QueryClientImpl as GovQueryClientImpl, + QueryProposalsResponse, +} from 'cosmjs-types/cosmos/gov/v1beta1/query'; + import type { Any } from 'cosmjs-types/google/protobuf/any'; import { BaseAccount } from 'cosmjs-types/cosmos/auth/v1beta1/auth'; +import type { SlashingExtension } from '@cosmjs/stargate/build/modules'; +import { longify } from '@cosmjs/stargate/build/queryclient'; -export interface AuthExtension { - readonly auth: { - readonly account: (address: string) => Promise; - readonly accounts: () => Promise; +export interface ExtraExtension { + readonly extra: { + readonly accounts: (page?: PageRequest) => Promise; + readonly votes: ( + proposalId: GovProposalId, + page?: PageRequest + ) => Promise; + readonly proposals: ( + proposalStatus: ProposalStatus, + page?: PageRequest + ) => Promise; }; } -function setupAuthExtension(base: QueryClient) { +function setupExtraExtension(base: QueryClient) { const rpc = createProtobufRpcClient(base); - const queryService = new QueryClientImpl(rpc); + const authQueryService = new AuthQueryClientImpl(rpc); + const govQueryService = new GovQueryClientImpl(rpc); return { - auth: { - account: async (address: string) => { - const { account } = await queryService.Account({ address: address }); - return account?.value ? BaseAccount.decode(account.value) : undefined; + extra: { + accounts: async (page?: PageRequest) => { + return await authQueryService.Accounts({ + pagination: CosmosPageRequest.fromPartial({ + key: page?.key ? fromBase64(page.key) : undefined, + reverse: page?.reverse ?? true, + }), + }); }, - accounts: async () => { - return await queryService.Accounts(); + votes: async (proposalId: GovProposalId, page?: PageRequest) => { + return await govQueryService.Votes({ + proposalId: longify(proposalId), + pagination: CosmosPageRequest.fromPartial({ + key: page?.key ? fromBase64(page.key) : undefined, + reverse: page?.reverse ?? true, + }), + }); + }, + proposals: async (proposalStatus: ProposalStatus, page?: PageRequest) => { + return await govQueryService.Proposals({ + proposalStatus, + voter: '', + depositor: '', + pagination: CosmosPageRequest.fromPartial({ + key: page?.key ? fromBase64(page.key) : undefined, + reverse: page?.reverse ?? true, + }), + }); }, }, }; @@ -91,7 +128,8 @@ export class BaseRestClient { IbcExtension & SlashingExtension & DistributionExtension & - TxExtension; + TxExtension & + ExtraExtension; constructor(endpoint: string, registry: R) { this.endpoint = endpoint; @@ -116,7 +154,8 @@ export class BaseRestClient { setupIbcExtension, setupSlashingExtension, setupDistributionExtension, - setupTxExtension + setupTxExtension, + setupExtraExtension ); } @@ -178,7 +217,7 @@ export class CosmosRestClient extends BaseRestClient { // if (!page) page = new PageRequest(); // const query = `?${page.toQueryString()}`; // return this.request(this.registry.auth_accounts, {}, query); - const res = await this.queryClient.auth.accounts(); + const res = await this.queryClient.extra.accounts(page); console.log(res); return res; } @@ -301,8 +340,12 @@ export class CosmosRestClient extends BaseRestClient { } // Gov async getParams(subspace: string, key: string) { - console.log(this.registry.params, subspace, key); - return this.request(this.registry.params, { subspace, key }); + // console.log(this.registry.params, subspace, key); + // return this.request(this.registry.params, { subspace, key }); + switch (subspace) { + case 'distribution': + return await this.getDistributionParams(); + } } async getGovParamsVoting() { // return this.request(this.registry.gov_params_voting, {}); @@ -325,11 +368,7 @@ export class CosmosRestClient extends BaseRestClient { async getGovProposals(status: ProposalStatus, page?: PageRequest) { if (!page) page = new PageRequest(); page.reverse = true; - // const query = `?proposal_status={status}&${page.toQueryString()}`; - // return this.request(this.registry.gov_proposals, { status }, query); - const paginationKey = page?.key ? fromBase64(page.key) : undefined; - - const res = this.queryClient.gov.proposals(status, '', '', paginationKey); + const res = this.queryClient.extra.proposals(status, page); console.log(res); return res; } @@ -361,7 +400,7 @@ export class CosmosRestClient extends BaseRestClient { // } // ); } - async getGovProposalVotes(proposal_id: string, page?: PageRequest) { + async getGovProposalVotes(proposal_id: GovProposalId, page?: PageRequest) { // if (!page) page = new PageRequest(); // page.reverse = true; // const query = `?proposal_status={status}&${page.toQueryString()}`; @@ -371,9 +410,9 @@ export class CosmosRestClient extends BaseRestClient { // query // ); - const paginationKey = page?.key ? fromBase64(page.key) : undefined; - const res = await this.queryClient.gov.votes(proposal_id, paginationKey); - console.log(res); + // const paginationKey = page?.key ? fromBase64(page.key) : undefined; + const res = await this.queryClient.extra.votes(proposal_id, page); + console.log('vote', proposal_id, res); return res; } async getGovProposalVotesVoter(proposal_id: string, voter: string) { diff --git a/src/modules/[chain]/gov/[proposal_id].vue b/src/modules/[chain]/gov/[proposal_id].vue index 69e58d46..30893093 100644 --- a/src/modules/[chain]/gov/[proposal_id].vue +++ b/src/modules/[chain]/gov/[proposal_id].vue @@ -1,5 +1,6 @@