-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: added fallback for ipfs and make first request from cache (#92)
* fix: added fallback for ipfs and make first request from cache * fix: typo
- Loading branch information
Showing
8 changed files
with
80 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { | ||
getProposalMetadata as baseGetProposalMetadata, | ||
ProposalMetadata, | ||
} from '@bgd-labs/aave-governance-ui-helpers'; | ||
import matter from 'gray-matter'; | ||
|
||
import { texts } from '../ui/utils/texts'; | ||
import { cachedIPFSDataPath, githubStartUrl } from './cacheGithubLinks'; | ||
import { fallbackGateways, ipfsGateway } from './configs'; | ||
|
||
export async function getProposalMetadata({ | ||
hash, | ||
setIpfsError, | ||
}: { | ||
hash: string; | ||
setIpfsError?: (ipfsHash: string, text?: string, remove?: boolean) => void; | ||
}): Promise<ProposalMetadata | undefined> { | ||
try { | ||
const request = await fetch(`${githubStartUrl}${cachedIPFSDataPath(hash)}`); | ||
if (request.ok) { | ||
const response = await request.json(); | ||
const { content, data } = matter(response.description); | ||
return { | ||
...response, | ||
ipfsHash: hash, | ||
description: content, | ||
...data, | ||
}; | ||
} else { | ||
console.error( | ||
"Can't fetch cached ipfs data. Try to fetch from IPFS gateway", | ||
); | ||
return await baseGetProposalMetadata({ | ||
hash, | ||
gateway: ipfsGateway, | ||
setIpfsError, | ||
errorText: texts.other.fetchFromIpfsError, | ||
fallbackGateways, | ||
}); | ||
} | ||
} catch (e) { | ||
console.error( | ||
'An error occurred while fetching proposal metadata from IPFS, trying to request one more time.', | ||
); | ||
return await baseGetProposalMetadata({ | ||
hash, | ||
gateway: ipfsGateway, | ||
setIpfsError, | ||
errorText: texts.other.fetchFromIpfsError, | ||
fallbackGateways, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fc7fbdf
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.
This commit was deployed on ipfs