@0xsquid/react-hooks 2.1.8-beta.1 → 2.1.8
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,7 +1,6 @@
|
|
|
1
1
|
import { useQuery } from "@tanstack/react-query";
|
|
2
|
-
import { internalSquidApiBaseUrl } from "../../core/constants";
|
|
3
2
|
import { keys } from "../../core/queries/queries-keys";
|
|
4
|
-
const TOKEN_PRICE_API_URL =
|
|
3
|
+
const TOKEN_PRICE_API_URL = `https://squid-app-v2-git-chore-wallet-squid-hooks-wiring-0xsquid.vercel.app/api/coingecko`;
|
|
5
4
|
export const useMultipleTokenPrices = (tokens) => {
|
|
6
5
|
const coingeckoIds = Array.from(new Set(tokens.map((token) => token.coingeckoId).filter(Boolean)));
|
|
7
6
|
const coinGeckoQuery = useQuery({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMultipleTokenPrices.js","sourceRoot":"","sources":["../../../src/hooks/tokens/useMultipleTokenPrices.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"useMultipleTokenPrices.js","sourceRoot":"","sources":["../../../src/hooks/tokens/useMultipleTokenPrices.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AAEvD,MAAM,mBAAmB,GAAG,2FAA2F,CAAC;AAcxH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,MAAoC,EACpC,EAAE;IACF,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAC7B,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CACtD,CAAC;I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X,aAAa;QACb,SAAS,EAAE,cAAc,CAAC,SAAS;QACnC,OAAO,EAAE,cAAc,CAAC,OAAO;QAC/B,KAAK,EAAE,cAAc,CAAC,KAAK;QAC3B,OAAO,EAAE,cAAc,CAAC,OAAO;KAChC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @param {string} seed - The seed
|
|
4
|
-
* @returns {string} The
|
|
2
|
+
* Custom hook to return a deterministic avatar image URL based on the provided seed.
|
|
3
|
+
* @param {string} seed - The seed used to determine the avatar.
|
|
4
|
+
* @returns {string} - The selected avatar image URL.
|
|
5
5
|
*/
|
|
6
6
|
export declare const useAvatar: (seed?: string) => string;
|
|
@@ -1,66 +1,43 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
|
-
const
|
|
2
|
+
const zeroAddress = "0x0000000000000000000000000000000000000000";
|
|
3
|
+
const avatarImagesBaseUrl = "https://raw.githubusercontent.com/0xsquid/assets/main/squid-brand-assets/pfps";
|
|
4
|
+
const avatarImages = [
|
|
5
|
+
`${avatarImagesBaseUrl}/pfp1.svg`,
|
|
6
|
+
`${avatarImagesBaseUrl}/pfp15.svg`,
|
|
7
|
+
`${avatarImagesBaseUrl}/pfp2.svg`,
|
|
8
|
+
`${avatarImagesBaseUrl}/pfp22.svg`,
|
|
9
|
+
`${avatarImagesBaseUrl}/pfp29.svg`,
|
|
10
|
+
`${avatarImagesBaseUrl}/pfp3.svg`,
|
|
11
|
+
`${avatarImagesBaseUrl}/pfp36.svg`,
|
|
12
|
+
`${avatarImagesBaseUrl}/pfp4.svg`,
|
|
13
|
+
`${avatarImagesBaseUrl}/pfp41.svg`,
|
|
14
|
+
`${avatarImagesBaseUrl}/pfp5.svg`,
|
|
15
|
+
`${avatarImagesBaseUrl}/pfp6.svg`,
|
|
16
|
+
`${avatarImagesBaseUrl}/pfp8.svg`,
|
|
17
|
+
];
|
|
3
18
|
/**
|
|
4
|
-
*
|
|
5
|
-
* @param {
|
|
6
|
-
* @param {number}
|
|
7
|
-
* @returns {number} - The
|
|
19
|
+
* Simple hash function to create a deterministic index from a given string.
|
|
20
|
+
* @param {string} str - The input string to hash.
|
|
21
|
+
* @param {number} max - The maximum value for the hash.
|
|
22
|
+
* @returns {number} - The index within the array.
|
|
8
23
|
*/
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
* Scales a byte to a value within a given range.
|
|
12
|
-
* @param {number} byte - The byte value to scale (0-255).
|
|
13
|
-
* @param {number} min - The minimum value of the range.
|
|
14
|
-
* @param {number} max - The maximum value of the range.
|
|
15
|
-
* @returns {number} - The scaled value within the specified range.
|
|
16
|
-
*/
|
|
17
|
-
const bScaleRange = (byte, min, max) => min + (max - min) * (byte / 255);
|
|
18
|
-
/**
|
|
19
|
-
* Converts a string into a Uint8Array of bytes.
|
|
20
|
-
* @param {string} str - The string to convert.
|
|
21
|
-
* @returns {Uint8Array} - The resulting array of bytes.
|
|
22
|
-
*/
|
|
23
|
-
const stringToBytes = (str) => {
|
|
24
|
-
const hash = new Uint8Array(16);
|
|
24
|
+
const hashStringToIndex = (str, max) => {
|
|
25
|
+
let index = 0;
|
|
25
26
|
for (let i = 0; i < str.length; i++) {
|
|
26
|
-
|
|
27
|
+
index = (index * 31 + str.charCodeAt(i)) % max;
|
|
27
28
|
}
|
|
28
|
-
return
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Generates an array of HSL color strings based on a seed string.
|
|
32
|
-
* @param {string} seed - The seed string used to generate colors.
|
|
33
|
-
* @returns {string[]} - An array of HSL color strings.
|
|
34
|
-
*/
|
|
35
|
-
const generateHSLColors = (seed) => {
|
|
36
|
-
const bytes = stringToBytes(seed);
|
|
37
|
-
const startHue = bscale(bytes[12], 360);
|
|
38
|
-
const startLightness = bScaleRange(bytes[2], 32, 69.5);
|
|
39
|
-
const endLightness = (97 + bScaleRange(bytes[8], 72, 97)) / 2;
|
|
40
|
-
const startSaturation = bScaleRange(bytes[7], 81, 97);
|
|
41
|
-
const endSaturation = Math.min(startSaturation - 10, bScaleRange(bytes[10], 70, 92));
|
|
42
|
-
return [0, 0.1, 0.7, 0.9, 1].map((t) => `hsl(${Math.round(startHue)}, ${Math.round(startSaturation - (startSaturation - endSaturation) * (1 - t))}%, ${Math.round(startLightness + (endLightness - startLightness) * (1 - t))}%)`);
|
|
29
|
+
return index;
|
|
43
30
|
};
|
|
44
31
|
/**
|
|
45
|
-
*
|
|
46
|
-
* @param {string} seed - The seed
|
|
47
|
-
* @returns {string} The
|
|
32
|
+
* Custom hook to return a deterministic avatar image URL based on the provided seed.
|
|
33
|
+
* @param {string} seed - The seed used to determine the avatar.
|
|
34
|
+
* @returns {string} - The selected avatar image URL.
|
|
48
35
|
*/
|
|
49
|
-
export const useAvatar = (seed =
|
|
36
|
+
export const useAvatar = (seed = zeroAddress) => {
|
|
50
37
|
const [avatar, setAvatar] = useState("");
|
|
51
38
|
useEffect(() => {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 110 110">
|
|
55
|
-
<defs><linearGradient id="gzr" x1="106.975" y1="136.156" x2="-12.9815" y2="13.5347" gradientUnits="userSpaceOnUse">
|
|
56
|
-
${colors
|
|
57
|
-
.map((color, i) => `<stop offset="${i * 0.25}" stop-color="${color}" />`)
|
|
58
|
-
.join("")}
|
|
59
|
-
</linearGradient></defs>
|
|
60
|
-
<rect width="110" height="110" fill="url(#gzr)" />
|
|
61
|
-
</svg>
|
|
62
|
-
`;
|
|
63
|
-
setAvatar(`data:image/svg+xml;base64,${btoa(svgString)}`);
|
|
39
|
+
const index = hashStringToIndex(seed, avatarImages.length);
|
|
40
|
+
setAvatar(avatarImages[index]);
|
|
64
41
|
}, [seed]);
|
|
65
42
|
return avatar;
|
|
66
43
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAvatar.js","sourceRoot":"","sources":["../../../src/hooks/user/useAvatar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,MAAM,
|
|
1
|
+
{"version":3,"file":"useAvatar.js","sourceRoot":"","sources":["../../../src/hooks/user/useAvatar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,MAAM,WAAW,GAAG,4CAA4C,CAAC;AAEjE,MAAM,mBAAmB,GACvB,+EAA+E,CAAC;AAElF,MAAM,YAAY,GAAG;IACnB,GAAG,mBAAmB,WAAW;IACjC,GAAG,mBAAmB,YAAY;IAClC,GAAG,mBAAmB,WAAW;IACjC,GAAG,mBAAmB,YAAY;IAClC,GAAG,mBAAmB,YAAY;IAClC,GAAG,mBAAmB,WAAW;IACjC,GAAG,mBAAmB,YAAY;IAClC,GAAG,mBAAmB,WAAW;IACjC,GAAG,mBAAmB,YAAY;IAClC,GAAG,mBAAmB,WAAW;IACjC,GAAG,mBAAmB,WAAW;IACjC,GAAG,mBAAmB,WAAW;CAClC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG,CAAC,GAAW,EAAE,GAAW,EAAU,EAAE;IAC7D,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACnC,KAAK,GAAG,CAAC,KAAK,GAAG,EAAE,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;KAChD;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAe,WAAW,EAAU,EAAE;IAC9D,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAS,EAAE,CAAC,CAAC;IAEjD,SAAS,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