diff --git a/airdrop/src/hooks/useGetAirdropData.ts b/airdrop/src/hooks/useGetAirdropData.ts index 794b07f..6fb7453 100644 --- a/airdrop/src/hooks/useGetAirdropData.ts +++ b/airdrop/src/hooks/useGetAirdropData.ts @@ -1,9 +1,7 @@ - import { useQuery } from "@tanstack/react-query"; -import { AbstractAddress } from "fuels"; -import { useUploadAirdropDataParams } from "./useUploadAirdropData"; import { PinataSDK } from "pinata"; import { PINATA_JWT } from "../lib"; +import { useUploadAirdropDataParams } from "./useUploadAirdropData"; export type ContractIdData = Array; @@ -15,20 +13,8 @@ export const pinata = new PinataSDK({ export const useGetAirdropData = () => { return useQuery({ queryKey: ["airdropData"], - // @ts-expect-error - revisit this later - queryFn: async () => { + queryFn: async (): Promise => { try { - const options = { - method: "GET", - headers: { - Authorization: `Bearer ${PINATA_JWT}`, - }, - }; - - const metaData = JSON.stringify({ - name: "AirdropData", - }); - const ipfsData = (await pinata.listFiles()).filter( (file) => file.metadata.name === "AirdropData" ); @@ -46,11 +32,16 @@ export const useGetAirdropData = () => { { airdropData } ); - if (airdropData) return airdropData; + if (airdropData) { + return airdropData as unknown as ContractIdData; + } return []; } catch (error) { - console.error("Error while fetching contractIds from ipfs in useGetAirdropContractId: ", error); - return []; + console.error( + "Error while fetching contractIds from ipfs in useGetAirdropContractId: ", + error + ); + throw error; } }, }); diff --git a/airdrop/src/hooks/useUploadAirdropData.ts b/airdrop/src/hooks/useUploadAirdropData.ts index ec75e1f..116bb34 100644 --- a/airdrop/src/hooks/useUploadAirdropData.ts +++ b/airdrop/src/hooks/useUploadAirdropData.ts @@ -1,8 +1,8 @@ -import { PINATA_JWT } from "../lib"; -import { AbstractAddress } from "fuels"; +import { getTruncatedAddress } from "@/lib/utils"; import { useMutation } from "@tanstack/react-query"; +import { AbstractAddress } from "fuels"; import toast from "react-hot-toast"; -import { getTruncatedAddress } from "@/lib/utils"; +import { PINATA_JWT } from "../lib"; export type useUploadAirdropDataParams = { @@ -10,6 +10,16 @@ export type useUploadAirdropDataParams = { recipients: Array<{ address: string; amount: bigint }>; }; +interface PinataFetchOptions { + method: string; + body: FormData; + headers: { + pinata_api_key?: string; + pinata_secret_api_key?: string; + Authorization: string; + }; +} + export const useUploadAirdropData = () => { const mutation = useMutation({ mutationFn: async ({ @@ -17,7 +27,6 @@ export const useUploadAirdropData = () => { recipients, }: useUploadAirdropDataParams) => { // Custom replacer function to handle BigInt values - // @ts-expect-error const replacer = (key: string, value: any) => { return typeof value === "bigint" ? value.toString() : value; }; @@ -37,7 +46,7 @@ export const useUploadAirdropData = () => { const blob = new Blob([airdropData], { type: "application/json" }); formData.append("file", blob, "airdropData.json"); - const fetchOptions = { + const fetchOptions: PinataFetchOptions = { method: "POST", body: formData, headers: { @@ -49,7 +58,6 @@ export const useUploadAirdropData = () => { const res = await fetch( "https://api.pinata.cloud/pinning/pinFileToIPFS", - // @ts-expect-error will fix it once the build succeeds fetchOptions ); const resData = await res.json();