remove Buffer

This commit is contained in:
Pham Tu 2024-01-17 10:13:59 +07:00
commit 9e7ad421b9
No known key found for this signature in database
GPG Key ID: 7460FD99133ADA1C
5 changed files with 58 additions and 42 deletions

View File

@ -186,11 +186,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;
}
@ -303,12 +303,10 @@ export class CosmosRestClient extends BaseRestClient<RequestRegistry> {
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);
@ -407,9 +405,14 @@ 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;
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) {

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, toBase64 } 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 {

View File

@ -5,10 +5,10 @@ import type { PageRequest, PaginatedProposals } from '@/types';
import { LoadingStatus } from './useDashboard';
import { useWalletStore } from './useWalletStore';
import { reactive } from 'vue';
import { toBase64 } from '@cosmjs/encoding';
import {
Proposal,
ProposalStatus,
TextProposal,
type ProposalStatus,
} from 'cosmjs-types/cosmos/gov/v1beta1/gov';
export const useGovStore = defineStore('govStore', {
@ -19,7 +19,7 @@ export const useGovStore = defineStore('govStore', {
voting: {},
tally: {},
},
proposals: {} as Record<string, PaginatedProposals>,
proposals: {} as Record<ProposalStatus, Proposal[]>,
loading: {} as Record<string, LoadingStatus>,
};
},
@ -35,7 +35,7 @@ export const useGovStore = defineStore('govStore', {
initial() {
this.$reset();
this.fetchParams();
this.fetchProposals(2);
this.fetchProposals(ProposalStatus.PROPOSAL_STATUS_VOTING_PERIOD);
},
async fetchProposals(status: ProposalStatus, pagination?: PageRequest) {
//if (!this.loading[status]) {
@ -56,35 +56,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';
}
// 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.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);
}