thirdweb 5.105.38 → 5.105.39

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 (74) hide show
  1. package/dist/cjs/bridge/Token.js +4 -1
  2. package/dist/cjs/bridge/Token.js.map +1 -1
  3. package/dist/cjs/react/web/ui/Bridge/BridgeOrchestrator.js.map +1 -1
  4. package/dist/cjs/react/web/ui/Bridge/DirectPayment.js.map +1 -1
  5. package/dist/cjs/react/web/ui/Bridge/FundWallet.js.map +1 -1
  6. package/dist/cjs/react/web/ui/Bridge/TransactionPayment.js.map +1 -1
  7. package/dist/cjs/stories/Bridge/fixtures.js.map +1 -1
  8. package/dist/cjs/version.js +1 -1
  9. package/dist/esm/bridge/Token.js +4 -1
  10. package/dist/esm/bridge/Token.js.map +1 -1
  11. package/dist/esm/react/web/ui/Bridge/BridgeOrchestrator.js.map +1 -1
  12. package/dist/esm/react/web/ui/Bridge/DirectPayment.js.map +1 -1
  13. package/dist/esm/react/web/ui/Bridge/FundWallet.js.map +1 -1
  14. package/dist/esm/react/web/ui/Bridge/TransactionPayment.js.map +1 -1
  15. package/dist/esm/stories/Bridge/fixtures.js.map +1 -1
  16. package/dist/esm/version.js +1 -1
  17. package/dist/types/bridge/Onramp.d.ts +2 -2
  18. package/dist/types/bridge/Onramp.d.ts.map +1 -1
  19. package/dist/types/bridge/Token.d.ts +7 -5
  20. package/dist/types/bridge/Token.d.ts.map +1 -1
  21. package/dist/types/bridge/index.d.ts +1 -1
  22. package/dist/types/bridge/index.d.ts.map +1 -1
  23. package/dist/types/bridge/types/Route.d.ts +7 -7
  24. package/dist/types/bridge/types/Route.d.ts.map +1 -1
  25. package/dist/types/bridge/types/Token.d.ts +2 -0
  26. package/dist/types/bridge/types/Token.d.ts.map +1 -1
  27. package/dist/types/pay/convert/get-token.d.ts +2 -2
  28. package/dist/types/pay/convert/get-token.d.ts.map +1 -1
  29. package/dist/types/react/core/hooks/usePaymentMethods.d.ts.map +1 -1
  30. package/dist/types/react/core/hooks/useTransactionDetails.d.ts +2 -2
  31. package/dist/types/react/core/hooks/useTransactionDetails.d.ts.map +1 -1
  32. package/dist/types/react/core/machines/paymentMachine.d.ts +4 -4
  33. package/dist/types/react/core/machines/paymentMachine.d.ts.map +1 -1
  34. package/dist/types/react/web/ui/Bridge/BridgeOrchestrator.d.ts +3 -3
  35. package/dist/types/react/web/ui/Bridge/BridgeOrchestrator.d.ts.map +1 -1
  36. package/dist/types/react/web/ui/Bridge/DirectPayment.d.ts +2 -2
  37. package/dist/types/react/web/ui/Bridge/DirectPayment.d.ts.map +1 -1
  38. package/dist/types/react/web/ui/Bridge/FundWallet.d.ts +2 -2
  39. package/dist/types/react/web/ui/Bridge/FundWallet.d.ts.map +1 -1
  40. package/dist/types/react/web/ui/Bridge/TransactionPayment.d.ts +2 -2
  41. package/dist/types/react/web/ui/Bridge/TransactionPayment.d.ts.map +1 -1
  42. package/dist/types/stories/Bridge/BridgeOrchestrator.stories.d.ts +1 -1
  43. package/dist/types/stories/Bridge/BridgeOrchestrator.stories.d.ts.map +1 -1
  44. package/dist/types/stories/Bridge/DirectPayment.stories.d.ts +2 -2
  45. package/dist/types/stories/Bridge/DirectPayment.stories.d.ts.map +1 -1
  46. package/dist/types/stories/Bridge/FundWallet.stories.d.ts +2 -2
  47. package/dist/types/stories/Bridge/FundWallet.stories.d.ts.map +1 -1
  48. package/dist/types/stories/Bridge/PaymentDetails.stories.d.ts +1 -1
  49. package/dist/types/stories/Bridge/PaymentSelection.stories.d.ts +1 -1
  50. package/dist/types/stories/Bridge/SuccessScreen.stories.d.ts +1 -1
  51. package/dist/types/stories/Bridge/SuccessScreen.stories.d.ts.map +1 -1
  52. package/dist/types/stories/Bridge/TransactionPayment.stories.d.ts +1 -1
  53. package/dist/types/stories/Bridge/TransactionPayment.stories.d.ts.map +1 -1
  54. package/dist/types/stories/Bridge/fixtures.d.ts +4 -4
  55. package/dist/types/stories/Bridge/fixtures.d.ts.map +1 -1
  56. package/dist/types/stories/TokenBalanceRow.stories.d.ts +1 -1
  57. package/dist/types/version.d.ts +1 -1
  58. package/package.json +1 -1
  59. package/src/bridge/Onramp.ts +2 -2
  60. package/src/bridge/Token.test.ts +20 -2
  61. package/src/bridge/Token.ts +25 -9
  62. package/src/bridge/index.ts +1 -1
  63. package/src/bridge/types/Route.ts +7 -7
  64. package/src/bridge/types/Token.ts +3 -0
  65. package/src/pay/convert/get-token.ts +2 -2
  66. package/src/react/core/hooks/usePaymentMethods.ts +2 -2
  67. package/src/react/core/hooks/useTransactionDetails.ts +2 -2
  68. package/src/react/core/machines/paymentMachine.ts +4 -4
  69. package/src/react/web/ui/Bridge/BridgeOrchestrator.tsx +4 -4
  70. package/src/react/web/ui/Bridge/DirectPayment.tsx +6 -2
  71. package/src/react/web/ui/Bridge/FundWallet.tsx +6 -2
  72. package/src/react/web/ui/Bridge/TransactionPayment.tsx +6 -2
  73. package/src/stories/Bridge/fixtures.ts +4 -4
  74. package/src/version.ts +1 -1
@@ -2,7 +2,7 @@ import type { ThirdwebClient } from "../client/client.js";
2
2
  import { getThirdwebBaseUrl } from "../utils/domains.js";
3
3
  import { getClientFetch } from "../utils/fetch.js";
4
4
  import { ApiError } from "./types/Errors.js";
5
- import type { Token } from "./types/Token.js";
5
+ import type { Token, TokenWithPrices } from "./types/Token.js";
6
6
 
7
7
  /**
8
8
  * Retrieves supported Universal Bridge tokens based on the provided filters.
@@ -128,9 +128,20 @@ import type { Token } from "./types/Token.js";
128
128
  * @bridge
129
129
  * @beta
130
130
  */
131
- export async function tokens(options: tokens.Options): Promise<tokens.Result> {
132
- const { client, chainId, tokenAddress, symbol, name, limit, offset } =
133
- options;
131
+ export async function tokens<
132
+ IncludePrices extends boolean = true,
133
+ R extends Token | TokenWithPrices = TokenWithPrices,
134
+ >(options: tokens.Options<IncludePrices>): Promise<R[]> {
135
+ const {
136
+ client,
137
+ chainId,
138
+ tokenAddress,
139
+ symbol,
140
+ name,
141
+ limit,
142
+ offset,
143
+ includePrices,
144
+ } = options;
134
145
 
135
146
  const clientFetch = getClientFetch(client);
136
147
  const url = new URL(`${getThirdwebBaseUrl("bridge")}/v1/tokens`);
@@ -153,6 +164,9 @@ export async function tokens(options: tokens.Options): Promise<tokens.Result> {
153
164
  if (offset !== null && offset !== undefined) {
154
165
  url.searchParams.set("offset", offset.toString());
155
166
  }
167
+ if (includePrices !== undefined) {
168
+ url.searchParams.set("includePrices", includePrices.toString());
169
+ }
156
170
 
157
171
  const response = await clientFetch(url.toString());
158
172
  if (!response.ok) {
@@ -165,7 +179,7 @@ export async function tokens(options: tokens.Options): Promise<tokens.Result> {
165
179
  });
166
180
  }
167
181
 
168
- const { data }: { data: Token[] } = await response.json();
182
+ const { data }: { data: R[] } = await response.json();
169
183
  return data;
170
184
  }
171
185
 
@@ -173,7 +187,7 @@ export declare namespace tokens {
173
187
  /**
174
188
  * Input parameters for {@link tokens}.
175
189
  */
176
- type Options = {
190
+ type Options<IncludePrices extends boolean> = {
177
191
  /** Your {@link ThirdwebClient} instance. */
178
192
  client: ThirdwebClient;
179
193
  /** Filter by a specific chain ID. */
@@ -188,12 +202,14 @@ export declare namespace tokens {
188
202
  limit?: number;
189
203
  /** Number of tokens to skip (min: 0, default: 0). */
190
204
  offset?: number | null;
205
+ /** Whether or not to include prices for the tokens. Setting this to false will speed up the request. */
206
+ includePrices?: IncludePrices;
191
207
  };
192
208
 
193
209
  /**
194
210
  * The result returned from {@link Bridge.tokens}.
195
211
  */
196
- type Result = Token[];
212
+ type Result<T extends Token | TokenWithPrices> = T[];
197
213
  }
198
214
 
199
215
  /**
@@ -254,7 +270,7 @@ export async function add(options: add.Options): Promise<add.Result> {
254
270
  });
255
271
  }
256
272
 
257
- const { data }: { data: Token } = await response.json();
273
+ const { data }: { data: TokenWithPrices } = await response.json();
258
274
  return data;
259
275
  }
260
276
 
@@ -274,5 +290,5 @@ export declare namespace add {
274
290
  /**
275
291
  * The result returned from {@link Bridge.add}.
276
292
  */
277
- type Result = Token;
293
+ type Result = TokenWithPrices;
278
294
  }
@@ -17,7 +17,7 @@ export type {
17
17
  RouteTransaction,
18
18
  } from "./types/Route.js";
19
19
  export type { Status } from "./types/Status.js";
20
- export type { Token } from "./types/Token.js";
20
+ export type { Token, TokenWithPrices } from "./types/Token.js";
21
21
  export type { WebhookPayload } from "./Webhook.js";
22
22
  export * as Webhook from "./Webhook.js";
23
23
  export { parse } from "./Webhook.js";
@@ -2,24 +2,24 @@ import type { Hex as ox__Hex } from "ox";
2
2
  import type { Chain } from "../../chains/types.js";
3
3
  import type { ThirdwebClient } from "../../client/client.js";
4
4
  import type { Action } from "./BridgeAction.js";
5
- import type { Token } from "./Token.js";
5
+ import type { TokenWithPrices } from "./Token.js";
6
6
 
7
7
  export type Route = {
8
- originToken: Token;
9
- destinationToken: Token;
8
+ originToken: TokenWithPrices;
9
+ destinationToken: TokenWithPrices;
10
10
  };
11
11
 
12
12
  export type RouteQuoteStep = {
13
- originToken: Token;
14
- destinationToken: Token;
13
+ originToken: TokenWithPrices;
14
+ destinationToken: TokenWithPrices;
15
15
  originAmount: bigint;
16
16
  destinationAmount: bigint;
17
17
  estimatedExecutionTimeMs: number;
18
18
  };
19
19
 
20
20
  export type RouteStep = {
21
- originToken: Token;
22
- destinationToken: Token;
21
+ originToken: TokenWithPrices;
22
+ destinationToken: TokenWithPrices;
23
23
  originAmount: bigint;
24
24
  destinationAmount: bigint;
25
25
  estimatedExecutionTimeMs: number;
@@ -7,5 +7,8 @@ export type Token = {
7
7
  symbol: string;
8
8
  name: string;
9
9
  iconUri?: string;
10
+ };
11
+
12
+ export type TokenWithPrices = Token & {
10
13
  prices: Record<string, number>;
11
14
  };
@@ -1,5 +1,5 @@
1
1
  import { add, tokens } from "../../bridge/Token.js";
2
- import type { Token } from "../../bridge/types/Token.js";
2
+ import type { TokenWithPrices } from "../../bridge/types/Token.js";
3
3
  import type { ThirdwebClient } from "../../client/client.js";
4
4
  import { withCache } from "../../utils/promise/withCache.js";
5
5
 
@@ -7,7 +7,7 @@ export async function getToken(
7
7
  client: ThirdwebClient,
8
8
  tokenAddress: string,
9
9
  chainId: number,
10
- ): Promise<Token> {
10
+ ): Promise<TokenWithPrices> {
11
11
  return withCache(
12
12
  async () => {
13
13
  const result = await tokens({
@@ -1,7 +1,7 @@
1
1
  import { useQuery } from "@tanstack/react-query";
2
2
  import type { Quote } from "../../../bridge/index.js";
3
3
  import { ApiError } from "../../../bridge/types/Errors.js";
4
- import type { Token } from "../../../bridge/types/Token.js";
4
+ import type { Token, TokenWithPrices } from "../../../bridge/types/Token.js";
5
5
  import type { ThirdwebClient } from "../../../client/client.js";
6
6
  import { getThirdwebBaseUrl } from "../../../utils/domains.js";
7
7
  import { getClientFetch } from "../../../utils/fetch.js";
@@ -82,7 +82,7 @@ export function usePaymentMethods(options: {
82
82
 
83
83
  const {
84
84
  data: allValidOriginTokens,
85
- }: { data: { quote: Quote; balance: string; token: Token }[] } =
85
+ }: { data: { quote: Quote; balance: string; token: TokenWithPrices }[] } =
86
86
  await response.json();
87
87
 
88
88
  // Sort by enough balance to pay THEN gross balance
@@ -1,7 +1,7 @@
1
1
  import { useQuery } from "@tanstack/react-query";
2
2
  import type { AbiFunction } from "abitype";
3
3
  import { toFunctionSelector } from "viem";
4
- import type { Token } from "../../../bridge/index.js";
4
+ import type { TokenWithPrices } from "../../../bridge/index.js";
5
5
  import type { ThirdwebClient } from "../../../client/client.js";
6
6
  import { NATIVE_TOKEN_ADDRESS } from "../../../constants/addresses.js";
7
7
  import type { CompilerMetadata } from "../../../contract/actions/compiler-metadata.js";
@@ -34,7 +34,7 @@ interface TransactionDetails {
34
34
  usdValueDisplay: string | null;
35
35
  txCostDisplay: string;
36
36
  gasCostDisplay: string | null;
37
- tokenInfo: Token | null;
37
+ tokenInfo: TokenWithPrices | null;
38
38
  costWei: bigint;
39
39
  gasCostWei: bigint | null;
40
40
  totalCost: string;
@@ -1,6 +1,6 @@
1
1
  import { useCallback, useState } from "react";
2
2
  import type { Quote } from "../../../bridge/index.js";
3
- import type { Token } from "../../../bridge/types/Token.js";
3
+ import type { TokenWithPrices } from "../../../bridge/types/Token.js";
4
4
  import type { Address } from "../../../utils/address.js";
5
5
  import type { AsyncStorage } from "../../../utils/storage/AsyncStorage.js";
6
6
  import type { Wallet } from "../../../wallets/interfaces/wallet.js";
@@ -23,7 +23,7 @@ export type PaymentMethod =
23
23
  | {
24
24
  type: "wallet";
25
25
  payerWallet: Wallet;
26
- originToken: Token;
26
+ originToken: TokenWithPrices;
27
27
  balance: bigint;
28
28
  quote: Quote;
29
29
  }
@@ -43,7 +43,7 @@ export interface PaymentMachineContext {
43
43
 
44
44
  // Target requirements (resolved in init state)
45
45
  destinationAmount?: string;
46
- destinationToken?: Token;
46
+ destinationToken?: TokenWithPrices;
47
47
  receiverAddress?: Address;
48
48
 
49
49
  // User selections (set in methodSelection state)
@@ -73,7 +73,7 @@ export interface PaymentMachineContext {
73
73
  type PaymentMachineEvent =
74
74
  | {
75
75
  type: "DESTINATION_CONFIRMED";
76
- destinationToken: Token;
76
+ destinationToken: TokenWithPrices;
77
77
  destinationAmount: string;
78
78
  receiverAddress: Address;
79
79
  }
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { useCallback, useMemo } from "react";
3
- import type { Token } from "../../../../bridge/types/Token.js";
3
+ import type { TokenWithPrices } from "../../../../bridge/types/Token.js";
4
4
  import type { ThirdwebClient } from "../../../../client/client.js";
5
5
  import type { SupportedFiatCurrency } from "../../../../pay/convert/type.js";
6
6
  import type { PurchaseData } from "../../../../pay/types.js";
@@ -46,7 +46,7 @@ export type UIOptions = Prettify<
46
46
  } & (
47
47
  | {
48
48
  mode: "fund_wallet";
49
- destinationToken: Token;
49
+ destinationToken: TokenWithPrices;
50
50
  initialAmount?: string;
51
51
  presetOptions?: [number, number, number];
52
52
  }
@@ -54,7 +54,7 @@ export type UIOptions = Prettify<
54
54
  mode: "direct_payment";
55
55
  paymentInfo: {
56
56
  sellerAddress: Address;
57
- token: Token;
57
+ token: TokenWithPrices;
58
58
  amount: string;
59
59
  feePayer?: "sender" | "receiver";
60
60
  };
@@ -235,7 +235,7 @@ export function BridgeOrchestrator({
235
235
 
236
236
  // Handle requirements resolved from FundWallet and DirectPayment
237
237
  const handleRequirementsResolved = useCallback(
238
- (amount: string, token: Token, receiverAddress: Address) => {
238
+ (amount: string, token: TokenWithPrices, receiverAddress: Address) => {
239
239
  send({
240
240
  destinationAmount: amount,
241
241
  destinationToken: token,
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import type { Token } from "../../../../bridge/types/Token.js";
2
+ import type { TokenWithPrices } from "../../../../bridge/types/Token.js";
3
3
  import { defineChain } from "../../../../chains/utils.js";
4
4
  import type { ThirdwebClient } from "../../../../client/client.js";
5
5
  import type { Address } from "../../../../utils/address.js";
@@ -28,7 +28,11 @@ export interface DirectPaymentProps {
28
28
  /**
29
29
  * Called when user continues with the payment
30
30
  */
31
- onContinue: (amount: string, token: Token, receiverAddress: Address) => void;
31
+ onContinue: (
32
+ amount: string,
33
+ token: TokenWithPrices,
34
+ receiverAddress: Address,
35
+ ) => void;
32
36
 
33
37
  /**
34
38
  * Whether to show thirdweb branding in the widget.
@@ -1,7 +1,7 @@
1
1
  /** biome-ignore-all lint/a11y/useSemanticElements: FIXME */
2
2
  "use client";
3
3
  import { useRef, useState } from "react";
4
- import type { Token } from "../../../../bridge/types/Token.js";
4
+ import type { TokenWithPrices } from "../../../../bridge/types/Token.js";
5
5
  import type { ThirdwebClient } from "../../../../client/client.js";
6
6
  import { type Address, getAddress } from "../../../../utils/address.js";
7
7
  import { numberToPlainString } from "../../../../utils/formatNumber.js";
@@ -46,7 +46,11 @@ export interface FundWalletProps {
46
46
  /**
47
47
  * Called when continue is clicked with the resolved requirements
48
48
  */
49
- onContinue: (amount: string, token: Token, receiverAddress: Address) => void;
49
+ onContinue: (
50
+ amount: string,
51
+ token: TokenWithPrices,
52
+ receiverAddress: Address,
53
+ ) => void;
50
54
 
51
55
  /**
52
56
  * Quick buy amounts
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { useQuery } from "@tanstack/react-query";
3
- import type { Token } from "../../../../bridge/index.js";
3
+ import type { TokenWithPrices } from "../../../../bridge/types/Token.js";
4
4
  import type { ThirdwebClient } from "../../../../client/client.js";
5
5
  import { NATIVE_TOKEN_ADDRESS } from "../../../../constants/addresses.js";
6
6
  import {
@@ -46,7 +46,11 @@ export interface TransactionPaymentProps {
46
46
  /**
47
47
  * Called when user confirms transaction execution
48
48
  */
49
- onContinue: (amount: string, token: Token, receiverAddress: Address) => void;
49
+ onContinue: (
50
+ amount: string,
51
+ token: TokenWithPrices,
52
+ receiverAddress: Address,
53
+ ) => void;
50
54
 
51
55
  /**
52
56
  * Request to execute the transaction immediately (skips funding flow)
@@ -1,5 +1,5 @@
1
1
  import { stringify } from "viem";
2
- import type { Token } from "../../bridge/index.js";
2
+ import type { TokenWithPrices } from "../../bridge/types/Token.js";
3
3
  import { base } from "../../chains/chain-definitions/base.js";
4
4
  import { baseSepolia } from "../../chains/chain-definitions/base-sepolia.js";
5
5
  import { polygon } from "../../chains/chain-definitions/polygon.js";
@@ -19,7 +19,7 @@ import { toWei } from "../../utils/units.js";
19
19
  import type { Account, Wallet } from "../../wallets/interfaces/wallet.js";
20
20
  import { storyClient } from "../utils.js";
21
21
 
22
- export const ETH: Token = {
22
+ export const ETH: TokenWithPrices = {
23
23
  address: NATIVE_TOKEN_ADDRESS,
24
24
  chainId: 10,
25
25
  decimals: 18,
@@ -32,7 +32,7 @@ export const ETH: Token = {
32
32
  symbol: "ETH",
33
33
  };
34
34
 
35
- export const USDC: Token = {
35
+ export const USDC: TokenWithPrices = {
36
36
  address: getDefaultToken(base, "USDC")?.address ?? "",
37
37
  chainId: base.id,
38
38
  decimals: 6,
@@ -45,7 +45,7 @@ export const USDC: Token = {
45
45
  symbol: "USDC",
46
46
  };
47
47
 
48
- export const UNI: Token = {
48
+ export const UNI: TokenWithPrices = {
49
49
  address: "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
50
50
  chainId: 10,
51
51
  decimals: 18,
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.105.38";
1
+ export const version = "5.105.39";