Skip to content

Commit

Permalink
fix: add 3 alternative ipfs gateways for fetching NFT meta instead of…
Browse files Browse the repository at this point in the history
… one (#145)
  • Loading branch information
shenshin authored Aug 28, 2024
1 parent 7c089ab commit 4f2b603
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/app/user/Balances/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@/lib/endpoints'
import { tokenContracts, GovernorAddress } from '@/lib/contracts'
import { NftMeta } from '@/shared/types'
import { ipfsGateways } from '@/config'

export const fetchAddressTokens = (address: string, chainId = 31) =>
axiosInstance
Expand Down Expand Up @@ -91,12 +92,16 @@ export const fetchProposalsCreatedCached = () => axiosInstance.get('/proposals/a
export function fetchIpfsUri(uri: string, responseType?: 'json'): Promise<NftMeta>
export function fetchIpfsUri(uri: string, responseType?: 'blob'): Promise<Blob>
export async function fetchIpfsUri(
uri: string,
ipfsUri: string,
responseType: 'json' | 'blob' = 'json',
): Promise<NftMeta | Blob> {
uri = uri.replace('ipfs://', 'https://ipfs.io/ipfs/')
const { data } = await axiosInstance.get(uri, { responseType })
return data
return Promise.any(
ipfsGateways.map(async gateway => {
const httpsUrl = ipfsUri.replace('ipfs://', gateway)
const { data } = await axiosInstance.get(httpsUrl, { responseType })
return data
}),
)
}

export const fetchNftInfo = (address: string) =>
Expand Down
1 change: 1 addition & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './config'
export { ipfsGateways } from './ipfsGateways'
5 changes: 5 additions & 0 deletions src/config/ipfsGateways.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const ipfsGateways = [
'https://ipfs.io/ipfs/',
'https://gateway.pinata.cloud/ipfs/',
'https://dweb.link/ipfs/',
]

0 comments on commit 4f2b603

Please sign in to comment.