0xtrails 0.4.3 → 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-C9CA3tIi.js → ccip-Dw5AN7oU.js} +27 -27
- package/dist/cctp.d.ts +0 -149
- package/dist/cctp.d.ts.map +1 -1
- package/dist/chains.d.ts +31 -4
- package/dist/chains.d.ts.map +1 -1
- package/dist/config.d.ts +28 -52
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +1 -7
- 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-CNB57v0n.js → index-BtVUTbEZ.js} +32255 -40547
- package/dist/index.d.ts +13 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +320 -944
- package/dist/indexerClient.d.ts +9 -6
- package/dist/indexerClient.d.ts.map +1 -1
- package/dist/intents.d.ts +0 -18
- 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/sequenceWallet.d.ts +1 -1
- package/dist/sequenceWallet.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/trailsClient.d.ts +3 -3
- package/dist/trailsClient.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 +6 -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 +7 -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 +6 -18
- 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/ConfigDisplay.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/SlippageToleranceSettings.d.ts +1 -0
- package/dist/widget/components/SlippageToleranceSettings.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/components/WalletConnect.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 +6 -11
- 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.d.ts +1 -0
- package/dist/widget/index.d.ts.map +1 -1
- package/dist/widget/index.js +4 -2
- package/dist/widget/providers/TrailsProvider.d.ts +29 -0
- package/dist/widget/providers/TrailsProvider.d.ts.map +1 -0
- package/dist/widget/widget.d.ts +14 -3
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +9 -8
- package/src/analytics.ts +53 -21
- package/src/cctp.ts +0 -1016
- package/src/chains.ts +155 -68
- package/src/config.ts +51 -207
- package/src/constants.ts +1 -13
- 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 +18 -40
- package/src/indexerClient.ts +39 -48
- package/src/intents.ts +51 -226
- package/src/mutations.ts +3 -2
- package/src/paymasterSend.ts +2 -5
- package/src/prepareSend.ts +21 -14
- package/src/sendUserOp.ts +3 -64
- package/src/sequenceWallet.ts +1 -2
- package/src/tokenBalances.ts +2 -1
- package/src/tokens.ts +62 -133
- package/src/trailsClient.ts +17 -12
- 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 +179 -381
- 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 +7 -27
- package/src/transactionIntent/utils/index.ts +0 -1
- package/src/transactions.ts +19 -118
- package/src/umd.tsx +1 -3
- package/src/utils.ts +28 -8
- package/src/walletUtils.ts +42 -0
- package/src/wallets.ts +365 -208
- package/src/widget/compiled.css +1 -1
- package/src/widget/components/AccountIntentTransactionHistory.tsx +78 -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 +19 -59
- 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/SlippageToleranceSettings.tsx +63 -14
- package/src/widget/components/Toast.tsx +10 -0
- package/src/widget/components/TokenImage.tsx +56 -13
- package/src/widget/components/WalletConnect.tsx +37 -99
- 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 +790 -412
- package/src/widget/hooks/useIsConnectedWalletSmartContract.ts +43 -0
- package/src/widget/hooks/useIsSequenceWallet.ts +17 -0
- package/src/widget/hooks/useQuote.ts +27 -34
- package/src/widget/hooks/useRecentTokens.ts +2 -1
- package/src/widget/hooks/useSelectedFeeOption.tsx +257 -0
- package/src/widget/hooks/useSendForm.ts +175 -46
- package/src/widget/hooks/useTokenList.ts +15 -2
- package/src/widget/index.tsx +8 -0
- package/src/widget/providers/TrailsProvider.tsx +123 -0
- package/src/widget/widget.tsx +165 -143
- 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/trails.d.ts +0 -110
- package/dist/trails.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 -66
- package/src/preconditions.ts +0 -47
- package/src/trails.ts +0 -1303
- 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/transactions.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { useQuery } from "@tanstack/react-query"
|
|
2
2
|
import { getChainInfo } from "./chains.js"
|
|
3
|
-
import { getSequenceProjectAccessKey } from "./config.js"
|
|
4
|
-
import { getTrailsClient } from "./trailsClient.js"
|
|
5
3
|
import type { GuestModuleEvent, TrailsTokenSweeperEvent } from "./decoders.js"
|
|
6
4
|
import { logger } from "./logger.js"
|
|
7
|
-
import { bigintReplacer } from "./utils.js"
|
|
8
5
|
import { getExplorerUrl } from "./explorer.js"
|
|
9
|
-
import {
|
|
6
|
+
import { JsonEncode } from "@0xsequence/trails-api"
|
|
10
7
|
import { getChainIndexerUrl } from "./indexerClient.js"
|
|
11
8
|
import { abortControllerRegistry } from "./abortController.js"
|
|
9
|
+
import { useTrails } from "./widget/providers/TrailsProvider.js"
|
|
12
10
|
|
|
13
11
|
export type TransactionStateStatus =
|
|
14
12
|
| "pending"
|
|
@@ -161,11 +159,14 @@ export async function getAccountTransactionHistory({
|
|
|
161
159
|
page = 1,
|
|
162
160
|
includeMetadata = true,
|
|
163
161
|
abortSignal,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
162
|
+
apiKey,
|
|
163
|
+
indexerUrl,
|
|
164
|
+
}: GetAccountTransactionHistoryParams & {
|
|
165
|
+
apiKey: string
|
|
166
|
+
indexerUrl: string
|
|
167
|
+
}): Promise<TransactionHistoryResponse> {
|
|
168
|
+
if (!apiKey) {
|
|
169
|
+
throw new Error("Trails api key is required")
|
|
169
170
|
}
|
|
170
171
|
|
|
171
172
|
// Create a unique ID for this operation
|
|
@@ -187,7 +188,7 @@ export async function getAccountTransactionHistory({
|
|
|
187
188
|
}
|
|
188
189
|
|
|
189
190
|
// Get the chain-specific indexer URL
|
|
190
|
-
const chainIndexerUrl = getChainIndexerUrl(chainId)
|
|
191
|
+
const chainIndexerUrl = getChainIndexerUrl(chainId, indexerUrl)
|
|
191
192
|
if (!chainIndexerUrl) {
|
|
192
193
|
throw new Error(`Unsupported chain ID: ${chainId}`)
|
|
193
194
|
}
|
|
@@ -217,9 +218,9 @@ export async function getAccountTransactionHistory({
|
|
|
217
218
|
method: "POST",
|
|
218
219
|
headers: {
|
|
219
220
|
"Content-Type": "application/json",
|
|
220
|
-
"X-Access-Key":
|
|
221
|
+
"X-Access-Key": apiKey,
|
|
221
222
|
},
|
|
222
|
-
body:
|
|
223
|
+
body: JsonEncode(requestBody),
|
|
223
224
|
signal: abortSignal || operationAbortController.signal,
|
|
224
225
|
})
|
|
225
226
|
|
|
@@ -275,6 +276,9 @@ export type IntentTransaction = {
|
|
|
275
276
|
destinationTokenAmount?: string
|
|
276
277
|
destinationToAddress?: string
|
|
277
278
|
createdAt?: string
|
|
279
|
+
// Transaction hashes from API response
|
|
280
|
+
originTransactionHash?: string // Transaction hash from API
|
|
281
|
+
destinationTransactionHash?: string // Transaction hash from API
|
|
278
282
|
// Enriched token information
|
|
279
283
|
originToken?: {
|
|
280
284
|
symbol: string
|
|
@@ -310,66 +314,6 @@ export type IntentTransactionHistoryResponse = {
|
|
|
310
314
|
transactions: IntentTransaction[]
|
|
311
315
|
}
|
|
312
316
|
|
|
313
|
-
export type GetIntentTransactionHistoryParams = {
|
|
314
|
-
accountAddress: string
|
|
315
|
-
pageSize?: number
|
|
316
|
-
page?: number
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
export async function getIntentTransactionHistory({
|
|
320
|
-
accountAddress: _accountAddress,
|
|
321
|
-
pageSize = 10,
|
|
322
|
-
page = 1,
|
|
323
|
-
}: GetIntentTransactionHistoryParams): Promise<IntentTransactionHistoryResponse> {
|
|
324
|
-
const accessKey = getSequenceProjectAccessKey()
|
|
325
|
-
|
|
326
|
-
if (!accessKey) {
|
|
327
|
-
throw new Error("Sequence project access key is required")
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
try {
|
|
331
|
-
const trailsClient = getTrailsClient()
|
|
332
|
-
|
|
333
|
-
// Use the hybrid client's getIntentTransactionHistory method which tries Trails API first, then Sequence API
|
|
334
|
-
const result = await trailsClient.getIntentTransactionHistory({
|
|
335
|
-
page: {
|
|
336
|
-
pageSize,
|
|
337
|
-
sort: [
|
|
338
|
-
{
|
|
339
|
-
column: "created_at",
|
|
340
|
-
order: SortOrder.DESC,
|
|
341
|
-
},
|
|
342
|
-
],
|
|
343
|
-
},
|
|
344
|
-
})
|
|
345
|
-
|
|
346
|
-
// Note: The new API has a different IntentTransaction structure.
|
|
347
|
-
// We need to map the API response to our local type structure.
|
|
348
|
-
// For now, return an empty result as the API structure has changed significantly.
|
|
349
|
-
// TODO: Implement proper mapping from new API IntentTransaction to SDK IntentTransaction
|
|
350
|
-
return {
|
|
351
|
-
page: result.nextPage
|
|
352
|
-
? {
|
|
353
|
-
page,
|
|
354
|
-
pageSize,
|
|
355
|
-
more: true,
|
|
356
|
-
}
|
|
357
|
-
: {
|
|
358
|
-
page,
|
|
359
|
-
pageSize,
|
|
360
|
-
more: false,
|
|
361
|
-
},
|
|
362
|
-
transactions: [], // TODO: Map result.transactions to SDK IntentTransaction format
|
|
363
|
-
}
|
|
364
|
-
} catch (error) {
|
|
365
|
-
logger.console.error(
|
|
366
|
-
"[trails-sdk] Error fetching intent transaction history:",
|
|
367
|
-
error,
|
|
368
|
-
)
|
|
369
|
-
throw error
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
317
|
export type UseAccountTransactionHistoryParams = {
|
|
374
318
|
chainId?: number | null
|
|
375
319
|
accountAddress?: string | null
|
|
@@ -393,6 +337,7 @@ export function useAccountTransactionHistory({
|
|
|
393
337
|
includeMetadata = true,
|
|
394
338
|
abortSignal,
|
|
395
339
|
}: UseAccountTransactionHistoryParams): UseAccountTransactionHistoryReturn {
|
|
340
|
+
const { trailsApiKey, sequenceIndexerUrl } = useTrails()
|
|
396
341
|
const { data, isLoading, error } = useQuery({
|
|
397
342
|
queryKey: [
|
|
398
343
|
"accountTransactionHistory",
|
|
@@ -417,6 +362,8 @@ export function useAccountTransactionHistory({
|
|
|
417
362
|
page,
|
|
418
363
|
includeMetadata,
|
|
419
364
|
abortSignal: effectiveSignal,
|
|
365
|
+
apiKey: trailsApiKey || "",
|
|
366
|
+
indexerUrl: sequenceIndexerUrl!,
|
|
420
367
|
})
|
|
421
368
|
},
|
|
422
369
|
enabled: Boolean(chainId && accountAddress),
|
|
@@ -434,49 +381,3 @@ export function useAccountTransactionHistory({
|
|
|
434
381
|
error: error as Error | null,
|
|
435
382
|
}
|
|
436
383
|
}
|
|
437
|
-
|
|
438
|
-
export type UseIntentTransactionHistoryParams = {
|
|
439
|
-
accountAddress?: string | null
|
|
440
|
-
pageSize?: number
|
|
441
|
-
page?: number
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
export type UseIntentTransactionHistoryReturn = {
|
|
445
|
-
data: IntentTransactionHistoryResponse | undefined
|
|
446
|
-
isLoading: boolean
|
|
447
|
-
error: Error | null
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
export function useIntentTransactionHistory({
|
|
451
|
-
accountAddress,
|
|
452
|
-
pageSize = 10,
|
|
453
|
-
page = 1,
|
|
454
|
-
}: UseIntentTransactionHistoryParams): UseIntentTransactionHistoryReturn {
|
|
455
|
-
const { data, isLoading, error } = useQuery({
|
|
456
|
-
queryKey: ["intentTransactionHistory", accountAddress, pageSize, page],
|
|
457
|
-
queryFn: async () => {
|
|
458
|
-
if (!accountAddress) {
|
|
459
|
-
return undefined
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
return await getIntentTransactionHistory({
|
|
463
|
-
accountAddress,
|
|
464
|
-
pageSize,
|
|
465
|
-
page,
|
|
466
|
-
})
|
|
467
|
-
},
|
|
468
|
-
enabled: Boolean(accountAddress),
|
|
469
|
-
staleTime: 30 * 1000, // Consider data fresh for 30 seconds
|
|
470
|
-
refetchOnWindowFocus: false,
|
|
471
|
-
refetchOnMount: false,
|
|
472
|
-
refetchInterval: false,
|
|
473
|
-
retry: 2,
|
|
474
|
-
refetchOnReconnect: true,
|
|
475
|
-
})
|
|
476
|
-
|
|
477
|
-
return {
|
|
478
|
-
data,
|
|
479
|
-
isLoading,
|
|
480
|
-
error: error as Error | null,
|
|
481
|
-
}
|
|
482
|
-
}
|
package/src/umd.tsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from "react"
|
|
2
2
|
import { createRoot } from "react-dom/client"
|
|
3
|
-
import type { RelayerEnv } from "./relayer.js"
|
|
4
3
|
import type { Theme } from "./theme.js"
|
|
5
4
|
import { TrailsWidget } from "./widget/widget.js"
|
|
6
5
|
|
|
@@ -8,10 +7,9 @@ interface TrailsGlobal {
|
|
|
8
7
|
render: (
|
|
9
8
|
element: HTMLElement,
|
|
10
9
|
options: {
|
|
11
|
-
|
|
10
|
+
apiKey: string
|
|
12
11
|
sequenceIndexerUrl?: string
|
|
13
12
|
trailsApiUrl?: string
|
|
14
|
-
sequenceEnv?: RelayerEnv
|
|
15
13
|
toAddress?: string | null
|
|
16
14
|
toAmount?: string | null
|
|
17
15
|
toChainId?: number | string | null
|
package/src/utils.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ethAddress, zeroAddress } from "viem"
|
|
2
|
+
|
|
1
3
|
export async function requestWithTimeout<T>(
|
|
2
4
|
client: { request: (...args: any[]) => Promise<T> },
|
|
3
5
|
args: Parameters<typeof client.request>,
|
|
@@ -11,10 +13,6 @@ export async function requestWithTimeout<T>(
|
|
|
11
13
|
])
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
export function bigintToString(n: bigint): string {
|
|
15
|
-
return n.toString()
|
|
16
|
-
}
|
|
17
|
-
|
|
18
16
|
/**
|
|
19
17
|
* Formats completion time in seconds to human-readable format
|
|
20
18
|
* @param seconds - Time in seconds
|
|
@@ -69,10 +67,6 @@ export function getTimeAgo(timestamp?: number): string {
|
|
|
69
67
|
return `Sent ${diffInDays} days ago`
|
|
70
68
|
}
|
|
71
69
|
|
|
72
|
-
export function bigintReplacer(_key: string, value: any) {
|
|
73
|
-
return typeof value === "bigint" ? value.toString() : value
|
|
74
|
-
}
|
|
75
|
-
|
|
76
70
|
/**
|
|
77
71
|
* Truncates an Ethereum address to show first 6 and last 4 characters
|
|
78
72
|
* @param address - The full Ethereum address
|
|
@@ -86,3 +80,29 @@ export function truncateAddress(
|
|
|
86
80
|
if (!address) return ""
|
|
87
81
|
return `${address.slice(0, start)}…${address.slice(-end)}`
|
|
88
82
|
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Checks if an address represents a native token (ETH or zero address)
|
|
86
|
+
* @param address - The token address to check
|
|
87
|
+
* @param caseInsensitive - Whether to perform case-insensitive comparison (default: true)
|
|
88
|
+
* @returns True if the address is a native token address
|
|
89
|
+
*/
|
|
90
|
+
export function isNativeToken(
|
|
91
|
+
address?: string | null,
|
|
92
|
+
caseInsensitive = true,
|
|
93
|
+
): boolean {
|
|
94
|
+
if (!address) {
|
|
95
|
+
return false
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const addresses = caseInsensitive
|
|
99
|
+
? [zeroAddress.toLowerCase(), ethAddress.toLowerCase()]
|
|
100
|
+
: [zeroAddress, ethAddress]
|
|
101
|
+
|
|
102
|
+
const normalizedAddress = caseInsensitive ? address.toLowerCase() : address
|
|
103
|
+
|
|
104
|
+
return addresses.includes(normalizedAddress)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export const normalizeAddress = (address?: string | null): string =>
|
|
108
|
+
(address ?? "").toLowerCase()
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Connector } from "wagmi"
|
|
2
|
+
import { getIsContract } from "./contractUtils.js"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a wallet connector is a Sequence wallet.
|
|
6
|
+
* @param connector - The wagmi connector to check
|
|
7
|
+
* @returns true if the connector is a Sequence wallet, false otherwise
|
|
8
|
+
*/
|
|
9
|
+
export function isSequenceWallet(connector: Connector | undefined): boolean {
|
|
10
|
+
if (!connector) return false
|
|
11
|
+
const connectorName = connector.name?.toLowerCase() || ""
|
|
12
|
+
const connectorId = connector.id?.toLowerCase() || ""
|
|
13
|
+
return connectorName.includes("sequence") || connectorId.includes("sequence")
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Checks if a wallet ID indicates a Sequence wallet.
|
|
18
|
+
* @param walletId - The wallet ID to check
|
|
19
|
+
* @returns true if the wallet ID indicates a Sequence wallet, false otherwise
|
|
20
|
+
*/
|
|
21
|
+
export function isSequenceWalletById(walletId: string | undefined): boolean {
|
|
22
|
+
if (!walletId) return false
|
|
23
|
+
return walletId.toLowerCase().includes("sequence")
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Checks if an address is a smart contract wallet.
|
|
28
|
+
* @param address - The wallet address to check
|
|
29
|
+
* @param chainId - The chain ID to check the wallet on
|
|
30
|
+
* @returns Promise that resolves to true if the address is a smart contract, false otherwise
|
|
31
|
+
*/
|
|
32
|
+
export async function isSmartContractWallet(
|
|
33
|
+
address: string,
|
|
34
|
+
chainId: number,
|
|
35
|
+
): Promise<boolean> {
|
|
36
|
+
try {
|
|
37
|
+
return await getIsContract(address as `0x${string}`, chainId)
|
|
38
|
+
} catch {
|
|
39
|
+
// Return false on error to be safe
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
}
|