Skip to content

Commit

Permalink
Merge branch 'master' into author-privacy-selection
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaituVR authored Jan 6, 2025
2 parents 5bb96a4 + ba39f6d commit e62dee4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 21 deletions.
2 changes: 1 addition & 1 deletion apps/ui/src/components/EditorTimeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function formatVotingDuration(
:data="
isOffchainSpace || !editable
? {
...space,
network: space.network,
created,
start,
min_end,
Expand Down
29 changes: 29 additions & 0 deletions apps/ui/src/components/ProposalResults.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
quorumProgress
} from '@/helpers/quorum';
import { _n, _p, _vp } from '@/helpers/utils';
import { getNetwork, offchainNetworks } from '@/networks';
import { Proposal as ProposalType } from '@/types';
const DEFAULT_MAX_CHOICES = 6;
Expand All @@ -26,6 +27,8 @@ const props = withDefaults(
}
);
const proposalsStore = useProposalsStore();
const displayAllChoices = ref(false);
const totalProgress = computed(() => quorumProgress(props.proposal));
Expand Down Expand Up @@ -94,6 +97,32 @@ const isFinalizing = computed(() => {
['passed', 'executed', 'rejected'].includes(props.proposal.state)
);
});
async function refreshScores() {
try {
const network = getNetwork(props.proposal.network);
const hubUrl = network.api.apiUrl.replace('/graphql', '');
const response = await fetch(`${hubUrl}/api/scores/${props.proposal.id}`);
const result = await response.json();
if (result.result === true) {
proposalsStore.reset(props.proposal.space.id, props.proposal.network);
await proposalsStore.fetchProposal(
props.proposal.space.id,
props.proposal.id,
props.proposal.network
);
}
} catch (e) {
console.warn('Failed to refresh scores', e);
}
}
onMounted(() => {
if (offchainNetworks.includes(props.proposal.network) && isFinalizing.value) {
refreshScores();
}
});
</script>

<template>
Expand Down
10 changes: 8 additions & 2 deletions apps/ui/src/components/ProposalTimeline.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { _t } from '@/helpers/utils';
import { Proposal, Space } from '@/types';
import { NetworkID, Proposal, Space } from '@/types';
type ProposalTimelineValues = {
created?: number;
Expand All @@ -9,12 +9,18 @@ type ProposalTimelineValues = {
max_end: number;
};
type ProposalTimelineInput = {
network: NetworkID;
} & ProposalTimelineValues;
type State = {
id: keyof typeof LABELS;
value: number;
};
const props = defineProps<{ data: Proposal | Space }>();
const props = defineProps<{
data: Proposal | Space | ProposalTimelineInput;
}>();
const LABELS = {
created: 'Created',
Expand Down
12 changes: 3 additions & 9 deletions apps/ui/src/helpers/etherscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@ import { call } from './call';
import { getProvider } from './provider';

export async function getABI(chainId: number, address: string) {
let apiHost: string;
if (chainId === 1) apiHost = 'https://api.etherscan.io';
else if (chainId === 10) apiHost = 'https://api-optimistic.etherscan.io';
else if (chainId === 137) apiHost = 'https://api.polygonscan.com';
else if (chainId === 8453) apiHost = 'https://api.basescan.org';
else if (chainId === 42161) apiHost = 'https://api.arbiscan.io';
else if (chainId === 11155111) apiHost = 'https://api-sepolia.etherscan.io';
else throw new Error('Unsupported chainId');
const apiHost = `https://api.etherscan.io/v2/api`;

const params = new URLSearchParams({
chainid: chainId.toString(),
module: 'contract',
action: 'getAbi',
address,
apikey: import.meta.env.VITE_ETHERSCAN_API_KEY || ''
});

const res = await fetch(`${apiHost}/api?${params}`);
const res = await fetch(`${apiHost}?${params}`);
const { result } = await res.json();
const abi = JSON.parse(result);

Expand Down
18 changes: 9 additions & 9 deletions apps/ui/src/stores/votingPowers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ export function getIndex(space: SpaceDetails, block: number | null): string {
// we probably should separate it entirely (no more multipurpose VotingPowerItem)
// as it it's causing bugs and it's hard to understand

const prefix = isSpace(space) ? 'space' : 'proposal';
const prefix = getIsSpace(space) ? 'space' : 'proposal';

return `${prefix}:${space.id}:${block ?? LATEST_BLOCK_NAME}`;
}

function isSpace(item: SpaceDetails | Proposal): item is Space {
function getIsSpace(item: SpaceDetails | Proposal): item is Space {
return 'proposal_threshold' in item;
}

function isSpaceMember(space: Space, account: string): boolean {
function getIsSpaceMember(space: Space, account: string): boolean {
return [
...(space.additionalRawData?.admins || []),
...(space.additionalRawData?.moderators || []),
Expand All @@ -57,13 +57,15 @@ export const useVotingPowersStore = defineStore('votingPowers', () => {
if (existingVotingPower && existingVotingPower.status === 'success') return;

const network = getNetwork(item.network);
const isSpace = getIsSpace(item);
const isSpaceMember = getIsSpaceMember(space as Space, account);

let vpItem: VotingPowerItem = {
status: 'loading',
votingPowers: [],
symbol: space.voting_power_symbol,
error: null,
canPropose: false,
canPropose: isSpaceMember,
canVote: false
};

Expand All @@ -87,7 +89,7 @@ export const useVotingPowersStore = defineStore('votingPowers', () => {
account,
opts
),
isSpace(item)
isSpace && !isSpaceMember
? network.actions.getVotingPower(
space.id,
item.voting_power_validation_strategy_strategies,
Expand All @@ -105,15 +107,13 @@ export const useVotingPowersStore = defineStore('votingPowers', () => {
status: 'success'
};

if (isSpace(item) && proposeVp) {
if (isSpace && proposeVp) {
const totalProposeVp = proposeVp.reduce(
(acc, b) => acc + Number(b.value) / 10 ** b.cumulativeDecimals,
0
);

vpItem.canPropose =
totalProposeVp >= BigInt(item.proposal_threshold) ||
isSpaceMember(space as Space, account);
vpItem.canPropose = totalProposeVp >= BigInt(item.proposal_threshold);
} else {
vpItem.canVote = vp.some(vp => vp.value > 0n);
}
Expand Down

0 comments on commit e62dee4

Please sign in to comment.