diff --git a/web/src/hooks/useFetchJSONZST.js b/web/src/hooks/useFetchJSONZST.js index c88a408..8405d59 100644 --- a/web/src/hooks/useFetchJSONZST.js +++ b/web/src/hooks/useFetchJSONZST.js @@ -20,21 +20,20 @@ export async function fetchJSONZST(url) { export default function useFetchJSONZST(urls, options) { return useQueries( - urls.map(({ url, fallbackUrls }, i) => ({ - queryKey: ["fetchJSONZST", url], + urls.map(({ sourceUrls }, i) => ({ + queryKey: ["fetchJSONZST", sourceUrls[0]], queryFn: async () => { try { - return await fetchJSONZST(url); + return await Promise.any( + sourceUrls.map((url) => + fetchJSONZST(url).catch((err) => { + console.log(`failed to fetch ${url}`, err); + throw err; + }) + ) + ); } catch (err) { - console.log(`error fetching ${url}`, err); - for (const fallbackUrl of fallbackUrls) { - console.log(`trying fallback ${fallbackUrl}`); - try { - return await fetchJSONZST(fallbackUrl); - } catch (err) { - console.log(`error fetching ${fallbackUrl}`, err); - } - } + console.log(`all sourceUrls failed`, sourceUrls, err); throw err; } }, diff --git a/web/src/hooks/useFetchRewardSnapshots.js b/web/src/hooks/useFetchRewardSnapshots.js index dcb2e8b..5661412 100644 --- a/web/src/hooks/useFetchRewardSnapshots.js +++ b/web/src/hooks/useFetchRewardSnapshots.js @@ -14,8 +14,8 @@ export default function useFetchRewardSnapshots({ let [ipfsBase] = useSetting("ipfs.base"); let snapshotJsons = useFetchJSONZST( (snapshots || []).map(({ rewardIndex, merkleTreeCID }) => ({ - url: `${ipfsBase}/ipfs/${merkleTreeCID}/rp-rewards-${network}-${rewardIndex}.json.zst`, - fallbackUrls: [ + sourceUrls: [ + `${ipfsBase}/ipfs/${merkleTreeCID}/rp-rewards-${network}-${rewardIndex}.json.zst`, `${fallbackBase}/${network}/rp-rewards-${network}-${rewardIndex}.json`, ], })),