From d67cd52ceb9090ae25a59a8b5a995c0eb9698a4c Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Sat, 18 Dec 2021 07:31:03 -0300 Subject: [PATCH] Move check to outside useSWR --- src/use4Bytes.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/use4Bytes.ts b/src/use4Bytes.ts index 8e6ef41..a1adfdb 100644 --- a/src/use4Bytes.ts +++ b/src/use4Bytes.ts @@ -111,10 +111,6 @@ export const use4Bytes = ( const assetsURLPrefix = config?.assetsURLPrefix; const fourBytesFetcher = (key: string | null) => { - // TODO: throw error? - if (assetsURLPrefix === undefined) { - return undefined; - } if (key === null || key === "0x") { return undefined; } @@ -126,17 +122,14 @@ export const use4Bytes = ( return undefined; } - return fetch4Bytes(assetsURLPrefix, key.slice(2)); + return fetch4Bytes(assetsURLPrefix!, key.slice(2)); }; const { data, error } = useSWRImmutable( - rawFourBytes, + assetsURLPrefix !== undefined ? rawFourBytes : null, fourBytesFetcher ); - if (error) { - return undefined; - } - return data; + return error ? undefined : data; }; export const useMethodSelector = (data: string): [boolean, string, string] => {