From d57c9f145a8a01b3b3a9eadea5a8d13f27760bd7 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 6 Jan 2025 17:20:53 +0530 Subject: [PATCH 1/4] fix: Use etherscan API v2 to use it for multichain (#1081) --- apps/ui/src/helpers/etherscan.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/apps/ui/src/helpers/etherscan.ts b/apps/ui/src/helpers/etherscan.ts index 8b0070c86..484659a3f 100644 --- a/apps/ui/src/helpers/etherscan.ts +++ b/apps/ui/src/helpers/etherscan.ts @@ -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); From e79b4ef93917c672746a558807dd98b707c1e409 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 6 Jan 2025 17:40:46 +0530 Subject: [PATCH 2/4] fix: refresh scores once proposal is closed (#1077) * fix: refresh scores once proposal is closed * fix * fix: check for offchain spaces * fix: reset instead of reload --- apps/ui/src/components/ProposalResults.vue | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/apps/ui/src/components/ProposalResults.vue b/apps/ui/src/components/ProposalResults.vue index 78617a6e8..34bf3f174 100644 --- a/apps/ui/src/components/ProposalResults.vue +++ b/apps/ui/src/components/ProposalResults.vue @@ -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; @@ -26,6 +27,8 @@ const props = withDefaults( } ); +const proposalsStore = useProposalsStore(); + const displayAllChoices = ref(false); const totalProgress = computed(() => quorumProgress(props.proposal)); @@ -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(); + } +});