Move check to outside useSWR
This commit is contained in:
parent
61383a36d9
commit
d67cd52ceb
@ -111,10 +111,6 @@ export const use4Bytes = (
|
|||||||
const assetsURLPrefix = config?.assetsURLPrefix;
|
const assetsURLPrefix = config?.assetsURLPrefix;
|
||||||
|
|
||||||
const fourBytesFetcher = (key: string | null) => {
|
const fourBytesFetcher = (key: string | null) => {
|
||||||
// TODO: throw error?
|
|
||||||
if (assetsURLPrefix === undefined) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
if (key === null || key === "0x") {
|
if (key === null || key === "0x") {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@ -126,17 +122,14 @@ export const use4Bytes = (
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fetch4Bytes(assetsURLPrefix, key.slice(2));
|
return fetch4Bytes(assetsURLPrefix!, key.slice(2));
|
||||||
};
|
};
|
||||||
|
|
||||||
const { data, error } = useSWRImmutable<FourBytesEntry | null | undefined>(
|
const { data, error } = useSWRImmutable<FourBytesEntry | null | undefined>(
|
||||||
rawFourBytes,
|
assetsURLPrefix !== undefined ? rawFourBytes : null,
|
||||||
fourBytesFetcher
|
fourBytesFetcher
|
||||||
);
|
);
|
||||||
if (error) {
|
return error ? undefined : data;
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useMethodSelector = (data: string): [boolean, string, string] => {
|
export const useMethodSelector = (data: string): [boolean, string, string] => {
|
||||||
|
Loading…
Reference in New Issue
Block a user