Skip to content

Commit

Permalink
refactor(author-avatar): use a specific ipfs gateway for ipfs avatars
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanabaroa committed Feb 2, 2024
1 parent 4cf46c5 commit f665516
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/hooks/authors/author-avatars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import assert from 'assert'
import {Nft, ChainProviders, Author} from '../../types'
import {ethers} from 'ethers'
import {getNftMetadataUrl, getNftImageUrl, getNftOwner} from '../../lib/chain'
import {defaultMediaIpfsGatewayUrl} from '../../stores/accounts/account-generator'

/**
* @param nft - The NFT object to resolve the URL of.
Expand All @@ -16,7 +17,7 @@ import {getNftMetadataUrl, getNftImageUrl, getNftOwner} from '../../lib/chain'
export function useNftMetadataUrl(nft?: Nft, accountName?: string) {
const account = useAccount({accountName})
// possible to use account.plebbit instead of account.plebbitOptions
const ipfsGatewayUrl = account?.plebbitOptions?.ipfsGatewayUrls?.[0]
const ipfsGatewayUrl = account?.mediaIpfsGatewayUrl || defaultMediaIpfsGatewayUrl
const chainProviders = account?.plebbitOptions?.chainProviders
const [nftMetadataUrl, setNftMetadataUrl] = useState()
const [error, setError] = useState<Error | undefined>()
Expand Down Expand Up @@ -64,7 +65,7 @@ export function useNftImageUrl(nftMetadataUrl?: string, accountName?: string) {
assert(!nftMetadataUrl || typeof nftMetadataUrl === 'string', `useNftImageUrl invalid argument nftMetadataUrl '${nftMetadataUrl}' not a string`)
const account = useAccount({accountName})
// possible to use account.plebbit instead of account.plebbitOptions
const ipfsGatewayUrl = account?.plebbitOptions?.ipfsGatewayUrls?.[0]
const ipfsGatewayUrl = account?.mediaIpfsGatewayUrl || defaultMediaIpfsGatewayUrl
const [imageUrl, setImageUrl] = useState()
const [error, setError] = useState<Error | undefined>()

Expand Down
5 changes: 5 additions & 0 deletions src/stores/accounts/account-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export const getDefaultPlebbitOptions = () => {
}
}

// the gateway to use in <img src> for nft avatars
// @ts-ignore
export const defaultMediaIpfsGatewayUrl = window.defaultMediaIpfsGatewayUrl || 'https://ipfs.io'

export const generateDefaultAccount = async () => {
const plebbitOptions = getDefaultPlebbitOptions()
const plebbit = await PlebbitJs.Plebbit(plebbitOptions)
Expand Down Expand Up @@ -81,6 +85,7 @@ export const generateDefaultAccount = async () => {
blockedAddresses: {},
blockedCids: {},
subplebbits,
mediaIpfsGatewayUrl: defaultMediaIpfsGatewayUrl,
}
return account
}
Expand Down

0 comments on commit f665516

Please sign in to comment.