Skip to content

Commit

Permalink
Merge pull request #157 from lidofinance/fix/start-vote-event-fetch
Browse files Browse the repository at this point in the history
fix: StartVote event fetch fallback
  • Loading branch information
AnnaSila authored Feb 21, 2024
2 parents 290a521 + deeaec3 commit 0f2ad56
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
7 changes: 2 additions & 5 deletions modules/dashboard/ui/DashboardVote/DashboardVote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,9 +79,6 @@ export function DashboardVote({

const isEnded =
status === VoteStatus.Rejected || status === VoteStatus.Executed

const { metadata } = eventStart

return (
<Link passHref href={urls.vote(voteId)}>
<Wrap>
Expand All @@ -98,7 +95,7 @@ export function DashboardVote({
<VoteBody>
<VoteTitle>Vote #{voteId}</VoteTitle>
<VoteDescriptionWrap>
<VoteDescription metadata={metadata} />
<VoteDescription metadata={eventStart?.metadata} />
</VoteDescriptionWrap>
</VoteBody>

Expand Down
1 change: 1 addition & 0 deletions modules/shared/utils/csp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 7 additions & 3 deletions modules/votes/ui/VoteDescription/VoteDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@ 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 = '',
error,
initialLoading,
} = useSWR(cid, fetcherIPFS, { onError: noop })

if (!cid) {
if (!metadata) {
return <DescriptionText>Failed to fetch vote description.</DescriptionText>
}

if (!cid && metadata) {
return <DescriptionText>{replaceJsxElements(metadata)}</DescriptionText>
}

Expand Down
2 changes: 1 addition & 1 deletion modules/votes/utils/getEventVoteStart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0f2ad56

Please sign in to comment.