@@ -2,7 +2,7 @@ import type { ThirdwebClient } from "../client/client.js";
22import { getThirdwebBaseUrl } from "../utils/domains.js" ;
33import { getClientFetch } from "../utils/fetch.js" ;
44import { ApiError } from "./types/Errors.js" ;
5- import type { Token } from "./types/Token.js" ;
5+ import type { Token , TokenWithPrices } from "./types/Token.js" ;
66
77/**
88 * Retrieves supported Universal Bridge tokens based on the provided filters.
@@ -128,9 +128,20 @@ import type { Token } from "./types/Token.js";
128128 * @bridge
129129 * @beta
130130 */
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 ;
134145
135146 const clientFetch = getClientFetch ( client ) ;
136147 const url = new URL ( `${ getThirdwebBaseUrl ( "bridge" ) } /v1/tokens` ) ;
@@ -153,6 +164,9 @@ export async function tokens(options: tokens.Options): Promise<tokens.Result> {
153164 if ( offset !== null && offset !== undefined ) {
154165 url . searchParams . set ( "offset" , offset . toString ( ) ) ;
155166 }
167+ if ( includePrices !== undefined ) {
168+ url . searchParams . set ( "includePrices" , includePrices . toString ( ) ) ;
169+ }
156170
157171 const response = await clientFetch ( url . toString ( ) ) ;
158172 if ( ! response . ok ) {
@@ -165,15 +179,15 @@ export async function tokens(options: tokens.Options): Promise<tokens.Result> {
165179 } ) ;
166180 }
167181
168- const { data } : { data : Token [ ] } = await response . json ( ) ;
182+ const { data } : { data : R [ ] } = await response . json ( ) ;
169183 return data ;
170184}
171185
172186export declare namespace tokens {
173187 /**
174188 * Input parameters for {@link tokens}.
175189 */
176- type Options = {
190+ type Options < IncludePrices extends boolean > = {
177191 /** Your {@link ThirdwebClient} instance. */
178192 client : ThirdwebClient ;
179193 /** Filter by a specific chain ID. */
@@ -188,12 +202,14 @@ export declare namespace tokens {
188202 limit ?: number ;
189203 /** Number of tokens to skip (min: 0, default: 0). */
190204 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 ;
191207 } ;
192208
193209 /**
194210 * The result returned from {@link Bridge.tokens}.
195211 */
196- type Result = Token [ ] ;
212+ type Result < T extends Token | TokenWithPrices > = T [ ] ;
197213}
198214
199215/**
@@ -254,7 +270,7 @@ export async function add(options: add.Options): Promise<add.Result> {
254270 } ) ;
255271 }
256272
257- const { data } : { data : Token } = await response . json ( ) ;
273+ const { data } : { data : TokenWithPrices } = await response . json ( ) ;
258274 return data ;
259275}
260276
@@ -274,5 +290,5 @@ export declare namespace add {
274290 /**
275291 * The result returned from {@link Bridge.add}.
276292 */
277- type Result = Token ;
293+ type Result = TokenWithPrices ;
278294}
0 commit comments