Skip to content

Commit

Permalink
Use IPFS Gateway as default option to get Merkle tree data (#1028)
Browse files Browse the repository at this point in the history
  • Loading branch information
saeta.eth authored May 5, 2023
1 parent 100498d commit 4ec9d2e
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/hooks/aelin/useMerkleTreeData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ const useMerkleTreeData = (variables: Props) => {
try {
if (!isIPFS.cid(variables.ipfsHash)) throw new Error('Invalid ipfs hash')

const client = new Web3Storage({
token: env.NEXT_PUBLIC_WEB3_STORAGE_TOKEN_KEY as string,
})
const response = await fetch(getMerkleTreeIpfsGatewayUrl(variables.ipfsHash))
const merkleTreeDataJson = await response.json()
return merkleTreeDataJson
} catch (err) {
console.error(err)

const res = await client.get(variables.ipfsHash)
try {
const client = new Web3Storage({
token: env.NEXT_PUBLIC_WEB3_STORAGE_TOKEN_KEY as string,
})

if (!res?.ok) throw new Error('Unexpected fetch response')
const res = await client.get(variables.ipfsHash)

const files = await res?.files()
if (!res?.ok) throw new Error('Unexpected fetch response')

const merkleTreeDataJson = JSON.parse(await files[0].text())
const files = await res?.files()

return merkleTreeDataJson
} catch (err) {
console.error(err)
const merkleTreeDataJson = JSON.parse(await files[0].text())

try {
const response = await fetch(getMerkleTreeIpfsGatewayUrl(variables.ipfsHash))
const merkleTreeDataJson = await response.json()
return merkleTreeDataJson
} catch (err) {
console.log(err)
Expand Down

0 comments on commit 4ec9d2e

Please sign in to comment.