thirdweb 5.110.6 → 5.111.0-nightly-8ef418c543b89679286a200175a35c41e98240e2-20251101000402

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 (45) hide show
  1. package/dist/cjs/bridge/index.js +1 -3
  2. package/dist/cjs/bridge/index.js.map +1 -1
  3. package/dist/cjs/exports/react.js +2 -4
  4. package/dist/cjs/exports/react.js.map +1 -1
  5. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js +5 -6
  6. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  7. package/dist/cjs/version.js +1 -1
  8. package/dist/cjs/version.js.map +1 -1
  9. package/dist/esm/bridge/index.js +0 -1
  10. package/dist/esm/bridge/index.js.map +1 -1
  11. package/dist/esm/exports/react.js +0 -1
  12. package/dist/esm/exports/react.js.map +1 -1
  13. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js +5 -6
  14. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  15. package/dist/esm/version.js +1 -1
  16. package/dist/esm/version.js.map +1 -1
  17. package/dist/scripts/bridge-widget.js +70 -70
  18. package/dist/types/bridge/index.d.ts +0 -1
  19. package/dist/types/bridge/index.d.ts.map +1 -1
  20. package/dist/types/exports/react.d.ts +0 -1
  21. package/dist/types/exports/react.d.ts.map +1 -1
  22. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  23. package/dist/types/version.d.ts +1 -1
  24. package/dist/types/version.d.ts.map +1 -1
  25. package/package.json +1 -1
  26. package/src/bridge/index.ts +0 -1
  27. package/src/exports/react.ts +0 -4
  28. package/src/react/core/hooks/transaction/useSendTransaction.ts +5 -8
  29. package/src/version.ts +1 -1
  30. package/dist/cjs/bridge/Routes.js +0 -166
  31. package/dist/cjs/bridge/Routes.js.map +0 -1
  32. package/dist/cjs/react/core/hooks/useBridgeRoutes.js +0 -61
  33. package/dist/cjs/react/core/hooks/useBridgeRoutes.js.map +0 -1
  34. package/dist/esm/bridge/Routes.js +0 -163
  35. package/dist/esm/bridge/Routes.js.map +0 -1
  36. package/dist/esm/react/core/hooks/useBridgeRoutes.js +0 -58
  37. package/dist/esm/react/core/hooks/useBridgeRoutes.js.map +0 -1
  38. package/dist/types/bridge/Routes.d.ts +0 -166
  39. package/dist/types/bridge/Routes.d.ts.map +0 -1
  40. package/dist/types/react/core/hooks/useBridgeRoutes.d.ts +0 -29
  41. package/dist/types/react/core/hooks/useBridgeRoutes.d.ts.map +0 -1
  42. package/src/bridge/Routes.test.ts +0 -161
  43. package/src/bridge/Routes.ts +0 -228
  44. package/src/react/core/hooks/useBridgeRoutes.test.ts +0 -137
  45. package/src/react/core/hooks/useBridgeRoutes.ts +0 -75
@@ -1,137 +0,0 @@
1
- import {
2
- beforeEach,
3
- describe,
4
- expect,
5
- it,
6
- type MockedFunction,
7
- vi,
8
- } from "vitest";
9
- import { routes } from "../../../bridge/Routes.js";
10
- import { ApiError } from "../../../bridge/types/Errors.js";
11
- import type { Route } from "../../../bridge/types/Route.js";
12
- import type { ThirdwebClient } from "../../../client/client.js";
13
- import type { UseBridgeRoutesParams } from "./useBridgeRoutes.js";
14
-
15
- // Mock the Bridge routes function
16
- vi.mock("../../../bridge/Routes.js", () => ({
17
- routes: vi.fn(),
18
- }));
19
-
20
- const mockRoutes = routes as MockedFunction<typeof routes>;
21
-
22
- // Mock client
23
- const mockClient = { clientId: "test" } as ThirdwebClient;
24
-
25
- // Mock route data
26
- const mockRouteData: Route[] = [
27
- {
28
- destinationToken: {
29
- address: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
30
- chainId: 137,
31
- decimals: 18,
32
- name: "Wrapped Ethereum",
33
- priceUsd: 2000.0,
34
- symbol: "WETH",
35
- },
36
- originToken: {
37
- address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
38
- chainId: 1,
39
- decimals: 18,
40
- name: "Ethereum",
41
- priceUsd: 2000.0,
42
- symbol: "ETH",
43
- },
44
- },
45
- ];
46
-
47
- describe("useBridgeRoutes", () => {
48
- beforeEach(() => {
49
- vi.clearAllMocks();
50
- });
51
-
52
- it("should export correct hook parameters type", () => {
53
- // Type-only test to verify UseBridgeRoutesParams interface
54
- const params: UseBridgeRoutesParams = {
55
- client: mockClient,
56
- destinationChainId: 137,
57
- enabled: true,
58
- originChainId: 1,
59
- };
60
-
61
- expect(params).toBeDefined();
62
- expect(params.client).toBe(mockClient);
63
- expect(params.originChainId).toBe(1);
64
- expect(params.destinationChainId).toBe(137);
65
- expect(params.enabled).toBe(true);
66
- });
67
-
68
- it("should handle different parameter combinations", () => {
69
- const fullParams: UseBridgeRoutesParams = {
70
- client: mockClient,
71
- destinationChainId: 137,
72
- destinationTokenAddress: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
73
- enabled: false,
74
- limit: 10,
75
- maxSteps: 3,
76
- offset: 0,
77
- originChainId: 1,
78
- originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
79
- sortBy: "popularity",
80
- };
81
-
82
- expect(fullParams).toBeDefined();
83
- expect(fullParams.sortBy).toBe("popularity");
84
- expect(fullParams.maxSteps).toBe(3);
85
- expect(fullParams.limit).toBe(10);
86
- expect(fullParams.offset).toBe(0);
87
- });
88
-
89
- it("should have optional enabled parameter defaulting to true", () => {
90
- const paramsWithoutEnabled: UseBridgeRoutesParams = {
91
- client: mockClient,
92
- destinationChainId: 137,
93
- originChainId: 1,
94
- };
95
-
96
- expect(paramsWithoutEnabled.enabled).toBeUndefined(); // Should be optional
97
- });
98
-
99
- it("should validate that Bridge.routes would be called with correct parameters", async () => {
100
- const testParams = {
101
- client: mockClient,
102
- destinationChainId: 137,
103
- originChainId: 1,
104
- originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" as const,
105
- };
106
-
107
- // Mock the routes function to return our test data
108
- mockRoutes.mockResolvedValue(mockRouteData);
109
-
110
- // Directly call the routes function to verify it works with our parameters
111
- const result = await routes(testParams);
112
-
113
- expect(mockRoutes).toHaveBeenCalledWith(testParams);
114
- expect(result).toEqual(mockRouteData);
115
- });
116
-
117
- it("should handle API errors properly", async () => {
118
- const apiError = new ApiError({
119
- code: "INVALID_INPUT",
120
- message: "Invalid parameters",
121
- statusCode: 400,
122
- });
123
-
124
- mockRoutes.mockRejectedValue(apiError);
125
-
126
- try {
127
- await routes({
128
- client: mockClient,
129
- destinationChainId: 137,
130
- originChainId: 1,
131
- });
132
- } catch (error) {
133
- expect(error).toBe(apiError);
134
- expect(error).toBeInstanceOf(ApiError);
135
- }
136
- });
137
- });
@@ -1,75 +0,0 @@
1
- import { useQuery } from "@tanstack/react-query";
2
- import type { routes as RoutesTypes } from "../../../bridge/Routes.js";
3
- import { routes } from "../../../bridge/Routes.js";
4
- import { ApiError } from "../../../bridge/types/Errors.js";
5
- import { mapBridgeError } from "../errors/mapBridgeError.js";
6
-
7
- /**
8
- * Parameters for the useBridgeRoutes hook
9
- */
10
- export type UseBridgeRoutesParams = RoutesTypes.Options & {
11
- /**
12
- * Whether to enable the query. Useful for conditional fetching.
13
- * @default true
14
- */
15
- enabled?: boolean;
16
- };
17
-
18
- /**
19
- * Hook that fetches available bridge routes with caching and retry logic
20
- *
21
- * @param params - Parameters for fetching routes including client and filter options
22
- * @returns React Query result with routes data, loading state, and error handling
23
- *
24
- * @example
25
- * ```tsx
26
- * const { data: routes, isLoading, error } = useBridgeRoutes({
27
- * client: thirdwebClient,
28
- * originChainId: 1,
29
- * destinationChainId: 137,
30
- * originTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
31
- * });
32
- * ```
33
- */
34
- export function useBridgeRoutes(params: UseBridgeRoutesParams) {
35
- const { enabled = true, ...routeParams } = params;
36
-
37
- return useQuery({
38
- enabled: enabled && !!routeParams.client,
39
- gcTime: 10 * 60 * 1000,
40
- queryFn: () => routes(routeParams),
41
- queryKey: [
42
- "bridge-routes",
43
- {
44
- destinationChainId: routeParams.destinationChainId,
45
- destinationTokenAddress: routeParams.destinationTokenAddress,
46
- limit: routeParams.limit,
47
- maxSteps: routeParams.maxSteps,
48
- offset: routeParams.offset,
49
- originChainId: routeParams.originChainId,
50
- originTokenAddress: routeParams.originTokenAddress,
51
- sortBy: routeParams.sortBy,
52
- },
53
- ], // 5 minutes - routes are relatively stable
54
- retry: (failureCount, error) => {
55
- // Handle both ApiError and generic Error instances
56
- if (error instanceof ApiError) {
57
- const bridgeError = mapBridgeError(error);
58
-
59
- // Don't retry on client-side errors (4xx)
60
- if (
61
- bridgeError.statusCode &&
62
- bridgeError.statusCode >= 400 &&
63
- bridgeError.statusCode < 500
64
- ) {
65
- return false;
66
- }
67
- }
68
-
69
- // Retry up to 3 times for server errors or network issues
70
- return failureCount < 3;
71
- }, // 10 minutes garbage collection
72
- retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000),
73
- staleTime: 5 * 60 * 1000, // Exponential backoff, max 30s
74
- });
75
- }