diff --git a/src/components/PaginationBar.vue b/src/components/PaginationBar.vue
new file mode 100644
index 00000000..99ae0858
--- /dev/null
+++ b/src/components/PaginationBar.vue
@@ -0,0 +1,42 @@
+
+
+
+
diff --git a/src/components/ProposalListItem.vue b/src/components/ProposalListItem.vue
index f7cd88be..cc4e00cd 100644
--- a/src/components/ProposalListItem.vue
+++ b/src/components/ProposalListItem.vue
@@ -54,7 +54,7 @@ const proposalInfo = ref();
#{{ item?.proposal_id }}
-
+ |
|
-
+ |
|
-
+ |
-
{{ item?.badgeContent }}
diff --git a/src/libs/client.ts b/src/libs/client.ts
index 483e4d21..4085822e 100644
--- a/src/libs/client.ts
+++ b/src/libs/client.ts
@@ -8,6 +8,7 @@ import {
type Registry,
type AbstractRegistry,
} from './registry';
+import { PageRequest } from '@/types';
export class BaseRestClient {
endpoint: string;
@@ -98,10 +99,11 @@ export class CosmosRestClient extends BaseRestClient {
async getGovParamsTally() {
return this.request(this.registry.gov_params_tally, {});
}
- async getGovProposals(status: string, limit = 20) {
- const query =
- '?proposal_status={status}&pagination.limit={limit}&pagination.reverse=true&pagination.key=';
- return this.request(this.registry.gov_proposals, { status, limit }, query);
+ async getGovProposals(status: string, 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);
}
async getGovProposal(proposal_id: string) {
return this.request(this.registry.gov_proposals_proposal_id, {
diff --git a/src/libs/registry.ts b/src/libs/registry.ts
index 0b47f38d..7d02093e 100644
--- a/src/libs/registry.ts
+++ b/src/libs/registry.ts
@@ -42,7 +42,7 @@ import type {
Validator,
} from '@/types/staking';
import type { PaginatedTxs, Tx, TxResponse } from '@/types/tx';
-
+import semver from 'semver'
export interface Request {
url: string;
adapter: (source: any) => T;
diff --git a/src/modules/[chain]/gov/index.vue b/src/modules/[chain]/gov/index.vue
index b6c528a8..3fcaa323 100644
--- a/src/modules/[chain]/gov/index.vue
+++ b/src/modules/[chain]/gov/index.vue
@@ -2,8 +2,13 @@
import { useGovStore } from '@/stores';
import ProposalListItem from '@/components/ProposalListItem.vue';
import { ref, onMounted } from 'vue';
+import PaginationBar from '@/components/PaginationBar.vue';
+import { PageRequest } from '@/types';
+
const tab = ref('2');
const store = useGovStore();
+const pageNo = ref({} as Record)
+const pageRequest = ref(new PageRequest())
onMounted(() => {
store.fetchProposals('2').then((x) => {
@@ -11,17 +16,25 @@ onMounted(() => {
tab.value = '3';
store.fetchProposals('3');
}
+ store.fetchProposals('3');
+ store.fetchProposals('4');
});
});
const changeTab = (val: '2' | '3' | '4') => {
tab.value = val;
- store.fetchProposals(val);
};
+
+function page(p: number) {
+ pageNo.value[tab.value] = p
+ pageRequest.value.setPage(p)
+ store.fetchProposals(tab.value, pageRequest.value)
+}
+
-
diff --git a/src/stores/useGovStore.ts b/src/stores/useGovStore.ts
index 33fd62f9..1554c6a6 100644
--- a/src/stores/useGovStore.ts
+++ b/src/stores/useGovStore.ts
@@ -32,10 +32,10 @@ export const useGovStore = defineStore('govStore', {
this.fetchProposals("2");
},
async fetchProposals(status: string, pagination?: PageRequest) {
- if (!this.loading[status]) {
+ //if (!this.loading[status]) {
this.loading[status] = LoadingStatus.Loading;
const proposals = reactive(
- await this.blockchain.rpc?.getGovProposals(status)
+ await this.blockchain.rpc?.getGovProposals(status, pagination)
);
if (status === '2') {
proposals?.proposals?.forEach((item) => {
@@ -44,7 +44,7 @@ export const useGovStore = defineStore('govStore', {
});
if (this.walletstore.currentAddress) {
try {
- this.fetchProposalVotesVoter(item.proposal_id,this.walletstore.currentAddress).then((res) => {
+ this.fetchProposalVotesVoter(item.proposal_id, this.walletstore.currentAddress).then((res) => {
item.voterStatus = res?.vote?.option || 'No With Veto'
});
} catch (error) {
@@ -55,10 +55,10 @@ export const useGovStore = defineStore('govStore', {
}
});
}
-
+
this.loading[status] = LoadingStatus.Loaded;
this.proposals[status] = proposals;
- }
+ //}
return this.proposals[status];
},
async fetchParams() {
diff --git a/src/types/common.ts b/src/types/common.ts
index 580b107c..4e7957de 100644
--- a/src/types/common.ts
+++ b/src/types/common.ts
@@ -15,7 +15,28 @@ export interface Pagination {
}
export class PageRequest {
- limit?: number;
+ key?: string;
+ limit: number;
+ offset?: number;
+ count_total: boolean;
+ reverse?: boolean;
+ constructor() {
+ this.limit = 20
+ this.count_total = true
+ }
+ toQueryString() {
+ const query = []
+ if(this.key) query.push(`pagination.key=${this.key}`)
+ if(this.limit) query.push(`pagination.limit=${this.limit}`)
+ if(this.offset) 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('&')
+ }
+ setPage(page: number) {
+ if(page >= 1) this.offset = (page - 1) * this.limit
+ }
+
}
export interface PaginatedResponse {
|