thirdweb 5.121.1 → 5.121.2

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 +1 @@
1
- {"version":3,"file":"token-query.d.ts","sourceRoot":"","sources":["../../../../../../../src/react/web/ui/Bridge/common/token-query.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAItE,KAAK,gBAAgB,GACjB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAE,GAC3C;IACE,IAAI,EAAE,mBAAmB,CAAC;CAC3B,CAAC;AAEN,wBAAgB,aAAa,CAAC,MAAM,EAAE;IACpC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,MAAM,EAAE,cAAc,CAAC;CACxB,2EAgCA"}
1
+ {"version":3,"file":"token-query.d.ts","sourceRoot":"","sources":["../../../../../../../src/react/web/ui/Bridge/common/token-query.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAItE,KAAK,gBAAgB,GACjB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAE,GAC3C;IACE,IAAI,EAAE,mBAAmB,CAAC;CAC3B,CAAC;AAEN,wBAAgB,aAAa,CAAC,MAAM,EAAE;IACpC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,MAAM,EAAE,cAAc,CAAC;CACxB,2EAmCA"}
@@ -1,2 +1,2 @@
1
- export declare const version = "5.121.1";
1
+ export declare const version = "5.121.2";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -400,7 +400,7 @@
400
400
  }
401
401
  },
402
402
  "typings": "./dist/types/exports/thirdweb.d.ts",
403
- "version": "5.121.1",
403
+ "version": "5.121.2",
404
404
  "scripts": {
405
405
  "bench": "vitest -c ./test/vitest.config.ts bench",
406
406
  "bench:compare": "bun run ./benchmarks/run.ts",
@@ -0,0 +1,117 @@
1
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
2
+ import { renderHook, waitFor } from "@testing-library/react";
3
+ import type { ReactNode } from "react";
4
+ import { beforeEach, describe, expect, it, vi } from "vitest";
5
+ import { TEST_CLIENT } from "~test/test-clients.js";
6
+ import type { TokenWithPrices } from "../../../../../bridge/index.js";
7
+ import { getToken } from "../../../../../pay/convert/get-token.js";
8
+ import { useTokenQuery } from "./token-query.js";
9
+
10
+ vi.mock("../../../../../pay/convert/get-token.js", () => ({
11
+ getToken: vi.fn(),
12
+ }));
13
+
14
+ const TOKEN_ADDRESS = "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359";
15
+ const CHAIN_ID = 137;
16
+
17
+ const MOCK_TOKEN = {
18
+ address: TOKEN_ADDRESS,
19
+ chainId: CHAIN_ID,
20
+ decimals: 6,
21
+ name: "USD Coin",
22
+ prices: { USD: 1 },
23
+ symbol: "USDC",
24
+ } as TokenWithPrices;
25
+
26
+ const createWrapper = () => {
27
+ const queryClient = new QueryClient({
28
+ defaultOptions: {
29
+ queries: {
30
+ retry: false,
31
+ },
32
+ },
33
+ });
34
+ return ({ children }: { children: ReactNode }) => (
35
+ <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
36
+ );
37
+ };
38
+
39
+ describe("useTokenQuery", () => {
40
+ beforeEach(() => {
41
+ vi.mocked(getToken).mockReset();
42
+ });
43
+
44
+ it("returns success when getToken resolves", async () => {
45
+ vi.mocked(getToken).mockResolvedValue(MOCK_TOKEN);
46
+
47
+ const { result } = renderHook(
48
+ () =>
49
+ useTokenQuery({
50
+ chainId: CHAIN_ID,
51
+ client: TEST_CLIENT,
52
+ tokenAddress: TOKEN_ADDRESS,
53
+ }),
54
+ { wrapper: createWrapper() },
55
+ );
56
+
57
+ await waitFor(() => expect(result.current.isSuccess).toBe(true));
58
+ expect(result.current.data).toEqual({
59
+ token: MOCK_TOKEN,
60
+ type: "success",
61
+ });
62
+ });
63
+
64
+ it("returns unsupported_token when getToken throws a not-supported Error", async () => {
65
+ vi.mocked(getToken).mockRejectedValue(new Error("Token not supported"));
66
+
67
+ const { result } = renderHook(
68
+ () =>
69
+ useTokenQuery({
70
+ chainId: CHAIN_ID,
71
+ client: TEST_CLIENT,
72
+ tokenAddress: TOKEN_ADDRESS,
73
+ }),
74
+ { wrapper: createWrapper() },
75
+ );
76
+
77
+ await waitFor(() => expect(result.current.isSuccess).toBe(true));
78
+ expect(result.current.data).toEqual({ type: "unsupported_token" });
79
+ expect(result.current.isError).toBe(false);
80
+ });
81
+
82
+ it("surfaces 401 failures as query errors instead of unsupported_token", async () => {
83
+ vi.mocked(getToken).mockRejectedValue(new Error("401 Unauthorized"));
84
+
85
+ const { result } = renderHook(
86
+ () =>
87
+ useTokenQuery({
88
+ chainId: CHAIN_ID,
89
+ client: TEST_CLIENT,
90
+ tokenAddress: TOKEN_ADDRESS,
91
+ }),
92
+ { wrapper: createWrapper() },
93
+ );
94
+
95
+ await waitFor(() => expect(result.current.isError).toBe(true));
96
+ expect(result.current.data).toBeUndefined();
97
+ expect(result.current.error).toBeInstanceOf(Error);
98
+ expect((result.current.error as Error).message).toBe("401 Unauthorized");
99
+ });
100
+
101
+ it("surfaces non-Error rejections as query errors instead of unsupported_token", async () => {
102
+ vi.mocked(getToken).mockRejectedValue("timeout");
103
+
104
+ const { result } = renderHook(
105
+ () =>
106
+ useTokenQuery({
107
+ chainId: CHAIN_ID,
108
+ client: TEST_CLIENT,
109
+ tokenAddress: TOKEN_ADDRESS,
110
+ }),
111
+ { wrapper: createWrapper() },
112
+ );
113
+
114
+ await waitFor(() => expect(result.current.isError).toBe(true));
115
+ expect(result.current.data).toBeUndefined();
116
+ });
117
+ });
@@ -27,7 +27,10 @@ export function useTokenQuery(params: {
27
27
  tokenAddress,
28
28
  params.chainId,
29
29
  ).catch((err) => {
30
- err.message.includes("not supported") ? undefined : Promise.reject(err);
30
+ if (err instanceof Error && err.message.includes("not supported")) {
31
+ return undefined;
32
+ }
33
+ throw err;
31
34
  });
32
35
 
33
36
  if (!token) {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.121.1";
1
+ export const version = "5.121.2";