chore: update incompatible data

This commit is contained in:
ducphamle2 2024-01-16 18:02:30 -08:00
parent 3bc6a3b660
commit 85ccf92330
No known key found for this signature in database
GPG Key ID: FA031B25C90F3E68
5 changed files with 71 additions and 50 deletions

View File

@ -46,6 +46,7 @@ import type {
SlashingExtension,
} from '@cosmjs/stargate/build/modules';
import type { BondStatusString } from '@cosmjs/stargate/build/modules/staking/queries';
import type { ProposalStatus } from 'cosmjs-types/cosmos/gov/v1beta1/gov';
export class BaseRestClient<R extends AbstractRegistry> {
endpoint: string;
@ -186,11 +187,11 @@ export class CosmosRestClient extends BaseRestClient<RequestRegistry> {
async getBankSupplyByDenom(denom: string) {
let supply;
try {
supply = this.queryClient?.bank.supplyOf(denom);
supply = await this.queryClient.bank.supplyOf(denom);
console.log(supply);
} catch (err) {
// will move this to sdk version profile later
console.log(err);
console.log('err getting bank supply: ', err);
}
return supply;
}
@ -291,7 +292,7 @@ export class CosmosRestClient extends BaseRestClient<RequestRegistry> {
console.log(res);
return res;
}
async getGovProposals(status: string, page?: PageRequest) {
async getGovProposals(status: ProposalStatus, page?: PageRequest) {
if (!page) page = new PageRequest();
page.reverse = true;
// const query = `?proposal_status={status}&${page.toQueryString()}`;
@ -300,17 +301,20 @@ export class CosmosRestClient extends BaseRestClient<RequestRegistry> {
? Buffer.from(page.key, 'base64')
: undefined;
// @ts-ignore
const res = this.queryClient.gov.proposals(status, '', '', paginationKey);
const res = await this.queryClient.gov.proposals(
status,
'',
'',
paginationKey
);
console.log(res);
return res;
}
async getGovProposal(proposal_id: string) {
return this.request(this.registry.gov_proposals_proposal_id, {
proposal_id,
});
return this.queryClient.gov.proposal(proposal_id);
}
async getGovProposalDeposits(proposal_id: string) {
return this.request(this.registry.gov_proposals_deposits, { proposal_id });
return this.queryClient.gov.deposits(proposal_id);
}
async getGovProposalTally(proposal_id: string) {
const res = await this.queryClient.gov.tally(proposal_id);
@ -411,16 +415,21 @@ export class CosmosRestClient extends BaseRestClient<RequestRegistry> {
// return this.request(this.registry.staking_params, {});
}
async getStakingPool() {
const res = await this.queryClient.staking.pool();
console.log(res);
return res;
// return this.request(this.registry.staking_pool, {});
// try {
// // const res = await this.queryClient.staking.pool();
// const res = await this.request(this.registry.staking_pool, {});
// console.log(res);
// return res;
// } catch (error) {
// console.log('error staking pool: ', error);
// }
return this.request(this.registry.staking_pool, {});
}
async getStakingValidators(status: BondStatusString, limit = 200) {
const res = await this.queryClient.staking.validators(status);
console.log(status, res);
return res;
// return this.request(this.registry.staking_validators, { status, limit });
// const res = await this.queryClient.staking.validators(status);
// console.log(status, res);
// return res;
return this.request(this.registry.staking_validators, { status, limit });
}
async getStakingValidator(validator_addr: string) {
// return this.request(this.registry.staking_validators_address, {

View File

@ -3,13 +3,14 @@ import { decodeTxRaw, type DecodedTxRaw } from '@cosmjs/proto-signing';
import { useBlockchain } from '@/stores';
import { hashTx } from '@/libs';
import type { Block } from '@/types';
import type { BlockResponse } from '@cosmjs/tendermint-rpc';
export const useBlockModule = defineStore('blockModule', {
state: () => {
return {
latest: {} as Block,
current: {} as Block,
recents: [] as Block[],
latest: {} as BlockResponse,
current: {} as BlockResponse,
recents: [] as BlockResponse[],
};
},
getters: {
@ -23,7 +24,7 @@ export const useBlockModule = defineStore('blockModule', {
txsInRecents() {
const txs = [] as { hash: string; tx: DecodedTxRaw }[];
this.recents.forEach((x) =>
x.block?.data?.txs.forEach((tx: Uint8Array) => {
x.block?.txs.forEach((tx: Uint8Array) => {
if (tx) {
try {
txs.push({

View File

@ -8,6 +8,18 @@ import { fromBase64 } from '@cosmjs/encoding';
import { useRouter } from 'vue-router';
import type { BlockResponse } from '@cosmjs/tendermint-rpc';
const compareHashEqual = (
firstHash: Uint8Array,
secondHash: Uint8Array
): boolean => {
for (let i = 0; i < firstHash.length; i++) {
if (firstHash[i] !== secondHash[i]) {
return false;
}
}
return true;
};
export const useBaseStore = defineStore('baseStore', {
state: () => {
return {
@ -99,11 +111,9 @@ export const useBaseStore = defineStore('baseStore', {
}
//check if the block exists in recents
if (
this.recents.findIndex(
(x) =>
Buffer.from(x?.blockId?.hash).toString('base64') ===
Buffer.from(this.latest?.blockId?.hash).toString('base64')
) === -1
this.recents.findIndex((x) => {
return compareHashEqual(x.blockId.hash, this.latest.blockId.hash);
}) === -1
) {
if (this.recents.length >= 50) {
this.recents.shift();

View File

@ -4,6 +4,7 @@ import type { PageRequest, PaginatedProposals } from '@/types';
import { LoadingStatus } from './useDashboard';
import { useWalletStore } from './useWalletStore';
import { reactive } from 'vue';
import { Proposal, ProposalStatus } from 'cosmjs-types/cosmos/gov/v1beta1/gov';
export const useGovStore = defineStore('govStore', {
state: () => {
@ -13,7 +14,7 @@ export const useGovStore = defineStore('govStore', {
voting: {},
tally: {},
},
proposals: {} as Record<string, PaginatedProposals>,
proposals: {} as Record<ProposalStatus, Proposal[]>,
loading: {} as Record<string, LoadingStatus>,
};
},
@ -29,9 +30,9 @@ export const useGovStore = defineStore('govStore', {
initial() {
this.$reset();
this.fetchParams();
this.fetchProposals('2');
this.fetchProposals(ProposalStatus.PROPOSAL_STATUS_VOTING_PERIOD);
},
async fetchProposals(status: string, pagination?: PageRequest) {
async fetchProposals(status: ProposalStatus, pagination?: PageRequest) {
//if (!this.loading[status]) {
this.loading[status] = LoadingStatus.Loading;
const proposals = reactive(
@ -46,35 +47,35 @@ export const useGovStore = defineStore('govStore', {
});
}
if (status === '2') {
if (status === ProposalStatus.PROPOSAL_STATUS_VOTING_PERIOD) {
proposals?.proposals?.forEach((item) => {
// this.fetchTally(item.proposalId.toString()).then((res) => {
// item.finalTallyResult = res?.tally;
// });
if (this.walletstore.currentAddress) {
try {
this.fetchProposalVotesVoter(
item.proposalId.toString(),
this.walletstore.currentAddress
)
.then((res) => {
item.status = res?.vote?.option || 'VOTE_OPTION_NO_WITH_VETO';
// 'No With Veto';
})
.catch((reject) => {
item.status = 'VOTE_OPTION_NO_WITH_VETO';
});
} catch (error) {
item.status = 'VOTE_OPTION_NO_WITH_VETO';
}
} else {
item.status = 'VOTE_OPTION_NO_WITH_VETO';
}
// if (this.walletstore.currentAddress) {
// try {
// this.fetchProposalVotesVoter(
// item.proposalId.toString(),
// this.walletstore.currentAddress
// )
// .then((res) => {
// item.status = res.vote.options[res.vote.options.length].option || 'VOTE_OPTION_NO_WITH_VETO';
// // 'No With Veto';
// })
// .catch((reject) => {
// item.status = 'VOTE_OPTION_NO_WITH_VETO';
// });
// } catch (error) {
// item.status = 'VOTE_OPTION_NO_WITH_VETO';
// }
// } else {
// item.status = 'VOTE_OPTION_NO_WITH_VETO';
// }
});
}
this.loading[status] = LoadingStatus.Loaded;
this.proposals[status] = proposals;
this.proposals[status] = proposals.proposals;
//}
return this.proposals[status];
},

View File

@ -102,7 +102,7 @@ export const useParamStore = defineStore('paramstore', {
// this.syncing = false
// }
// this.latestTime = toDay(res.block.header.time, 'long')
this.latestTime = res.block.header.time;
this.latestTime = res.block.header.time.toDateString();
} catch (error) {
console.warn(error);
}