Skip to content

Commit

Permalink
Merge pull request #24 from codingknite/exex-backfill
Browse files Browse the repository at this point in the history
arweave-exex fallback
  • Loading branch information
codingknite authored Sep 26, 2024
2 parents 00143fa + 75eb994 commit 366640d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/hooks/useArweaveId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ interface ArweaveIdProps {
arweaveId: string;
}

interface ExexFallbackProps {
block_hash: string;
arweave_hash: string;
block_number: number;
}

interface BlockProps {
block: number | undefined | null;
}
Expand All @@ -30,6 +36,23 @@ export function useArweaveId({ block }: BlockProps) {
if (data.arweaveId) {
return data.arweaveId;
}

const exexFallback = await fetch(
`https://arweave-exex-backfill.shuttleapp.rs/block/id/${ block }`,
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
},
);

const fallbackData = (await exexFallback.json()) as ExexFallbackProps;

if (fallbackData.arweave_hash) {
return fallbackData.arweave_hash;
}

return 'Arweave Id Not Found';
},
enabled: Boolean(block),
Expand Down

0 comments on commit 366640d

Please sign in to comment.