diff --git a/src/libs/client.ts b/src/libs/client.ts index 7471391f..708ce37b 100644 --- a/src/libs/client.ts +++ b/src/libs/client.ts @@ -84,19 +84,13 @@ function setupExtraExtension(base: QueryClient) { extra: { accounts: async (page?: PageRequest) => { return await authQueryService.Accounts({ - pagination: CosmosPageRequest.fromPartial({ - key: page?.key ? fromBase64(page.key) : undefined, - reverse: page?.reverse ?? true, - }), + pagination: page?.toPagination(), }); }, 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, - }), + pagination: page?.toPagination(), }); }, proposals: async (proposalStatus: ProposalStatus, page?: PageRequest) => { @@ -104,10 +98,7 @@ function setupExtraExtension(base: QueryClient) { proposalStatus, voter: '', depositor: '', - pagination: CosmosPageRequest.fromPartial({ - key: page?.key ? fromBase64(page.key) : undefined, - reverse: page?.reverse ?? true, - }), + pagination: page?.toPagination(), }); }, }, @@ -229,7 +220,7 @@ export class CosmosRestClient extends BaseRestClient { } // Bank Module async getBankParams() { - return this.request(this.registry.bank_params, {}); + return await this.request(this.registry.bank_params, {}); // const res = await this.queryClient.bank } async getBankBalances(address: string) { @@ -368,12 +359,12 @@ export class CosmosRestClient extends BaseRestClient { async getGovProposals(status: ProposalStatus, page?: PageRequest) { if (!page) page = new PageRequest(); page.reverse = true; - const res = this.queryClient.extra.proposals(status, page); - console.log(res); + const res = await this.queryClient.extra.proposals(status, page); + console.log('getGovProposals', res); return res; } async getGovProposal(proposal_id: string) { - return this.queryClient.gov.proposal(proposal_id); + return await this.queryClient.gov.proposal(proposal_id); } async getGovProposalDeposits(proposal_id: string) { return this.queryClient.gov.deposits(proposal_id); diff --git a/src/types/common.ts b/src/types/common.ts index 37b04ad1..9679867d 100644 --- a/src/types/common.ts +++ b/src/types/common.ts @@ -1,3 +1,7 @@ +import { fromBase64 } from '@cosmjs/encoding'; +import { longify } from '@cosmjs/stargate/build/queryclient'; +import { PageRequest as CosmosPageRequest } from 'cosmjs-types/cosmos/base/query/v1beta1/pagination'; + export interface Key { '@type': string; key: string; @@ -20,25 +24,28 @@ export class PageRequest { offset?: number; count_total?: boolean; reverse?: boolean; + constructor(limit?: number, reverse?: boolean) { this.limit = limit ?? 20; this.count_total = true; this.reverse = reverse ?? false; } - toQueryString() { - const query = []; - if (this.key) query.push(`pagination.key=${this.key}`); - if (this.limit) query.push(`pagination.limit=${this.limit}`); - if (this.offset !== undefined) - query.push(`pagination.offset=${this.offset}`); - if (this.count_total) - query.push(`pagination.count_total=${this.count_total}`); - if (this.reverse) query.push(`pagination.reverse=${this.reverse}`); - return query.join('&'); + + toPagination() { + const pagination = CosmosPageRequest.fromPartial({ + key: this.key ? fromBase64(this.key) : undefined, + countTotal: true, + offset: this.offset ? longify(this.offset) : undefined, + limit: this.limit ? longify(this.limit) : undefined, + reverse: this.reverse ?? true, + }); + return pagination; } + setPage(page: number) { if (page >= 1) this.offset = (page - 1) * this.limit; } + setPageSize(size: number) { this.limit = size; }