diff --git a/src/proposals/components/proposalList/ActiveProposalListItem.tsx b/src/proposals/components/proposalList/ActiveProposalListItem.tsx index 7059ddc0..c38297dc 100644 --- a/src/proposals/components/proposalList/ActiveProposalListItem.tsx +++ b/src/proposals/components/proposalList/ActiveProposalListItem.tsx @@ -5,8 +5,8 @@ import { } from '@bgd-labs/aave-governance-ui-helpers'; import { WalletType } from '@bgd-labs/frontend-web3-utils'; import { Box, useTheme } from '@mui/system'; -import React, { useState } from 'react'; -import { zeroAddress } from 'viem'; +import React, { useEffect, useState } from 'react'; +import { Hex, zeroAddress } from 'viem'; import { useStore } from '../../../store/ZustandStoreProvider'; import { Link } from '../../../ui'; @@ -43,9 +43,34 @@ export function ActiveProposalListItem({ const isRendered = useStore((state) => state.isRendered); const appClients = useStore((state) => state.appClients); const ipfsDataErrors = useStore((state) => state.ipfsDataErrors); + const ipfsData = useStore((state) => state.ipfsData); + const getIpfsData = useStore((state) => state.getIpfsData); let activeWallet = useStore((state) => state.activeWallet); + const proposal = proposalData.proposal; + const loading = proposalData.loading; + const balanceLoading = proposalData.balanceLoading; + const [isClicked, setIsClicked] = useState(false); + const [isIPFSError, setIsIpfsError] = useState( + ipfsDataErrors[proposal.data.ipfsHash] && !ipfsData[proposal.data.ipfsHash], + ); + const [ipfsErrorCount, setIpfsErrorCount] = useState(0); + + const MAX_COUNT = 5; + + useEffect(() => { + setIsIpfsError( + ipfsDataErrors[proposal.data.ipfsHash] && + !ipfsData[proposal.data.ipfsHash], + ); + if (isIPFSError && ipfsErrorCount <= MAX_COUNT) { + setTimeout(async () => { + getIpfsData([proposal.data.id], proposal.data.ipfsHash as Hex); + setIpfsErrorCount(ipfsErrorCount + 1); + }, 1000); + } + }, [ipfsErrorCount, isIPFSError, Object.keys(ipfsDataErrors).length]); if (isForHelpModal) { activeWallet = { @@ -59,10 +84,6 @@ export function ActiveProposalListItem({ }; } - const proposal = proposalData.proposal; - const loading = proposalData.loading; - const balanceLoading = proposalData.balanceLoading; - const { stateTimestamp, estimatedState, @@ -126,7 +147,7 @@ export function ActiveProposalListItem({ - {ipfsDataErrors[proposal.data.ipfsHash] ? ( - ipfsDataErrors[proposal.data.ipfsHash] + {isIPFSError && ipfsErrorCount > MAX_COUNT ? ( + 'Ipfs getting error' + ) : isIPFSError ? ( + ) : proposal.data.title === `Proposal #${proposal.data.id}` ? ( diff --git a/src/proposals/store/proposalsSlice.ts b/src/proposals/store/proposalsSlice.ts index b9de58f8..c5a7434f 100644 --- a/src/proposals/store/proposalsSlice.ts +++ b/src/proposals/store/proposalsSlice.ts @@ -102,7 +102,11 @@ export interface IProposalsSlice { ipfsData: Record; ipfsDataErrors: Record; - setIpfsDataErrors: (ipfsHash: string, text?: string) => void; + setIpfsDataErrors: ( + ipfsHash: string, + text?: string, + remove?: boolean, + ) => void; setIpfsData: (hash: string, data: ProposalMetadata) => void; getIpfsData: (ids: number[], hash?: Hex) => Promise; @@ -459,13 +463,23 @@ export const createProposalsSlice: StoreSlice< ipfsData: {}, ipfsDataErrors: {}, - setIpfsDataErrors: (ipfsHash, text) => { - set((state) => - produce(state, (draft) => { - draft.ipfsDataErrors[ipfsHash] = - text === '' ? '' : text || texts.other.fetchFromIpfsError; - }), - ); + setIpfsDataErrors: (ipfsHash, text, remove) => { + if (remove) { + set((state) => + produce(state, (draft) => { + if (!!draft.ipfsDataErrors[ipfsHash]) { + delete draft.ipfsDataErrors[ipfsHash]; + } + }), + ); + } else { + set((state) => + produce(state, (draft) => { + draft.ipfsDataErrors[ipfsHash] = + text === '' ? '' : text || texts.other.fetchFromIpfsError; + }), + ); + } }, setIpfsData: (hash, data) => { if (!get().ipfsData[hash]) { @@ -507,6 +521,8 @@ export const createProposalsSlice: StoreSlice< ); if (ipfsData) { + get().setIpfsDataErrors(hash, '', true); + set((state) => produce(state, (draft) => { draft.ipfsData[hash] = ipfsData;