From 731a8190ed871960145e554e0fa2d79b467d5283 Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Wed, 10 Aug 2022 02:04:36 -0300 Subject: [PATCH] Dont try to download files that dont exist on sourcify --- src/sourcify/useSourcify.ts | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/sourcify/useSourcify.ts b/src/sourcify/useSourcify.ts index e2a4498..f4f0a8a 100644 --- a/src/sourcify/useSourcify.ts +++ b/src/sourcify/useSourcify.ts @@ -81,24 +81,17 @@ export type Metadata = { }; }; -const fetchSourcifyMetadata = async ( - address: ChecksummedAddress, - chainId: number, - source: SourcifySource, - abortController: AbortController -): Promise => { +const sourcifyFetcher = async (url: string) => { try { - const metadataURL = sourcifyMetadata(address, chainId, source); - const result = await fetch(metadataURL, { - signal: abortController.signal, - }); - if (result.ok) { - return await result.json(); + const res = await fetch(url); + if (res.ok) { + return res.json(); } - return null; } catch (err) { - console.error(err); + console.warn( + `error while getting Sourcify metadata: url=${url} err=${err}` + ); return null; } }; @@ -112,8 +105,9 @@ export const useSourcifyMetadata = ( address === undefined || chainId === undefined ? null : sourcifyMetadata(address, chainId, source); - const { data, error } = useSWRImmutable(metadataURL, (url) => - fetch(url).then((res) => res.json()) + const { data, error } = useSWRImmutable( + metadataURL, + sourcifyFetcher ); if (error) { return null;