0xtrails 0.4.0 → 0.4.2
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/aave.d.ts.map +1 -1
- package/dist/{ccip-BpQGQiWq.js → ccip-Dl3umoGg.js} +5 -5
- package/dist/{index-DsJM5F-V.js → index-sMS_ge1R.js} +13958 -13860
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +596 -565
- package/dist/intents.d.ts +1 -1
- package/dist/intents.d.ts.map +1 -1
- package/dist/morpho.d.ts.map +1 -1
- package/dist/mutations.d.ts +2 -2
- package/dist/mutations.d.ts.map +1 -1
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/trails.d.ts +9 -10
- package/dist/trails.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts +3 -2
- package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts +1 -1
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/standardDeposit.d.ts +3 -2
- package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/crossChain.d.ts +1 -1
- package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts +3 -2
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -1
- package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -1
- package/dist/transactionIntent/types.d.ts +1 -1
- package/dist/transactionIntent/types.d.ts.map +1 -1
- package/dist/widget/components/FeeOptions.d.ts +2 -1
- package/dist/widget/components/FeeOptions.d.ts.map +1 -1
- package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
- package/dist/widget/hooks/useQuote.d.ts +32 -1
- package/dist/widget/hooks/useQuote.d.ts.map +1 -1
- package/dist/widget/hooks/useSendForm.d.ts +1 -1
- package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
- package/dist/widget/index.js +1 -1
- package/package.json +7 -7
- package/src/aave.ts +1 -0
- package/src/index.ts +1 -1
- package/src/indexerClient.ts +1 -1
- package/src/intents.ts +2 -2
- package/src/morpho.ts +3 -2
- package/src/mutations.ts +53 -5
- package/src/prepareSend.ts +12 -1
- package/src/trails.ts +57 -65
- package/src/trailsClient.ts +1 -1
- package/src/transactionIntent/deposits/depositOrchestrator.ts +4 -1
- package/src/transactionIntent/deposits/gaslessDeposit.ts +1 -1
- package/src/transactionIntent/deposits/standardDeposit.ts +124 -3
- package/src/transactionIntent/handlers/crossChain.ts +14 -9
- package/src/transactionIntent/handlers/sameChainSameToken.ts +32 -12
- package/src/transactionIntent/quote/quoteHelpers.ts +4 -11
- package/src/transactionIntent/types.ts +1 -1
- package/src/widget/components/FeeOptions.tsx +2 -1
- package/src/widget/components/PoolDeposit.tsx +68 -4
- package/src/widget/hooks/useDebugScreens.ts +11 -11
- package/src/widget/hooks/useQuote.ts +54 -5
- package/src/widget/hooks/useSendForm.ts +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useQuery } from "@tanstack/react-query"
|
|
2
|
-
import { useRef } from "react"
|
|
2
|
+
import { useRef, useMemo } from "react"
|
|
3
3
|
import type { TransactionReceipt } from "viem"
|
|
4
4
|
import { zeroAddress } from "viem"
|
|
5
5
|
import { useIndexerGatewayClient } from "../../indexerClient.js"
|
|
@@ -13,7 +13,12 @@ import { prepareSend } from "../../prepareSend.js"
|
|
|
13
13
|
import { abortControllerRegistry } from "../../abortController.js"
|
|
14
14
|
import { TradeType } from "../../prepareSend.js"
|
|
15
15
|
import { getChainInfo } from "../../chains.js"
|
|
16
|
-
import type {
|
|
16
|
+
import type { TrailsClientConfig } from "../../trailsClient.js"
|
|
17
|
+
import type { IndexerGatewayConfig } from "../../indexerClient.js"
|
|
18
|
+
import type {
|
|
19
|
+
MetaTxnReceipt,
|
|
20
|
+
PrepareSendOptions,
|
|
21
|
+
} from "../../transactionIntent/types.js"
|
|
17
22
|
import type { Chain } from "../../chains.js"
|
|
18
23
|
import type { SupportedToken } from "../../tokens.js"
|
|
19
24
|
import type { TransactionState } from "../../transactions.js"
|
|
@@ -21,6 +26,7 @@ import type { PrepareSendFees } from "../../prepareSend.js"
|
|
|
21
26
|
import type { SequenceEnv } from "../../config.js"
|
|
22
27
|
import { getTokenPrice } from "../../prices.js"
|
|
23
28
|
import { useCommitIntent, useExecuteIntent } from "../../mutations.js"
|
|
29
|
+
import type { CheckoutOnHandlers } from "./useCheckout.js"
|
|
24
30
|
|
|
25
31
|
export type UseQuoteProps = {
|
|
26
32
|
walletClient?: any // TODO: fix this, has to do with viem/wagmi versions
|
|
@@ -35,12 +41,42 @@ export type UseQuoteProps = {
|
|
|
35
41
|
slippageTolerance?: string | number | null
|
|
36
42
|
onStatusUpdate?: ((transactionStates: TransactionState[]) => void) | null
|
|
37
43
|
quoteProvider?: string | null
|
|
44
|
+
/**
|
|
45
|
+
* Optional checkout event handlers for tracking the states of a Trails transaction.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* checkoutOnHandlers: {
|
|
50
|
+
* triggerCheckoutStart: () => {
|
|
51
|
+
* console.log('Checkout started')
|
|
52
|
+
* },
|
|
53
|
+
* triggerCheckoutQuote: (quote) => {
|
|
54
|
+
* console.log('Quote received:', quote)
|
|
55
|
+
* },
|
|
56
|
+
* triggerCheckoutComplete: (status, accountAddress) => {
|
|
57
|
+
* console.log('Checkout completed:', status, accountAddress)
|
|
58
|
+
* }
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* Available handlers:
|
|
63
|
+
* - `triggerCheckoutStart`
|
|
64
|
+
* - `triggerCheckoutQuote`
|
|
65
|
+
* - `triggerCheckoutSignatureRequest`
|
|
66
|
+
* - `triggerCheckoutSignatureConfirmed`
|
|
67
|
+
* - `triggerCheckoutSignatureRejected`
|
|
68
|
+
* - `triggerCheckoutComplete`
|
|
69
|
+
* - `triggerCheckoutError`
|
|
70
|
+
* - `triggerCheckoutStatusUpdate`
|
|
71
|
+
*/
|
|
72
|
+
checkoutOnHandlers?: Partial<CheckoutOnHandlers>
|
|
38
73
|
paymasterUrl?: string
|
|
39
74
|
selectedFeeToken?: {
|
|
40
75
|
tokenAddress: string
|
|
41
76
|
tokenSymbol?: string
|
|
42
77
|
} | null
|
|
43
78
|
abortSignal?: AbortSignal
|
|
79
|
+
apiKey?: string | null
|
|
44
80
|
}
|
|
45
81
|
|
|
46
82
|
export type SwapReturn = {
|
|
@@ -111,11 +147,13 @@ export function useQuote({
|
|
|
111
147
|
toCalldata,
|
|
112
148
|
slippageTolerance,
|
|
113
149
|
onStatusUpdate,
|
|
150
|
+
checkoutOnHandlers,
|
|
114
151
|
quoteProvider,
|
|
115
152
|
paymasterUrl,
|
|
116
153
|
selectedFeeToken,
|
|
117
154
|
nodeGatewayEnv,
|
|
118
155
|
abortSignal: externalAbortSignal,
|
|
156
|
+
apiKey,
|
|
119
157
|
}: Partial<
|
|
120
158
|
UseQuoteProps & { nodeGatewayEnv?: SequenceEnv }
|
|
121
159
|
> = {}): UseQuoteReturn {
|
|
@@ -147,8 +185,17 @@ export function useQuote({
|
|
|
147
185
|
})()
|
|
148
186
|
: abortControllerRef.current.signal
|
|
149
187
|
|
|
150
|
-
const
|
|
151
|
-
|
|
188
|
+
const trailsClientConfig = useMemo<TrailsClientConfig>(() => {
|
|
189
|
+
return apiKey ? { apiKey } : {}
|
|
190
|
+
}, [apiKey])
|
|
191
|
+
const indexerGatewayClientConfig = useMemo<IndexerGatewayConfig>(() => {
|
|
192
|
+
return apiKey ? { projectAccessKey: apiKey } : {}
|
|
193
|
+
}, [apiKey])
|
|
194
|
+
|
|
195
|
+
const trailsClient = useTrailsClient(trailsClientConfig)
|
|
196
|
+
const indexerGatewayClient = useIndexerGatewayClient(
|
|
197
|
+
indexerGatewayClientConfig,
|
|
198
|
+
)
|
|
152
199
|
|
|
153
200
|
const { supportedTokens } = useSupportedTokens()
|
|
154
201
|
|
|
@@ -169,6 +216,7 @@ export function useQuote({
|
|
|
169
216
|
tradeType,
|
|
170
217
|
slippageTolerance,
|
|
171
218
|
quoteProvider,
|
|
219
|
+
apiKey,
|
|
172
220
|
],
|
|
173
221
|
queryFn: async () => {
|
|
174
222
|
try {
|
|
@@ -311,7 +359,7 @@ export function useQuote({
|
|
|
311
359
|
const destinationTokenSymbol = destinationToken?.symbol ?? ""
|
|
312
360
|
const originTokenSymbol = originToken?.symbol ?? ""
|
|
313
361
|
|
|
314
|
-
const options = {
|
|
362
|
+
const options: PrepareSendOptions = {
|
|
315
363
|
account: walletClient.account!,
|
|
316
364
|
originTokenAddress: fromTokenAddress,
|
|
317
365
|
originChainId: fromChainId,
|
|
@@ -339,6 +387,7 @@ export function useQuote({
|
|
|
339
387
|
originNativeTokenPriceUsd: originNativeTokenPriceUsd,
|
|
340
388
|
commitIntentFn: commitIntentMutation.mutateAsync,
|
|
341
389
|
executeIntentFn: executeIntentMutation.mutateAsync,
|
|
390
|
+
checkoutOnHandlers,
|
|
342
391
|
}
|
|
343
392
|
|
|
344
393
|
logger.console.log("[trails-sdk] options", options)
|
|
@@ -163,7 +163,7 @@ export type UseSendReturn = {
|
|
|
163
163
|
destTokenPrices: TokenPrice[] | null
|
|
164
164
|
sourceTokenPrices: TokenPrice[] | null
|
|
165
165
|
selectedToken?: Token
|
|
166
|
-
selectedFeeToken: SelectedFeeToken |
|
|
166
|
+
selectedFeeToken: SelectedFeeToken | null
|
|
167
167
|
setIsChainDropdownOpen: (isOpen: boolean) => void
|
|
168
168
|
setIsTokenDropdownOpen: (isOpen: boolean) => void
|
|
169
169
|
toAmountFormatted: string
|
|
@@ -1336,7 +1336,7 @@ export function useSendForm({
|
|
|
1336
1336
|
destTokenPrices: destTokenPrices ?? null,
|
|
1337
1337
|
sourceTokenPrices: sourceTokenPrices ?? null,
|
|
1338
1338
|
selectedToken,
|
|
1339
|
-
selectedFeeToken: selectedFeeToken ??
|
|
1339
|
+
selectedFeeToken: selectedFeeToken ?? null,
|
|
1340
1340
|
setIsChainDropdownOpen,
|
|
1341
1341
|
setIsTokenDropdownOpen,
|
|
1342
1342
|
toAmountFormatted: quotedDestinationAmount,
|