0xtrails 0.5.0 → 0.6.0
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.
- package/dist/analytics.d.ts +8 -3
- package/dist/analytics.d.ts.map +1 -1
- package/dist/{ccip-DhEkQ6QC.js → ccip-Dw5AN7oU.js} +1 -1
- package/dist/cctp.d.ts +0 -149
- package/dist/cctp.d.ts.map +1 -1
- package/dist/chains.d.ts +28 -3
- package/dist/chains.d.ts.map +1 -1
- package/dist/config.d.ts +11 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/contractUtils.d.ts.map +1 -1
- package/dist/estimate.d.ts.map +1 -1
- package/dist/fees.d.ts.map +1 -1
- package/dist/gasless.d.ts +12 -0
- package/dist/gasless.d.ts.map +1 -1
- package/dist/{index-MhD2DA7_.js → index-BtVUTbEZ.js} +30984 -38945
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +108 -107
- package/dist/indexerClient.d.ts +2 -2
- package/dist/intents.d.ts +0 -17
- package/dist/intents.d.ts.map +1 -1
- package/dist/mutations.d.ts.map +1 -1
- package/dist/paymasterSend.d.ts.map +1 -1
- package/dist/prepareSend.d.ts +1 -1
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/sendUserOp.d.ts +0 -18
- package/dist/sendUserOp.d.ts.map +1 -1
- package/dist/tokenBalances.d.ts.map +1 -1
- package/dist/tokens.d.ts +10 -8
- package/dist/tokens.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +4 -5
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts +4 -5
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/standardDeposit.d.ts +2 -2
- package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/execution/transactionState.d.ts +2 -2
- package/dist/transactionIntent/execution/transactionState.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/crossChain.d.ts +4 -4
- package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/index.d.ts +0 -1
- package/dist/transactionIntent/handlers/index.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +4 -34
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -1
- package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -1
- package/dist/transactionIntent/quote/quoteHelpers.d.ts +2 -1
- package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -1
- package/dist/transactionIntent/types.d.ts +6 -19
- package/dist/transactionIntent/types.d.ts.map +1 -1
- package/dist/transactionIntent/utils/index.d.ts +0 -1
- package/dist/transactionIntent/utils/index.d.ts.map +1 -1
- package/dist/transactions.d.ts +2 -20
- package/dist/transactions.d.ts.map +1 -1
- package/dist/utils.d.ts +8 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/walletUtils.d.ts +21 -0
- package/dist/walletUtils.d.ts.map +1 -0
- package/dist/wallets.d.ts +33 -240
- package/dist/wallets.d.ts.map +1 -1
- package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
- package/dist/widget/components/FeeOption.d.ts +8 -13
- package/dist/widget/components/FeeOption.d.ts.map +1 -1
- package/dist/widget/components/FeeOptions.d.ts +11 -5
- package/dist/widget/components/FeeOptions.d.ts.map +1 -1
- package/dist/widget/components/NativeGasOption.d.ts.map +1 -1
- package/dist/widget/components/Pay.d.ts.map +1 -1
- package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
- package/dist/widget/components/QRCodeDeposit.d.ts +5 -0
- package/dist/widget/components/QRCodeDeposit.d.ts.map +1 -1
- package/dist/widget/components/QRCodeWalletSelect.d.ts +13 -0
- package/dist/widget/components/QRCodeWalletSelect.d.ts.map +1 -0
- package/dist/widget/components/QrCode.d.ts.map +1 -1
- package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
- package/dist/widget/components/Receipt.d.ts.map +1 -1
- package/dist/widget/components/ScreenHeader.d.ts +1 -1
- package/dist/widget/components/ScreenHeader.d.ts.map +1 -1
- package/dist/widget/components/Toast.d.ts.map +1 -1
- package/dist/widget/components/TokenImage.d.ts.map +1 -1
- package/dist/widget/css/compiled.css +1 -1
- package/dist/widget/hooks/useCheckout.d.ts +15 -1
- package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
- package/dist/widget/hooks/useCurrentScreen.d.ts +1 -1
- package/dist/widget/hooks/useCurrentScreen.d.ts.map +1 -1
- package/dist/widget/hooks/useDebugScreens.d.ts +1 -1
- package/dist/widget/hooks/useDebugScreens.d.ts.map +1 -1
- package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/hooks/useIsConnectedWalletSmartContract.d.ts +7 -0
- package/dist/widget/hooks/useIsConnectedWalletSmartContract.d.ts.map +1 -0
- package/dist/widget/hooks/useIsSequenceWallet.d.ts +6 -0
- package/dist/widget/hooks/useIsSequenceWallet.d.ts.map +1 -0
- package/dist/widget/hooks/useQuote.d.ts +5 -8
- package/dist/widget/hooks/useQuote.d.ts.map +1 -1
- package/dist/widget/hooks/useRecentTokens.d.ts.map +1 -1
- package/dist/widget/hooks/useSelectedFeeOption.d.ts +30 -0
- package/dist/widget/hooks/useSelectedFeeOption.d.ts.map +1 -0
- package/dist/widget/hooks/useSendForm.d.ts +6 -15
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
- package/dist/widget/index.js +1 -1
- package/dist/widget/providers/TrailsProvider.d.ts +23 -12
- package/dist/widget/providers/TrailsProvider.d.ts.map +1 -1
- package/dist/widget/widget.d.ts +11 -0
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/analytics.ts +53 -21
- package/src/cctp.ts +0 -1016
- package/src/chains.ts +93 -39
- package/src/config.ts +24 -6
- package/src/constants.ts +1 -4
- package/src/contractUtils.ts +6 -6
- package/src/estimate.ts +3 -6
- package/src/fees.ts +5 -10
- package/src/gasless.ts +45 -0
- package/src/index.ts +7 -6
- package/src/indexerClient.ts +2 -2
- package/src/intents.ts +52 -206
- package/src/mutations.ts +3 -2
- package/src/paymasterSend.ts +2 -5
- package/src/prepareSend.ts +9 -12
- package/src/sendUserOp.ts +3 -64
- package/src/tokenBalances.ts +2 -1
- package/src/tokens.ts +62 -133
- package/src/trailsClient.ts +1 -1
- package/src/transactionIntent/deposits/depositOrchestrator.ts +14 -15
- package/src/transactionIntent/deposits/gaslessDeposit.ts +70 -100
- package/src/transactionIntent/deposits/standardDeposit.ts +22 -28
- package/src/transactionIntent/execution/transactionState.ts +2 -2
- package/src/transactionIntent/handlers/crossChain.ts +165 -385
- package/src/transactionIntent/handlers/index.ts +0 -1
- package/src/transactionIntent/handlers/sameChainSameToken.ts +228 -94
- package/src/transactionIntent/quote/normalizeQuote.ts +4 -6
- package/src/transactionIntent/quote/quoteHelpers.ts +35 -3
- package/src/transactionIntent/types.ts +6 -27
- package/src/transactionIntent/utils/index.ts +0 -1
- package/src/transactions.ts +6 -203
- package/src/umd.tsx +1 -3
- package/src/utils.ts +28 -8
- package/src/walletUtils.ts +42 -0
- package/src/wallets.ts +361 -203
- package/src/widget/compiled.css +1 -1
- package/src/widget/components/AccountIntentTransactionHistory.tsx +73 -4
- package/src/widget/components/AccountSettings.tsx +17 -17
- package/src/widget/components/ChainList.tsx +3 -3
- package/src/widget/components/ClassicSwap.tsx +19 -10
- package/src/widget/components/ConfigDisplay.tsx +1 -1
- package/src/widget/components/FeeOption.tsx +63 -20
- package/src/widget/components/FeeOptions.tsx +54 -123
- package/src/widget/components/NativeGasOption.tsx +3 -1
- package/src/widget/components/Pay.tsx +18 -11
- package/src/widget/components/PoolDeposit.tsx +23 -10
- package/src/widget/components/QRCodeDeposit.tsx +50 -30
- package/src/widget/components/QRCodeWalletSelect.tsx +77 -0
- package/src/widget/components/QrCode.tsx +188 -233
- package/src/widget/components/QuoteDetails.tsx +48 -2
- package/src/widget/components/Receipt.tsx +5 -2
- package/src/widget/components/ScreenHeader.tsx +10 -8
- package/src/widget/components/Toast.tsx +10 -0
- package/src/widget/components/TokenImage.tsx +56 -13
- package/src/widget/hooks/useCheckout.ts +71 -0
- package/src/widget/hooks/useCurrentScreen.tsx +1 -0
- package/src/widget/hooks/useDebugScreens.ts +5 -0
- package/src/widget/hooks/useIntentTransactionHistory.ts +788 -418
- package/src/widget/hooks/useIsConnectedWalletSmartContract.ts +43 -0
- package/src/widget/hooks/useIsSequenceWallet.ts +17 -0
- package/src/widget/hooks/useQuote.ts +16 -17
- package/src/widget/hooks/useRecentTokens.ts +2 -1
- package/src/widget/hooks/useSelectedFeeOption.tsx +257 -0
- package/src/widget/hooks/useSendForm.ts +172 -47
- package/src/widget/hooks/useTokenList.ts +15 -2
- package/src/widget/providers/TrailsProvider.tsx +53 -25
- package/src/widget/widget.tsx +119 -48
- package/dist/cctpqueue.d.ts +0 -18
- package/dist/cctpqueue.d.ts.map +0 -1
- package/dist/preconditions.d.ts +0 -12
- package/dist/preconditions.d.ts.map +0 -1
- package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts +0 -62
- package/dist/transactionIntent/handlers/sameChainDifferentToken.d.ts.map +0 -1
- package/dist/transactionIntent/utils/lifiHelpers.d.ts +0 -10
- package/dist/transactionIntent/utils/lifiHelpers.d.ts.map +0 -1
- package/dist/widget/hooks/useSelectedFeeToken.d.ts +0 -33
- package/dist/widget/hooks/useSelectedFeeToken.d.ts.map +0 -1
- package/src/cctpqueue.ts +0 -69
- package/src/preconditions.ts +0 -47
- package/src/transactionIntent/handlers/sameChainDifferentToken.ts +0 -323
- package/src/transactionIntent/utils/lifiHelpers.ts +0 -68
- package/src/widget/hooks/useSelectedFeeToken.tsx +0 -288
package/src/tokens.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { zeroAddress, erc20Abi
|
|
3
|
-
import {
|
|
1
|
+
import { useQuery } from "@tanstack/react-query"
|
|
2
|
+
import { zeroAddress, erc20Abi } from "viem"
|
|
3
|
+
import {
|
|
4
|
+
getChainInfo,
|
|
5
|
+
getSupportedChains,
|
|
6
|
+
getPublicRpcClient,
|
|
7
|
+
} from "./chains.js"
|
|
4
8
|
import {
|
|
5
9
|
arbitrum,
|
|
6
10
|
base,
|
|
@@ -17,7 +21,10 @@ import { getRelaySupportedTokens, type Chain } from "./relaySdk.js"
|
|
|
17
21
|
import { useReadContracts } from "wagmi"
|
|
18
22
|
import { useMemo } from "react"
|
|
19
23
|
import { logger } from "./logger.js"
|
|
24
|
+
import { isNativeToken } from "./utils.js"
|
|
20
25
|
import { somnia } from "./customChains.js"
|
|
26
|
+
import { PROD_SEQUENCE_METADATA_URL } from "./constants.js"
|
|
27
|
+
import { useTrails } from "./widget/providers/TrailsProvider.js"
|
|
21
28
|
|
|
22
29
|
export type SupportedToken = {
|
|
23
30
|
id: string
|
|
@@ -48,6 +55,8 @@ export const commonTokenImages: Record<string, string> = {
|
|
|
48
55
|
APE: "https://assets.sequence.info/images/tokens/large/33139/0x0000000000000000000000000000000000000000.webp",
|
|
49
56
|
ANIME:
|
|
50
57
|
"https://assets.coingecko.com/coins/images/53575/large/anime.jpg?1736748703",
|
|
58
|
+
BNB: "https://assets.sequence.info/images/tokens/large/56/0x0000000000000000000000000000000000000000.webp",
|
|
59
|
+
AVAX: "https://assets.sequence.info/images/tokens/large/43114/0x0000000000000000000000000000000000000000.webp",
|
|
51
60
|
}
|
|
52
61
|
|
|
53
62
|
const cacheVersion = "01"
|
|
@@ -183,40 +192,6 @@ function getTokenImageCache(): Record<string, TokenImageCacheEntry> {
|
|
|
183
192
|
}
|
|
184
193
|
}
|
|
185
194
|
|
|
186
|
-
function setTokenImageCache(
|
|
187
|
-
key: string,
|
|
188
|
-
imageUrl: string,
|
|
189
|
-
found: boolean,
|
|
190
|
-
): void {
|
|
191
|
-
if (typeof window === "undefined") return
|
|
192
|
-
|
|
193
|
-
try {
|
|
194
|
-
const cache = getTokenImageCache()
|
|
195
|
-
cache[key] = {
|
|
196
|
-
imageUrl,
|
|
197
|
-
timestamp: Date.now(),
|
|
198
|
-
found,
|
|
199
|
-
}
|
|
200
|
-
localStorage.setItem(TOKEN_IMAGE_CACHE_KEY, JSON.stringify(cache))
|
|
201
|
-
} catch (error) {
|
|
202
|
-
logger.console.warn("[trails-sdk] Failed to cache token image:", error)
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// Dedicated QueryClient for token image fetching
|
|
207
|
-
const tokenImageQueryClient = new QueryClient({
|
|
208
|
-
defaultOptions: {
|
|
209
|
-
queries: {
|
|
210
|
-
staleTime: 24 * 60 * 60 * 1000, // 24 hours
|
|
211
|
-
gcTime: 7 * 24 * 60 * 60 * 1000, // 7 days
|
|
212
|
-
retry: 2,
|
|
213
|
-
retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000),
|
|
214
|
-
refetchOnWindowFocus: false,
|
|
215
|
-
refetchOnReconnect: false,
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
})
|
|
219
|
-
|
|
220
195
|
// Priority tokens that should appear first in the list
|
|
221
196
|
const PRIORITY_TOKENS = [
|
|
222
197
|
"ETH",
|
|
@@ -282,60 +257,6 @@ export function getCachedTokenImageUrl(
|
|
|
282
257
|
return cachedEntry?.imageUrl || ""
|
|
283
258
|
}
|
|
284
259
|
|
|
285
|
-
export async function getTokenImageUrlOrFallback({
|
|
286
|
-
chainId,
|
|
287
|
-
contractAddress,
|
|
288
|
-
symbol,
|
|
289
|
-
}: {
|
|
290
|
-
chainId?: number
|
|
291
|
-
contractAddress?: string
|
|
292
|
-
symbol?: string
|
|
293
|
-
}): Promise<string> {
|
|
294
|
-
const cacheKey = `${chainId}:${contractAddress}:${symbol}`
|
|
295
|
-
const imageUrl = getTokenImageUrl({ chainId, contractAddress, symbol })
|
|
296
|
-
|
|
297
|
-
// Check localStorage cache first
|
|
298
|
-
const cache = getTokenImageCache()
|
|
299
|
-
const cachedEntry = cache[cacheKey]
|
|
300
|
-
|
|
301
|
-
if (cachedEntry) {
|
|
302
|
-
if (cachedEntry.found) {
|
|
303
|
-
return cachedEntry.imageUrl
|
|
304
|
-
} else {
|
|
305
|
-
return "" // Return empty string if we previously found no image
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// Use QueryClient to fetch and cache the result
|
|
310
|
-
try {
|
|
311
|
-
const result = await tokenImageQueryClient.fetchQuery({
|
|
312
|
-
queryKey: ["tokenImage", chainId, contractAddress],
|
|
313
|
-
queryFn: async () => {
|
|
314
|
-
const response = await fetch(imageUrl, {
|
|
315
|
-
method: "HEAD", // Only fetch headers to check if image exists
|
|
316
|
-
cache: "no-cache", // Don't cache the fetch request itself
|
|
317
|
-
})
|
|
318
|
-
const found = response.ok
|
|
319
|
-
const resultUrl = found ? imageUrl : ""
|
|
320
|
-
|
|
321
|
-
// Cache the result in localStorage
|
|
322
|
-
setTokenImageCache(cacheKey, resultUrl, found)
|
|
323
|
-
|
|
324
|
-
return resultUrl
|
|
325
|
-
},
|
|
326
|
-
staleTime: 24 * 60 * 60 * 1000, // 24 hours
|
|
327
|
-
gcTime: 7 * 24 * 60 * 60 * 1000, // 7 days
|
|
328
|
-
})
|
|
329
|
-
|
|
330
|
-
return result
|
|
331
|
-
} catch (error) {
|
|
332
|
-
logger.console.error("[trails-sdk] Error fetching token image:", error)
|
|
333
|
-
// Cache the failure to avoid repeated requests
|
|
334
|
-
setTokenImageCache(cacheKey, "", false)
|
|
335
|
-
return ""
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
260
|
export async function getAllTokens(): Promise<SupportedToken[]> {
|
|
340
261
|
const relayTokens = (await getRelaySupportedTokens()) as SupportedToken[]
|
|
341
262
|
return relayTokens
|
|
@@ -352,20 +273,15 @@ export async function getSupportedTokens(): Promise<SupportedToken[]> {
|
|
|
352
273
|
})
|
|
353
274
|
}
|
|
354
275
|
|
|
355
|
-
|
|
276
|
+
// Use getTokenImageUrl directly (synchronous)
|
|
277
|
+
const imageUrl = getTokenImageUrl({
|
|
356
278
|
chainId: token.chainId,
|
|
357
279
|
contractAddress: token.contractAddress,
|
|
358
280
|
symbol: token.symbol,
|
|
359
281
|
})
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
.catch((error) => {
|
|
364
|
-
logger.console.error(
|
|
365
|
-
"[trails-sdk] Error getting token image url:",
|
|
366
|
-
error,
|
|
367
|
-
)
|
|
368
|
-
})
|
|
282
|
+
if (imageUrl) {
|
|
283
|
+
token.imageUrl = imageUrl
|
|
284
|
+
}
|
|
369
285
|
}
|
|
370
286
|
|
|
371
287
|
const additionalTokens: SupportedToken[] = []
|
|
@@ -451,23 +367,6 @@ export function useSupportedTokens({ chainId }: { chainId?: number } = {}): {
|
|
|
451
367
|
}
|
|
452
368
|
}
|
|
453
369
|
|
|
454
|
-
export async function getSourceTokenList(): Promise<string[]> {
|
|
455
|
-
const tokens = await getSupportedTokens()
|
|
456
|
-
return tokens.map((token) => token.symbol)
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
export function useSourceTokenList(): string[] {
|
|
460
|
-
const { data: list = [] } = useQuery({
|
|
461
|
-
queryKey: ["sourceTokenList"],
|
|
462
|
-
queryFn: getSourceTokenList,
|
|
463
|
-
staleTime: 1000 * 60 * 60, // 1 hour - token list rarely changes
|
|
464
|
-
gcTime: 1000 * 60 * 60 * 24, // 24 hours cache time
|
|
465
|
-
refetchOnWindowFocus: false,
|
|
466
|
-
refetchOnReconnect: false,
|
|
467
|
-
})
|
|
468
|
-
return list
|
|
469
|
-
}
|
|
470
|
-
|
|
471
370
|
const tokenNames: Record<string, string> = {
|
|
472
371
|
ETH: "Ethereum",
|
|
473
372
|
WETH: "Wrapped ETH",
|
|
@@ -593,10 +492,7 @@ export async function getTokenInfo(
|
|
|
593
492
|
}
|
|
594
493
|
|
|
595
494
|
// Create a public client for the specific chain
|
|
596
|
-
const publicClient =
|
|
597
|
-
chain: chainInfo,
|
|
598
|
-
transport: http(),
|
|
599
|
-
})
|
|
495
|
+
const publicClient = getPublicRpcClient(chainInfo)
|
|
600
496
|
|
|
601
497
|
// Read token data on-chain
|
|
602
498
|
const [name, symbol, decimals] = await Promise.all([
|
|
@@ -735,11 +631,13 @@ export function getTokenImageUrl({
|
|
|
735
631
|
contractAddress,
|
|
736
632
|
symbol,
|
|
737
633
|
fallbackImageUrl,
|
|
634
|
+
sequenceMetadataUrl,
|
|
738
635
|
}: {
|
|
739
636
|
chainId?: number
|
|
740
637
|
contractAddress?: string
|
|
741
638
|
symbol?: string
|
|
742
639
|
fallbackImageUrl?: string
|
|
640
|
+
sequenceMetadataUrl?: string
|
|
743
641
|
}) {
|
|
744
642
|
if (!chainId || !contractAddress || !symbol) {
|
|
745
643
|
return ""
|
|
@@ -765,14 +663,42 @@ export function getTokenImageUrl({
|
|
|
765
663
|
}
|
|
766
664
|
}
|
|
767
665
|
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
const imageUrl =
|
|
666
|
+
const baseUrl = sequenceMetadataUrl || PROD_SEQUENCE_METADATA_URL
|
|
667
|
+
const fallbackParam = fallbackImageUrl
|
|
668
|
+
? `?fallback=${encodeURIComponent(fallbackImageUrl)}`
|
|
669
|
+
: "?happy=true"
|
|
670
|
+
const imageUrl = `${baseUrl}/tokens/${chainId}/${contractAddress.toLowerCase()}/image${fallbackParam}`
|
|
773
671
|
return imageUrl
|
|
774
672
|
}
|
|
775
673
|
|
|
674
|
+
// React hook that returns a configured getTokenImageUrl function
|
|
675
|
+
export function useGetTokenImageUrl(): {
|
|
676
|
+
getTokenImageUrl: (params: {
|
|
677
|
+
chainId?: number
|
|
678
|
+
contractAddress?: string
|
|
679
|
+
symbol?: string
|
|
680
|
+
fallbackImageUrl?: string
|
|
681
|
+
}) => string
|
|
682
|
+
} {
|
|
683
|
+
const { sequenceMetadataUrl } = useTrails()
|
|
684
|
+
|
|
685
|
+
return useMemo(
|
|
686
|
+
() => ({
|
|
687
|
+
getTokenImageUrl: (params: {
|
|
688
|
+
chainId?: number
|
|
689
|
+
contractAddress?: string
|
|
690
|
+
symbol?: string
|
|
691
|
+
fallbackImageUrl?: string
|
|
692
|
+
}) =>
|
|
693
|
+
getTokenImageUrl({
|
|
694
|
+
...params,
|
|
695
|
+
sequenceMetadataUrl,
|
|
696
|
+
}),
|
|
697
|
+
}),
|
|
698
|
+
[sequenceMetadataUrl],
|
|
699
|
+
)
|
|
700
|
+
}
|
|
701
|
+
|
|
776
702
|
// React hook for token image fetching with caching
|
|
777
703
|
export function useTokenImageUrl({
|
|
778
704
|
chainId,
|
|
@@ -788,6 +714,7 @@ export function useTokenImageUrl({
|
|
|
788
714
|
error: Error | null
|
|
789
715
|
hasImage: boolean
|
|
790
716
|
} {
|
|
717
|
+
const { getTokenImageUrl } = useGetTokenImageUrl()
|
|
791
718
|
const {
|
|
792
719
|
data: imageUrl = "",
|
|
793
720
|
isLoading,
|
|
@@ -795,7 +722,7 @@ export function useTokenImageUrl({
|
|
|
795
722
|
} = useQuery({
|
|
796
723
|
queryKey: ["tokenImage", chainId, contractAddress, symbol],
|
|
797
724
|
queryFn: () =>
|
|
798
|
-
|
|
725
|
+
Promise.resolve(getTokenImageUrl({ chainId, contractAddress, symbol })),
|
|
799
726
|
enabled: !!chainId && !!contractAddress,
|
|
800
727
|
staleTime: 24 * 60 * 60 * 1000, // 24 hours
|
|
801
728
|
gcTime: 7 * 24 * 60 * 60 * 1000, // 7 days
|
|
@@ -834,11 +761,11 @@ export function useTokenInfo({
|
|
|
834
761
|
error: Error | null
|
|
835
762
|
} {
|
|
836
763
|
// Always call hooks unconditionally
|
|
764
|
+
const { getTokenImageUrl } = useGetTokenImageUrl()
|
|
837
765
|
const isAddress = address?.startsWith("0x") ?? false
|
|
838
766
|
|
|
839
767
|
// Handle any native token (zero address) - before any blockchain calls
|
|
840
|
-
const isNativeToken
|
|
841
|
-
address?.toLowerCase() === zeroAddress.toLowerCase() && !!chainId
|
|
768
|
+
const isNativeTokenAddress = isNativeToken(address) && !!chainId
|
|
842
769
|
|
|
843
770
|
// Check cache first
|
|
844
771
|
const cachedInfo = useMemo(() => {
|
|
@@ -853,7 +780,7 @@ export function useTokenInfo({
|
|
|
853
780
|
} as const
|
|
854
781
|
const result = useReadContracts({
|
|
855
782
|
contracts:
|
|
856
|
-
!!isAddress && !!chainId && !cachedInfo && !
|
|
783
|
+
!!isAddress && !!chainId && !cachedInfo && !isNativeTokenAddress
|
|
857
784
|
? [
|
|
858
785
|
{ ...contract, functionName: "name" },
|
|
859
786
|
{ ...contract, functionName: "symbol" },
|
|
@@ -868,7 +795,7 @@ export function useTokenInfo({
|
|
|
868
795
|
|
|
869
796
|
const tokenInfo = useMemo(() => {
|
|
870
797
|
// Handle native token (zero address) for any chain
|
|
871
|
-
if (
|
|
798
|
+
if (isNativeTokenAddress) {
|
|
872
799
|
const nativeSymbol = chainInfo?.nativeCurrency.symbol || "ETH"
|
|
873
800
|
const nativeName = chainInfo?.nativeCurrency.name || "Ethereum"
|
|
874
801
|
const decimals = chainInfo?.nativeCurrency.decimals ?? 18
|
|
@@ -930,7 +857,7 @@ export function useTokenInfo({
|
|
|
930
857
|
}, [
|
|
931
858
|
address,
|
|
932
859
|
chainId,
|
|
933
|
-
|
|
860
|
+
isNativeTokenAddress,
|
|
934
861
|
cachedInfo,
|
|
935
862
|
chainInfo?.name,
|
|
936
863
|
chainInfo?.nativeCurrency.symbol,
|
|
@@ -939,6 +866,7 @@ export function useTokenInfo({
|
|
|
939
866
|
name?.result,
|
|
940
867
|
symbol?.result,
|
|
941
868
|
decimals?.result,
|
|
869
|
+
getTokenImageUrl,
|
|
942
870
|
])
|
|
943
871
|
|
|
944
872
|
// Early return if not a valid address or chainId
|
|
@@ -967,6 +895,7 @@ export const tokenImageSymbolMap: Record<string, string> = {
|
|
|
967
895
|
USDT: "USDT",
|
|
968
896
|
DAI: "DAI",
|
|
969
897
|
xDAI: "DAI",
|
|
898
|
+
XDAI: "DAI",
|
|
970
899
|
WBTC: "WBTC",
|
|
971
900
|
cbBTC: "WBTC",
|
|
972
901
|
BAT: "BAT",
|
package/src/trailsClient.ts
CHANGED
|
@@ -25,7 +25,7 @@ export const useTrailsClient = (
|
|
|
25
25
|
|
|
26
26
|
const trailsClient = useMemo(() => {
|
|
27
27
|
return getTrailsClient({
|
|
28
|
-
apiKey: configOverride?.apiKey || trailsConfig.trailsApiKey,
|
|
28
|
+
apiKey: configOverride?.apiKey || trailsConfig.trailsApiKey || "",
|
|
29
29
|
hostname: configOverride?.hostname || trailsConfig.trailsApiUrl,
|
|
30
30
|
jwt: configOverride?.jwt,
|
|
31
31
|
})
|
|
@@ -5,8 +5,7 @@ import type {
|
|
|
5
5
|
WalletClient,
|
|
6
6
|
TransactionReceipt,
|
|
7
7
|
} from "viem"
|
|
8
|
-
import {
|
|
9
|
-
import type { TrailsApi } from "@0xsequence/trails-api"
|
|
8
|
+
import type { FeeOption, TrailsApi } from "@0xsequence/trails-api"
|
|
10
9
|
import type { TransactionState } from "../../transactions.js"
|
|
11
10
|
import type { CheckoutOnHandlers } from "../../widget/hooks/useCheckout.js"
|
|
12
11
|
import type {
|
|
@@ -14,8 +13,8 @@ import type {
|
|
|
14
13
|
GasFeeOptions,
|
|
15
14
|
ExecuteIntentResponse,
|
|
16
15
|
} from "@0xsequence/trails-api"
|
|
17
|
-
import type { SelectedFeeToken } from "../types.js"
|
|
18
16
|
import { logger } from "../../logger.js"
|
|
17
|
+
import { isNativeToken } from "../../utils.js"
|
|
19
18
|
import { attemptGaslessDeposit, getDoGasless } from "./gaslessDeposit.js"
|
|
20
19
|
import { attemptStandardDeposit } from "./standardDeposit.js"
|
|
21
20
|
|
|
@@ -24,7 +23,7 @@ export async function attemptUserDepositTx({
|
|
|
24
23
|
paymasterUrl,
|
|
25
24
|
chain,
|
|
26
25
|
account,
|
|
27
|
-
|
|
26
|
+
depositAmount,
|
|
28
27
|
originIntentAddress,
|
|
29
28
|
onOriginSend,
|
|
30
29
|
publicClient,
|
|
@@ -44,7 +43,7 @@ export async function attemptUserDepositTx({
|
|
|
44
43
|
depositAmountUsd,
|
|
45
44
|
feeOptions,
|
|
46
45
|
trailsClient,
|
|
47
|
-
|
|
46
|
+
selectedFeeOption,
|
|
48
47
|
walletId,
|
|
49
48
|
abortSignal,
|
|
50
49
|
checkoutOnHandlers,
|
|
@@ -58,7 +57,7 @@ export async function attemptUserDepositTx({
|
|
|
58
57
|
paymasterUrl?: string
|
|
59
58
|
chain: Chain
|
|
60
59
|
account: Account
|
|
61
|
-
|
|
60
|
+
depositAmount: string
|
|
62
61
|
originIntentAddress: string
|
|
63
62
|
onOriginSend?: () => void
|
|
64
63
|
publicClient: PublicClient
|
|
@@ -78,7 +77,7 @@ export async function attemptUserDepositTx({
|
|
|
78
77
|
depositAmountUsd: number
|
|
79
78
|
feeOptions?: GasFeeOptions
|
|
80
79
|
trailsClient: TrailsApi
|
|
81
|
-
|
|
80
|
+
selectedFeeOption?: FeeOption | null
|
|
82
81
|
walletId?: string
|
|
83
82
|
abortSignal?: AbortSignal
|
|
84
83
|
checkoutOnHandlers?: Partial<CheckoutOnHandlers>
|
|
@@ -121,7 +120,7 @@ export async function attemptUserDepositTx({
|
|
|
121
120
|
const doGasless = getDoGasless(
|
|
122
121
|
originTokenAddress,
|
|
123
122
|
feeOptions,
|
|
124
|
-
|
|
123
|
+
selectedFeeOption,
|
|
125
124
|
walletId,
|
|
126
125
|
)
|
|
127
126
|
logger.console.log(
|
|
@@ -131,11 +130,11 @@ export async function attemptUserDepositTx({
|
|
|
131
130
|
paymasterUrl,
|
|
132
131
|
hasFeeOptions: !!feeOptions,
|
|
133
132
|
feeOptionsCount: feeOptions?.feeOptions?.length || 0,
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
selectedFeeOption,
|
|
134
|
+
selectedFeeOptionSet:
|
|
135
|
+
selectedFeeOption !== null && selectedFeeOption !== undefined,
|
|
137
136
|
originTokenAddress,
|
|
138
|
-
isNotNative: originTokenAddress
|
|
137
|
+
isNotNative: !isNativeToken(originTokenAddress),
|
|
139
138
|
},
|
|
140
139
|
)
|
|
141
140
|
if (doGasless || paymasterUrl) {
|
|
@@ -151,7 +150,7 @@ export async function attemptUserDepositTx({
|
|
|
151
150
|
await attemptGaslessDeposit({
|
|
152
151
|
paymasterUrl,
|
|
153
152
|
depositTokenAddress: originTokenAddress,
|
|
154
|
-
depositTokenAmount:
|
|
153
|
+
depositTokenAmount: depositAmount,
|
|
155
154
|
depositRecipient: originIntentAddress,
|
|
156
155
|
onOriginSend,
|
|
157
156
|
walletClient,
|
|
@@ -159,7 +158,7 @@ export async function attemptUserDepositTx({
|
|
|
159
158
|
account,
|
|
160
159
|
trailsClient,
|
|
161
160
|
feeOptions: feeOptions,
|
|
162
|
-
|
|
161
|
+
selectedFeeOption,
|
|
163
162
|
abortSignal,
|
|
164
163
|
checkoutOnHandlers,
|
|
165
164
|
intentId,
|
|
@@ -182,7 +181,7 @@ export async function attemptUserDepositTx({
|
|
|
182
181
|
if (!depositUserTxnReceipt && !doGasless) {
|
|
183
182
|
depositUserTxnReceipt = await attemptStandardDeposit({
|
|
184
183
|
originTokenAddress,
|
|
185
|
-
|
|
184
|
+
depositAmount,
|
|
186
185
|
originIntentAddress,
|
|
187
186
|
onOriginSend,
|
|
188
187
|
publicClient,
|