@0xsquid/react-hooks 7.0.2 → 7.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useQuery } from "@tanstack/react-query";
|
|
2
2
|
const zeroAddress = "0x0000000000000000000000000000000000000000";
|
|
3
3
|
const avatarImagesBaseUrl = "https://raw.githubusercontent.com/0xsquid/assets/main/squid-brand-assets/pfps";
|
|
4
4
|
const TOTAL_AVATARS = 60;
|
|
@@ -24,11 +24,17 @@ const hashStringToIndex = (str, max) => {
|
|
|
24
24
|
* @returns {string} - The selected avatar image URL.
|
|
25
25
|
*/
|
|
26
26
|
export const useAvatar = (seed = zeroAddress) => {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
const { data: avatar } = useQuery({
|
|
28
|
+
queryKey: ["avatar", seed],
|
|
29
|
+
queryFn: () => {
|
|
30
|
+
const index = hashStringToIndex(seed, avatarImages.length);
|
|
31
|
+
return avatarImages[index];
|
|
32
|
+
},
|
|
33
|
+
// data is static, so no need to refetch
|
|
34
|
+
refetchOnWindowFocus: false,
|
|
35
|
+
cacheTime: Infinity,
|
|
36
|
+
staleTime: Infinity,
|
|
37
|
+
});
|
|
38
|
+
return avatar || "";
|
|
33
39
|
};
|
|
34
40
|
//# sourceMappingURL=useAvatar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAvatar.js","sourceRoot":"","sources":["../../../src/hooks/user/useAvatar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useAvatar.js","sourceRoot":"","sources":["../../../src/hooks/user/useAvatar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,MAAM,WAAW,GAAG,4CAA4C,CAAC;AAEjE,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