thirdweb 5.103.0 → 5.103.1

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.
Files changed (43) hide show
  1. package/dist/cjs/cli/bin.js +2 -2
  2. package/dist/cjs/cli/bin.js.map +1 -1
  3. package/dist/cjs/react/core/hooks/useTransactionDetails.js +1 -1
  4. package/dist/cjs/react/core/hooks/useTransactionDetails.js.map +1 -1
  5. package/dist/cjs/react/core/hooks/wallets/useSendToken.js +17 -2
  6. package/dist/cjs/react/core/hooks/wallets/useSendToken.js.map +1 -1
  7. package/dist/cjs/react/web/ui/Bridge/CheckoutWidget.js +0 -11
  8. package/dist/cjs/react/web/ui/Bridge/CheckoutWidget.js.map +1 -1
  9. package/dist/cjs/react/web/ui/Bridge/TransactionWidget.js +0 -17
  10. package/dist/cjs/react/web/ui/Bridge/TransactionWidget.js.map +1 -1
  11. package/dist/cjs/version.js +1 -1
  12. package/dist/esm/cli/bin.js +2 -2
  13. package/dist/esm/cli/bin.js.map +1 -1
  14. package/dist/esm/react/core/hooks/useTransactionDetails.js +1 -1
  15. package/dist/esm/react/core/hooks/useTransactionDetails.js.map +1 -1
  16. package/dist/esm/react/core/hooks/wallets/useSendToken.js +17 -2
  17. package/dist/esm/react/core/hooks/wallets/useSendToken.js.map +1 -1
  18. package/dist/esm/react/web/ui/Bridge/CheckoutWidget.js +0 -11
  19. package/dist/esm/react/web/ui/Bridge/CheckoutWidget.js.map +1 -1
  20. package/dist/esm/react/web/ui/Bridge/TransactionWidget.js +0 -17
  21. package/dist/esm/react/web/ui/Bridge/TransactionWidget.js.map +1 -1
  22. package/dist/esm/version.js +1 -1
  23. package/dist/types/react/core/hooks/wallets/useSendToken.d.ts.map +1 -1
  24. package/dist/types/react/web/ui/Bridge/CheckoutWidget.d.ts +0 -11
  25. package/dist/types/react/web/ui/Bridge/CheckoutWidget.d.ts.map +1 -1
  26. package/dist/types/react/web/ui/Bridge/TransactionWidget.d.ts +0 -17
  27. package/dist/types/react/web/ui/Bridge/TransactionWidget.d.ts.map +1 -1
  28. package/dist/types/version.d.ts +1 -1
  29. package/dist/types/wallets/utils/getWalletBalance.d.ts +1 -1
  30. package/dist/types/wallets/utils/getWalletBalance.d.ts.map +1 -1
  31. package/package.json +1 -1
  32. package/src/bridge/Status.test.ts +1 -1
  33. package/src/cli/bin.ts +2 -2
  34. package/src/react/core/hooks/useTransactionDetails.ts +1 -1
  35. package/src/react/core/hooks/wallets/useSendToken.ts +17 -3
  36. package/src/react/core/machines/paymentMachine.test.ts +0 -172
  37. package/src/react/web/adapters/adapters.test.ts +0 -8
  38. package/src/react/web/ui/Bridge/CheckoutWidget.tsx +0 -11
  39. package/src/react/web/ui/Bridge/TransactionWidget.tsx +0 -17
  40. package/src/version.ts +1 -1
  41. package/src/wallets/utils/getWalletBalance.ts +1 -1
  42. package/src/react/core/hooks/useBridgeError.test.ts +0 -172
  43. package/src/react/core/hooks/usePaymentMethods.test.ts +0 -336
@@ -1,336 +0,0 @@
1
- /**
2
- * @vitest-environment happy-dom
3
- */
4
- import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
5
- import { renderHook, waitFor } from "@testing-library/react";
6
- import { createElement } from "react";
7
- import { beforeEach, describe, expect, it, vi } from "vitest";
8
- import { routes } from "../../../bridge/Routes.js";
9
- import type { Token } from "../../../bridge/types/Token.js";
10
- import type { ThirdwebClient } from "../../../client/client.js";
11
- import { usePaymentMethods } from "./usePaymentMethods.js";
12
-
13
- // Mock the routes API
14
- vi.mock("../../../bridge/Routes.js", () => ({
15
- routes: vi.fn(),
16
- }));
17
-
18
- const mockRoutes = vi.mocked(routes);
19
-
20
- // Mock data
21
- const mockDestinationToken: Token = {
22
- chainId: 1,
23
- address: "0xA0b86a33E6441aA7A6fbEEc9bb27e5e8bc3b8eD7",
24
- decimals: 6,
25
- symbol: "USDC",
26
- name: "USD Coin",
27
- priceUsd: 1.0,
28
- };
29
-
30
- const mockClient = {
31
- clientId: "test-client-id",
32
- } as ThirdwebClient;
33
-
34
- const mockRouteData = [
35
- {
36
- originToken: {
37
- chainId: 1,
38
- address: "0xA0b86a33E6441aA7A6fbEEc9bb27e5e8bc3b8eD7",
39
- decimals: 18,
40
- symbol: "ETH",
41
- name: "Ethereum",
42
- priceUsd: 2000,
43
- },
44
- destinationToken: mockDestinationToken,
45
- steps: [],
46
- },
47
- {
48
- originToken: {
49
- chainId: 137,
50
- address: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
51
- decimals: 6,
52
- symbol: "USDC",
53
- name: "USD Coin",
54
- priceUsd: 1.0,
55
- },
56
- destinationToken: mockDestinationToken,
57
- steps: [],
58
- },
59
- {
60
- originToken: {
61
- chainId: 42161,
62
- address: "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8",
63
- decimals: 6,
64
- symbol: "USDC",
65
- name: "USD Coin",
66
- priceUsd: 1.0,
67
- },
68
- destinationToken: mockDestinationToken,
69
- steps: [],
70
- },
71
- ];
72
-
73
- // Test wrapper component
74
- const createWrapper = () => {
75
- const queryClient = new QueryClient({
76
- defaultOptions: {
77
- queries: {
78
- retry: false,
79
- },
80
- },
81
- });
82
-
83
- return ({ children }: { children: React.ReactNode }) =>
84
- createElement(QueryClientProvider, { client: queryClient }, children);
85
- };
86
-
87
- describe("usePaymentMethods", () => {
88
- beforeEach(() => {
89
- vi.clearAllMocks();
90
- });
91
-
92
- it("should require destinationToken and client parameters", () => {
93
- const wrapper = createWrapper();
94
-
95
- const { result } = renderHook(
96
- () =>
97
- usePaymentMethods({
98
- destinationToken: mockDestinationToken,
99
- destinationAmount: "1",
100
- client: mockClient,
101
- }),
102
- { wrapper },
103
- );
104
-
105
- expect(result.current).toBeDefined();
106
- expect(result.current.isLoading).toBe(true);
107
- });
108
-
109
- it("should fetch routes and transform data correctly", async () => {
110
- mockRoutes.mockResolvedValueOnce(mockRouteData);
111
- const wrapper = createWrapper();
112
-
113
- const { result } = renderHook(
114
- () =>
115
- usePaymentMethods({
116
- destinationToken: mockDestinationToken,
117
- destinationAmount: "1",
118
- client: mockClient,
119
- }),
120
- { wrapper },
121
- );
122
-
123
- // Initially loading
124
- expect(result.current.isLoading).toBe(true);
125
- expect(result.current.data).toEqual([]);
126
-
127
- // Wait for query to resolve
128
- await waitFor(() => {
129
- expect(result.current.isSuccess).toBe(true);
130
- });
131
-
132
- // Should have transformed data
133
- expect(result.current.data).toHaveLength(4); // 3 wallet methods + 1 fiat method
134
-
135
- const walletMethod = result.current.data[0];
136
- expect(walletMethod?.type).toBe("wallet");
137
- if (walletMethod?.type === "wallet") {
138
- expect(walletMethod.originToken).toEqual(mockRouteData[0]?.originToken);
139
- }
140
-
141
- const fiatMethod = result.current.data[3];
142
- expect(fiatMethod?.type).toBe("fiat");
143
- if (fiatMethod?.type === "fiat") {
144
- expect(fiatMethod.currency).toBe("USD");
145
- }
146
- });
147
-
148
- it("should call routes API with correct parameters", async () => {
149
- mockRoutes.mockResolvedValueOnce(mockRouteData);
150
- const wrapper = createWrapper();
151
-
152
- renderHook(
153
- () =>
154
- usePaymentMethods({
155
- destinationToken: mockDestinationToken,
156
- destinationAmount: "1",
157
- client: mockClient,
158
- }),
159
- { wrapper },
160
- );
161
-
162
- await waitFor(() => {
163
- expect(mockRoutes).toHaveBeenCalledWith({
164
- client: mockClient,
165
- destinationChainId: mockDestinationToken.chainId,
166
- destinationTokenAddress: mockDestinationToken.address,
167
- sortBy: "popularity",
168
- limit: 50,
169
- });
170
- });
171
- });
172
-
173
- it("should handle empty routes data", async () => {
174
- mockRoutes.mockResolvedValueOnce([]);
175
- const wrapper = createWrapper();
176
-
177
- const { result } = renderHook(
178
- () =>
179
- usePaymentMethods({
180
- destinationToken: mockDestinationToken,
181
- destinationAmount: "1",
182
- client: mockClient,
183
- }),
184
- { wrapper },
185
- );
186
-
187
- await waitFor(() => {
188
- expect(result.current.isSuccess).toBe(true);
189
- });
190
-
191
- // Should only have fiat method when no routes
192
- expect(result.current.data).toHaveLength(1);
193
- expect(result.current.data[0]).toEqual({
194
- type: "fiat",
195
- currency: "USD",
196
- });
197
- });
198
-
199
- it("should handle API errors gracefully", async () => {
200
- const mockError = new Error("API Error");
201
- mockRoutes.mockRejectedValueOnce(mockError);
202
- const wrapper = createWrapper();
203
-
204
- const { result } = renderHook(
205
- () =>
206
- usePaymentMethods({
207
- destinationToken: mockDestinationToken,
208
- destinationAmount: "1",
209
- client: mockClient,
210
- }),
211
- { wrapper },
212
- );
213
-
214
- await waitFor(() => {
215
- expect(result.current.isError).toBe(true);
216
- });
217
-
218
- expect(result.current.error).toBeTruthy();
219
- expect(result.current.data).toEqual([]);
220
- });
221
-
222
- it("should deduplicate origin tokens", async () => {
223
- // Mock data with duplicate origin tokens
224
- const firstRoute = mockRouteData[0];
225
- if (!firstRoute) {
226
- throw new Error("Mock data is invalid");
227
- }
228
-
229
- const mockDataWithDuplicates = [
230
- ...mockRouteData,
231
- {
232
- originToken: firstRoute.originToken, // Duplicate ETH
233
- destinationToken: mockDestinationToken,
234
- steps: [],
235
- },
236
- ];
237
-
238
- mockRoutes.mockResolvedValueOnce(mockDataWithDuplicates);
239
- const wrapper = createWrapper();
240
-
241
- const { result } = renderHook(
242
- () =>
243
- usePaymentMethods({
244
- destinationToken: mockDestinationToken,
245
- destinationAmount: "1",
246
- client: mockClient,
247
- }),
248
- { wrapper },
249
- );
250
-
251
- await waitFor(() => {
252
- expect(result.current.isSuccess).toBe(true);
253
- });
254
-
255
- // Should still have only 4 methods (3 unique wallet + 1 fiat)
256
- expect(result.current.data).toHaveLength(4);
257
-
258
- // Check that ETH only appears once
259
- const walletMethods = result.current.data.filter(
260
- (m) => m.type === "wallet",
261
- );
262
- const ethMethods = walletMethods.filter(
263
- (m) => m.type === "wallet" && m.originToken?.symbol === "ETH",
264
- );
265
- expect(ethMethods).toHaveLength(1);
266
- });
267
-
268
- it("should always include fiat payment option", async () => {
269
- mockRoutes.mockResolvedValueOnce(mockRouteData);
270
- const wrapper = createWrapper();
271
-
272
- const { result } = renderHook(
273
- () =>
274
- usePaymentMethods({
275
- destinationToken: mockDestinationToken,
276
- destinationAmount: "1",
277
- client: mockClient,
278
- }),
279
- { wrapper },
280
- );
281
-
282
- await waitFor(() => {
283
- expect(result.current.isSuccess).toBe(true);
284
- });
285
-
286
- const fiatMethods = result.current.data.filter((m) => m.type === "fiat");
287
- expect(fiatMethods).toHaveLength(1);
288
- expect(fiatMethods[0]).toEqual({
289
- type: "fiat",
290
- currency: "USD",
291
- });
292
- });
293
-
294
- it("should have correct query key for caching", async () => {
295
- mockRoutes.mockResolvedValueOnce(mockRouteData);
296
- const wrapper = createWrapper();
297
-
298
- const { result } = renderHook(
299
- () =>
300
- usePaymentMethods({
301
- destinationToken: mockDestinationToken,
302
- destinationAmount: "1",
303
- client: mockClient,
304
- }),
305
- { wrapper },
306
- );
307
-
308
- // The hook should use a query key that includes chain ID and token address
309
- await waitFor(() => {
310
- expect(result.current.isSuccess).toBe(true);
311
- });
312
-
313
- expect(mockRoutes).toHaveBeenCalledTimes(1);
314
- });
315
-
316
- it("should provide refetch functionality", async () => {
317
- mockRoutes.mockResolvedValueOnce(mockRouteData);
318
- const wrapper = createWrapper();
319
-
320
- const { result } = renderHook(
321
- () =>
322
- usePaymentMethods({
323
- destinationToken: mockDestinationToken,
324
- destinationAmount: "1",
325
- client: mockClient,
326
- }),
327
- { wrapper },
328
- );
329
-
330
- await waitFor(() => {
331
- expect(result.current.isSuccess).toBe(true);
332
- });
333
-
334
- expect(typeof result.current.refetch).toBe("function");
335
- });
336
- });