From 8d40a15d9d73f5cc72d8131b4f37c384fc8bf84d Mon Sep 17 00:00:00 2001 From: Alexander Belokon Date: Tue, 20 Feb 2024 12:24:50 +0100 Subject: [PATCH 1/2] refactor: add dRPC to csp rules --- modules/shared/utils/csp.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/shared/utils/csp.ts b/modules/shared/utils/csp.ts index 9b4ffee7..822c21b6 100644 --- a/modules/shared/utils/csp.ts +++ b/modules/shared/utils/csp.ts @@ -33,6 +33,7 @@ export const contentSecurityPolicy = { 'https://*.infura.io', 'https://*.alchemyapi.io', 'https://*.alchemy.com', + 'https://*.drpc.org', 'https://*.etherscan.io/api', 'https://*.ipfs.w3s.link', 'https://*.ipfs.dweb.link', From deeaec3d545451779385bc3add978281c678303d Mon Sep 17 00:00:00 2001 From: Alexander Belokon Date: Tue, 20 Feb 2024 14:16:34 +0100 Subject: [PATCH 2/2] fix: add fallback if StartVote event is failed to fetch --- modules/dashboard/ui/DashboardVote/DashboardVote.tsx | 7 ++----- modules/votes/ui/VoteDescription/VoteDescription.tsx | 10 +++++++--- modules/votes/utils/getEventVoteStart.ts | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/dashboard/ui/DashboardVote/DashboardVote.tsx b/modules/dashboard/ui/DashboardVote/DashboardVote.tsx index 1fe562c0..56a23580 100644 --- a/modules/dashboard/ui/DashboardVote/DashboardVote.tsx +++ b/modules/dashboard/ui/DashboardVote/DashboardVote.tsx @@ -25,7 +25,7 @@ import * as urls from 'modules/network/utils/urls' type Props = { voteId: number vote: Vote - eventStart: StartVoteEventObject + eventStart: StartVoteEventObject | null status: VoteStatus voteTime: number objectionPhaseTime: number @@ -79,9 +79,6 @@ export function DashboardVote({ const isEnded = status === VoteStatus.Rejected || status === VoteStatus.Executed - - const { metadata } = eventStart - return ( @@ -98,7 +95,7 @@ export function DashboardVote({ Vote #{voteId} - + diff --git a/modules/votes/ui/VoteDescription/VoteDescription.tsx b/modules/votes/ui/VoteDescription/VoteDescription.tsx index 8d572b72..0d049c05 100644 --- a/modules/votes/ui/VoteDescription/VoteDescription.tsx +++ b/modules/votes/ui/VoteDescription/VoteDescription.tsx @@ -10,14 +10,14 @@ import { fetcherIPFS } from 'modules/network/utils/fetcherIPFS' import { useSWR } from 'modules/network/hooks/useSwr' type Props = { - metadata: string + metadata: string | undefined allowMD?: boolean } const trimStart = (string = '') => `${string}`.replace(/^\s+/, '') export function VoteDescription({ metadata, allowMD }: Props) { - const cid = metadata.match(REGEX_LIDO_VOTE_CID)?.[1] || null + const cid = metadata?.match(REGEX_LIDO_VOTE_CID)?.[1] || null const { data = '', @@ -25,7 +25,11 @@ export function VoteDescription({ metadata, allowMD }: Props) { initialLoading, } = useSWR(cid, fetcherIPFS, { onError: noop }) - if (!cid) { + if (!metadata) { + return Failed to fetch vote description. + } + + if (!cid && metadata) { return {replaceJsxElements(metadata)} } diff --git a/modules/votes/utils/getEventVoteStart.ts b/modules/votes/utils/getEventVoteStart.ts index ef92b303..26d9cfbc 100644 --- a/modules/votes/utils/getEventVoteStart.ts +++ b/modules/votes/utils/getEventVoteStart.ts @@ -16,7 +16,7 @@ export async function getEventStartVote( ) const event = events[0] if (!events[0] || !event.decode) { - throw new Error('Start vote event parsing error') + return null } const decoded = event.decode(event.data, event.topics) return decoded as StartVoteEventObject