Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use decimals of each strategy to calculate voting power #1037

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions apps/ui/src/components/Modal/VotingPower.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,10 @@ const loading = computed(
/>
<div class="text-skin-link shrink-0">
{{
_n(
Number(strategy.value) / 10 ** votingPower.decimals,
'compact',
{
maximumFractionDigits: 2,
formatDust: true
}
)
_n(Number(strategy.value) / 10 ** strategy.decimals, 'compact', {
maximumFractionDigits: 2,
formatDust: true
})
}}
{{ votingPower.symbol }}
</div>
Expand Down
7 changes: 5 additions & 2 deletions apps/ui/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,11 @@ export function getSocialNetworksLink(data: any) {
export function getFormattedVotingPower(votingPower?: VotingPowerItem) {
if (!votingPower) return;

const { totalVotingPower, decimals, symbol } = votingPower;
const value = _vp(Number(totalVotingPower) / 10 ** decimals);
const { votingPowers, symbol } = votingPower;

const value = _vp(
votingPowers.reduce((acc, b) => acc + Number(b.value) / 10 ** b.decimals, 0)
);
Sekhmet marked this conversation as resolved.
Show resolved Hide resolved

return symbol ? `${value} ${symbol}` : value;
}
Expand Down
15 changes: 7 additions & 8 deletions apps/ui/src/views/SpaceUser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,18 @@ const socials = computed(() => getSocialNetworksLink(user.value));
const cb = computed(() => getCacheHash(user.value?.avatar));

const formattedVotingPower = computed(() => {
const votingPower = votingPowers.value.reduce((acc, b) => acc + b.value, 0n);
const decimals = Math.max(
...votingPowers.value.map(votingPower => votingPower.decimals),
0
const votingPower = _vp(
votingPowers.value.reduce(
(acc, b) => acc + Number(b.value) / 10 ** b.decimals,
0
)
);

const value = _vp(Number(votingPower) / 10 ** decimals);

if (props.space.voting_power_symbol) {
return `${value} ${props.space.voting_power_symbol}`;
return `${votingPower} ${props.space.voting_power_symbol}`;
}

return value;
return votingPower;
});

const navigation = computed(() => [
Expand Down