-
Notifications
You must be signed in to change notification settings - Fork 0
fix ipfs fetch #520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix ipfs fetch #520
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -243,8 +243,11 @@ export const parseHistoricalProposals = async ( | |||||||||||||||||||
| data?: HistoricalProposalData[], | ||||||||||||||||||||
| ): Promise<HistoricalProposalMerged[]> => { | ||||||||||||||||||||
| if (!data) return []; | ||||||||||||||||||||
| const ipfsFetches = data.map(d => getProposalsFromIpfs(d.description)); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Only fetch from IPFS if description (CID) is valid | ||||||||||||||||||||
|
||||||||||||||||||||
| // Only fetch from IPFS if description (CID) is valid | |
| // Only fetch from IPFS if a description (CID) is present |
Copilot
AI
Mar 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As written, a single failing IPFS request will reject Promise.all(ipfsFetches) and prevent parsing all historical proposals. To make this robust to invalid/missing CIDs or transient IPFS errors, consider catching per-item failures (or using Promise.allSettled) and falling back to empty IpfsDetails for that proposal.
| d.description ? getProposalsFromIpfs(d.description) : Promise.resolve({ ipfsHash: undefined }), | |
| ); | |
| const ipfsDetails = await Promise.all(ipfsFetches); | |
| d.description ? getProposalsFromIpfs(d.description) : Promise.resolve({ ipfsHash: undefined } as IpfsDetails), | |
| ); | |
| const ipfsResults = await Promise.allSettled(ipfsFetches); | |
| const ipfsDetails = ipfsResults.map(result => | |
| result.status === "fulfilled" ? result.value : ({ ipfsHash: undefined } as IpfsDetails), | |
| ); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,7 +16,10 @@ export const paginateProposals = (proposals: MergedProposal[], cursor?: string, | |||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export const enrichProposalsWithData = async (proposals: FromEventsToProposalsReturnType) => { | ||||||||||||||||||||||||||||||
| const ipfsFetches = proposals.map(p => getProposalsFromIpfs(p.ipfsHash)); | ||||||||||||||||||||||||||||||
| // Only fetch from IPFS if ipfsHash is valid | ||||||||||||||||||||||||||||||
| const ipfsFetches = proposals.map(p => | ||||||||||||||||||||||||||||||
| p.ipfsHash ? getProposalsFromIpfs(p.ipfsHash) : Promise.resolve({ ipfsHash: undefined }), | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+22
|
||||||||||||||||||||||||||||||
| // Only fetch from IPFS if ipfsHash is valid | |
| const ipfsFetches = proposals.map(p => | |
| p.ipfsHash ? getProposalsFromIpfs(p.ipfsHash) : Promise.resolve({ ipfsHash: undefined }), | |
| ); | |
| const ipfsFetches = proposals.map(p => getProposalsFromIpfs(p.ipfsHash)); |
Copilot
AI
Mar 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says the hash is "valid", but the condition only checks truthiness (non-empty). Either validate the CID format (or trim whitespace before checking), or reword the comment to reflect that this is only a presence check.
| // Only fetch from IPFS if ipfsHash is valid | |
| const ipfsFetches = proposals.map(p => | |
| p.ipfsHash ? getProposalsFromIpfs(p.ipfsHash) : Promise.resolve({ ipfsHash: undefined }), | |
| ); | |
| // Only fetch from IPFS if a non-empty ipfsHash is present | |
| const ipfsFetches = proposals.map(p => { | |
| const ipfsHash = p.ipfsHash?.trim(); | |
| return ipfsHash ? getProposalsFromIpfs(ipfsHash) : Promise.resolve({ ipfsHash: undefined }); | |
| }); |
Copilot
AI
Mar 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Promise.all(ipfsFetches) will reject if any getProposalsFromIpfs call fails (e.g., 404/timeout for an invalid CID), which can break the whole proposals load. Consider making each fetch resilient (wrap each call with .catch(() => ({})) / return a fallback IpfsDetails, or use Promise.allSettled and merge only fulfilled results).
| const ipfsDetails: IpfsDetails[] = await Promise.all(ipfsFetches); | |
| const ipfsDetailsResults = await Promise.allSettled(ipfsFetches); | |
| const ipfsDetails: IpfsDetails[] = ipfsDetailsResults.map(result => | |
| result.status === "fulfilled" ? result.value : ({ ipfsHash: undefined } as IpfsDetails), | |
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
README now states Node.js v22+, but the repo root
package.jsonstill declaresengines.nodeas>=18. Please align these (either bumpenginesto>=22if v22 is required, or keep README at v18+ if older Node versions are supported).