Skip to content

Commit

Permalink
feat: eclesia indexer support & fixes (#109)
Browse files Browse the repository at this point in the history
* feat: Eclesia Indexer updates

* fix: Validator set at height

* fix: History layout

* fix: lint errors

* fix: minor query error

* fix: more linting
  • Loading branch information
clockworkgr authored Jul 30, 2024
1 parent e876a88 commit 81928c8
Show file tree
Hide file tree
Showing 16 changed files with 5,671 additions and 4,323 deletions.
4 changes: 3 additions & 1 deletion src/components/helper/DelegatedTotal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ watch(height, async (newHeight, oldHeight) => {
try {
const dq = await getDelegatedAsync(address, newHeight.block[0].height);
if (dq) {
delegated.value = dq.action_delegation_total?.coins as Coin[];
delegated.value = dq.staked_balances.map((x) => {
return x.amount;
});
} else {
delegated.value = [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/helper/UserBalance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { getBalance } = useChainData();
const balances = getBalance(address);
const balance = computed(() => {
let bal = balances.value?.action_account_balance?.coins?.filter((x) => x.denom == denom)[0];
let bal = balances.value?.action_account_balance[0].coins?.filter((x) => x.denom == denom)[0];
if (bal) {
return bal;
} else {
Expand Down
11 changes: 8 additions & 3 deletions src/components/history/VoteHistory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ function prev() {
}
</script>
<template>
<div class="flex flex-col w-full pb-[72px]">
<div class="flex flex-col w-full">
<ProposalList
v-if="activeProposals && activeProposals.length > 0"
:address="address"
:proposals="activeProposals"
:title="$t('voteHistory.activeHeader')"
class="pb-[72px]"
/>
<ProposalList
v-if="pastProposals && pastProposals.length > 0"
Expand Down Expand Up @@ -107,7 +108,9 @@ function prev() {
:class="{ 'text-light hover:opacity-75 cursor-pointer': hasMore }"
@click="
() => {
next();
if (hasMore) {
next();
}
}
"
/>
Expand All @@ -117,7 +120,9 @@ function prev() {
:class="{ 'text-light hover:opacity-75 cursor-pointer': hasMore }"
@click="
() => {
offset = Math.floor((proposals?.proposal_aggregate.aggregate?.count ?? 0) / limit) * limit;
if (hasMore) {
offset = Math.floor((proposals?.proposal_aggregate.aggregate?.count ?? 0) / limit) * limit;
}
}
"
/>
Expand Down
13 changes: 5 additions & 8 deletions src/components/proposals/ProposalWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ const props = defineProps<{
height: number;
}>();
const { getProposal, getParams, getProposalTallies, getStakingStatus, getVotesAsync, getVoteOption } = useChainData();
const { validators, getVotingPower } = useValidators(
props.proposalId,
props.height != 0 ? props.height.toString() : undefined,
);
const { validators, getVotingPower } = useValidators(props.height != 0 ? props.height.toString() : undefined);
const validatorsWithStakeAndVotes = ref<
Array<
(ValidatorsQuery["validator_status"][0] | ValSetQuery["proposal_validator_status_snapshot"][0]) & {
Expand All @@ -64,9 +61,9 @@ watch(validators, async (valSet, _old) => {
try {
validatorsWithStakeAndVotes.value = await Promise.all(
valSet.map(async (val) => {
if (val.validator.validator_info && val.validator.validator_info.self_delegate_address) {
const vp = await getVotingPower(val.validator.validator_info.self_delegate_address);
const votes = await getVotesAsync(val.validator.validator_info.self_delegate_address, props.proposalId);
if (val.validator_info && val.validator_info.self_delegate_address) {
const vp = await getVotingPower(val.validator_info.self_delegate_address);
const votes = await getVotesAsync(val.validator_info.self_delegate_address, props.proposalId);
if (votes && votes.proposal_vote.length > 0) {
return {
...val,
Expand Down Expand Up @@ -191,7 +188,7 @@ function getValidatorVotes(voteType: VoteTypes) {
data.push({
name:
validatorsWithStakeAndVotes.value[i].validator.validator_descriptions[0].moniker ??
validatorsWithStakeAndVotes.value[i].validator_info.validator_descriptions[0].moniker ??
validatorsWithStakeAndVotes.value[i].validator_address,
value: tally[voteType],
});
Expand Down
4 changes: 2 additions & 2 deletions src/components/proposals/ValidatorBreakdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const getTxHash = (vote: VotesQuery["proposal_vote"][0]) => {
}
};
const getValidatorInfo = (address: string) => {
return props.validatorData.filter((x) => x.validator.validator_info?.self_delegate_address == address)[0].validator
return props.validatorData.filter((x) => x.validator_info?.self_delegate_address == address)[0].validator_info
.validator_descriptions[0];
};
</script>
Expand Down Expand Up @@ -64,7 +64,7 @@ const getValidatorInfo = (address: string) => {
</template>
<template v-else>
<div :key="validator.validator_address" class="grid grid-cols-5 py-4 w-full text-200 text-grey-50">
<span>{{ getValidatorInfo(validator.validator.validator_info?.self_delegate_address ?? "").moniker }}</span>
<span>{{ getValidatorInfo(validator.validator_info?.self_delegate_address ?? "").moniker }}</span>
<span> - </span>
<span>{{ $t("components.Breakdown.hasNotVoted") }}</span>
<span>-</span>
Expand Down
34 changes: 26 additions & 8 deletions src/composables/useChainData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,20 @@ export const useChainData = () => {
return result;
};
const getDelegated = (address: string, height?: number) => {
const { result } = useDelegatedQuery({ address, height });
return result;
if (height) {
const where = { _and: [{ height: { _lte: height } }, { delegator: { _eq: address } }] };
const { result } = useDelegatedQuery({ where });

return result;
} else {
const where = { delegator: { _eq: address } };
const { result } = useDelegatedQuery({ where });

return result;
}
};
const getValset = (proposalId: number, height: string) => {
const { result } = useValsetQuery({ proposalId, height });
const getValset = (height: string) => {
const { result } = useValsetQuery({ height });
return result;
};
const getValidators = () => {
Expand Down Expand Up @@ -263,11 +272,20 @@ export const useChainData = () => {
return result;
};
const getDelegatedAsync = async (address: string, height?: number) => {
const result = await useLazyDelegatedQuery({ address, height }).load();
return result;
if (height) {
const where = { _and: [{ height: { _lte: height } }, { delegator: { _eq: address } }] };
const result = useLazyDelegatedQuery({ where }).load();

return result;
} else {
const where = { delegator: { _eq: address } };
const result = useLazyDelegatedQuery({ where }).load();

return result;
}
};
const getValsetAsync = async (proposalId: number, height: string) => {
const result = await useLazyValsetQuery({ proposalId, height }).load();
const getValsetAsync = async (height: string) => {
const result = await useLazyValsetQuery({ height }).load();
return result;
};
const getValidatorsAsync = async () => {
Expand Down
12 changes: 7 additions & 5 deletions src/composables/useValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { provideApolloClient } from "@vue/apollo-composable";
import apolloClient from "@/apolloClient";

const { getValset, getDelegatedAsync, getValidators } = useChainData();
export const useValidators = (proposal_id: number, height?: string) => {
const validatorList = height ? getValset(proposal_id, height) : getValidators();
export const useValidators = (height?: string) => {
const validatorList = height ? getValset(height) : getValidators();
const validators = computed(() => {
if (validatorList.value) {
return "proposal_validator_status_snapshot" in validatorList.value
Expand All @@ -17,10 +17,12 @@ export const useValidators = (proposal_id: number, height?: string) => {
});
const getVotingPower = async (address: string) => {
provideApolloClient(apolloClient);
// This should be adjusted to get the full delegated voting power on chains utilising teh standard Cosmos SDK gov module
// This should be adjusted to get the full delegated voting power on chains utilising the standard Cosmos SDK gov module
const delegated = height ? await getDelegatedAsync(address, parseInt(height)) : await getDelegatedAsync(address);
if (delegated && delegated.action_delegation_total && delegated.action_delegation_total.coins) {
return parseInt(delegated.action_delegation_total.coins[0].amount);
if (delegated && delegated.staked_balances && delegated.staked_balances.length > 0) {
return delegated.staked_balances.reduce((total, stakedBalance) => {
return total + parseInt(stakedBalance.amount.amount);
}, 0);
} else {
return 0;
}
Expand Down
Loading

0 comments on commit 81928c8

Please sign in to comment.