0xtrails 0.4.2 → 0.5.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/{ccip-Dl3umoGg.js → ccip-DhEkQ6QC.js} +27 -27
- package/dist/cctpqueue.d.ts.map +1 -1
- package/dist/chains.d.ts +3 -1
- package/dist/chains.d.ts.map +1 -1
- package/dist/config.d.ts +17 -52
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +0 -6
- package/dist/constants.d.ts.map +1 -1
- package/dist/{index-sMS_ge1R.js → index-MhD2DA7_.js} +23613 -23893
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +319 -944
- package/dist/indexerClient.d.ts +9 -6
- package/dist/indexerClient.d.ts.map +1 -1
- package/dist/intents.d.ts +0 -1
- package/dist/intents.d.ts.map +1 -1
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/sequenceWallet.d.ts +1 -1
- package/dist/sequenceWallet.d.ts.map +1 -1
- package/dist/trailsClient.d.ts +3 -3
- package/dist/trailsClient.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/crossChain.d.ts +3 -1
- package/dist/transactionIntent/handlers/crossChain.d.ts.map +1 -1
- package/dist/transactionIntent/handlers/sameChainSameToken.d.ts.map +1 -1
- package/dist/transactionIntent/types.d.ts +1 -0
- package/dist/transactionIntent/types.d.ts.map +1 -1
- package/dist/transactions.d.ts +8 -2
- package/dist/transactions.d.ts.map +1 -1
- package/dist/wallets.d.ts.map +1 -1
- package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/components/ConfigDisplay.d.ts.map +1 -1
- package/dist/widget/components/FeeOptions.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/WalletConnect.d.ts.map +1 -1
- package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +1 -1
- package/dist/widget/hooks/useQuote.d.ts +2 -4
- package/dist/widget/hooks/useQuote.d.ts.map +1 -1
- package/dist/widget/hooks/useSendForm.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 +18 -0
- package/dist/widget/providers/TrailsProvider.d.ts.map +1 -0
- package/dist/widget/widget.d.ts +3 -3
- package/dist/widget/widget.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/analytics.ts +2 -2
- package/src/cctpqueue.ts +6 -3
- package/src/chains.ts +62 -29
- package/src/config.ts +36 -210
- package/src/constants.ts +0 -9
- package/src/index.ts +12 -35
- package/src/indexerClient.ts +39 -48
- package/src/intents.ts +0 -21
- package/src/prepareSend.ts +16 -2
- package/src/sequenceWallet.ts +1 -2
- package/src/trailsClient.ts +17 -12
- package/src/transactionIntent/deposits/gaslessDeposit.ts +88 -43
- package/src/transactionIntent/deposits/standardDeposit.ts +91 -53
- package/src/transactionIntent/handlers/crossChain.ts +88 -0
- package/src/transactionIntent/handlers/sameChainSameToken.ts +22 -0
- package/src/transactionIntent/types.ts +1 -0
- package/src/transactions.ts +122 -24
- package/src/wallets.ts +5 -6
- package/src/widget/components/AccountIntentTransactionHistory.tsx +5 -0
- package/src/widget/components/ConfigDisplay.tsx +19 -59
- package/src/widget/components/FeeOptions.tsx +1 -1
- package/src/widget/components/SlippageToleranceSettings.tsx +63 -14
- package/src/widget/components/WalletConnect.tsx +37 -99
- package/src/widget/hooks/useIntentTransactionHistory.ts +9 -1
- package/src/widget/hooks/useQuote.ts +11 -17
- package/src/widget/hooks/useSendForm.ts +4 -0
- package/src/widget/index.tsx +8 -0
- package/src/widget/providers/TrailsProvider.tsx +95 -0
- package/src/widget/widget.tsx +49 -98
- package/dist/trails.d.ts +0 -110
- package/dist/trails.d.ts.map +0 -1
- package/src/trails.ts +0 -1303
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import type React from "react"
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
globalConfig,
|
|
5
|
-
getSequenceEnv,
|
|
6
|
-
getTrailsApiUrl,
|
|
7
|
-
getSequenceIndexerUrl,
|
|
8
|
-
getSequenceProjectAccessKey,
|
|
9
|
-
getWalletConnectProjectId,
|
|
10
|
-
getSlippageTolerance,
|
|
11
|
-
getDebug,
|
|
12
|
-
} from "../../config.js"
|
|
2
|
+
import { useMemo } from "react"
|
|
3
|
+
import { useTrails } from "../providers/TrailsProvider.js"
|
|
13
4
|
import { getChainInfo } from "../../chains.js"
|
|
14
5
|
import { mainnet } from "viem/chains"
|
|
15
6
|
import { logger } from "../../logger.js"
|
|
16
7
|
import { useWidgetProps } from "../hooks/useWidgetProps.js"
|
|
17
8
|
import { useTargetAmount } from "../hooks/useTargetAmount.js"
|
|
9
|
+
import { getQueryParam } from "../../queryParams.js"
|
|
18
10
|
|
|
19
11
|
interface ConfigDisplayProps {
|
|
20
12
|
className?: string
|
|
@@ -31,45 +23,14 @@ export const ConfigDisplay: React.FC<ConfigDisplayProps> = ({
|
|
|
31
23
|
toCalldata,
|
|
32
24
|
} = useWidgetProps()
|
|
33
25
|
const { targetAmountUsdFormatted } = useTargetAmount()
|
|
34
|
-
const
|
|
35
|
-
const [trailsApiUrl, setTrailsApiUrl] = useState(getTrailsApiUrl())
|
|
36
|
-
const [sequenceIndexerUrl, setSequenceIndexerUrl] = useState(
|
|
37
|
-
getSequenceIndexerUrl(),
|
|
38
|
-
)
|
|
39
|
-
const [projectAccessKey, setProjectAccessKey] = useState(
|
|
40
|
-
getSequenceProjectAccessKey(),
|
|
41
|
-
)
|
|
42
|
-
const [walletConnectProjectId, setWalletConnectProjectId] = useState(
|
|
43
|
-
getWalletConnectProjectId(),
|
|
44
|
-
)
|
|
45
|
-
const [slippageTolerance, setSlippageTolerance] = useState(
|
|
46
|
-
getSlippageTolerance(),
|
|
47
|
-
)
|
|
48
|
-
const [debugMode, setDebugMode] = useState(getDebug())
|
|
49
|
-
const [rpcNodeUrl, setRpcNodeUrl] = useState(() => {
|
|
50
|
-
const mainnetChain = getChainInfo(mainnet.id)
|
|
51
|
-
return mainnetChain?.rpcUrls?.default?.http?.[0] || "N/A"
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
// Update configuration values in real time
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
const updateConfig = () => {
|
|
57
|
-
logger.console.log("[trails-sdk] globalConfig", globalConfig)
|
|
58
|
-
setSequenceEnv(getSequenceEnv())
|
|
59
|
-
setTrailsApiUrl(getTrailsApiUrl())
|
|
60
|
-
setSequenceIndexerUrl(getSequenceIndexerUrl())
|
|
61
|
-
setProjectAccessKey(getSequenceProjectAccessKey())
|
|
62
|
-
setWalletConnectProjectId(getWalletConnectProjectId())
|
|
63
|
-
setSlippageTolerance(getSlippageTolerance())
|
|
64
|
-
setDebugMode(getDebug())
|
|
26
|
+
const config = useTrails()
|
|
65
27
|
|
|
66
|
-
|
|
67
|
-
const mainnetChain = getChainInfo(mainnet.id)
|
|
68
|
-
setRpcNodeUrl(mainnetChain?.rpcUrls?.default?.http?.[0] || "N/A")
|
|
69
|
-
}
|
|
28
|
+
logger.console.log("[trails-sdk] Config from context:", config)
|
|
70
29
|
|
|
71
|
-
|
|
72
|
-
|
|
30
|
+
const debugMode = config.debug || getQueryParam("debug") === "true"
|
|
31
|
+
const rpcNodeUrl = useMemo(() => {
|
|
32
|
+
const mainnetChain = getChainInfo(mainnet.id)
|
|
33
|
+
return mainnetChain?.rpcUrls?.default?.http?.[0] || "N/A"
|
|
73
34
|
}, [])
|
|
74
35
|
|
|
75
36
|
const truncateString = (str: string, maxLength: number = 30) => {
|
|
@@ -82,16 +43,15 @@ export const ConfigDisplay: React.FC<ConfigDisplayProps> = ({
|
|
|
82
43
|
value: string
|
|
83
44
|
display: string
|
|
84
45
|
}>[] = [
|
|
85
|
-
{ label: "Sequence ENV", value: sequenceEnv, display: sequenceEnv },
|
|
86
46
|
{
|
|
87
47
|
label: "API URL",
|
|
88
|
-
value: trailsApiUrl,
|
|
89
|
-
display: truncateString(trailsApiUrl),
|
|
48
|
+
value: config.trailsApiUrl,
|
|
49
|
+
display: truncateString(config.trailsApiUrl || "N/A"),
|
|
90
50
|
},
|
|
91
51
|
{
|
|
92
52
|
label: "Indexer URL",
|
|
93
|
-
value: sequenceIndexerUrl,
|
|
94
|
-
display: truncateString(sequenceIndexerUrl),
|
|
53
|
+
value: config.sequenceIndexerUrl,
|
|
54
|
+
display: truncateString(config.sequenceIndexerUrl! || "N/A"),
|
|
95
55
|
},
|
|
96
56
|
{
|
|
97
57
|
label: "RPC Node URL (1)",
|
|
@@ -99,16 +59,16 @@ export const ConfigDisplay: React.FC<ConfigDisplayProps> = ({
|
|
|
99
59
|
display: truncateString(rpcNodeUrl),
|
|
100
60
|
},
|
|
101
61
|
{
|
|
102
|
-
label: "
|
|
103
|
-
value:
|
|
104
|
-
display: truncateString(
|
|
62
|
+
label: "Trails API Key",
|
|
63
|
+
value: config.trailsApiKey,
|
|
64
|
+
display: truncateString(config.trailsApiKey),
|
|
105
65
|
},
|
|
106
66
|
{
|
|
107
67
|
label: "WalletConnect Project ID",
|
|
108
|
-
value: truncateString(walletConnectProjectId),
|
|
109
|
-
display: truncateString(walletConnectProjectId),
|
|
68
|
+
value: truncateString(config.walletConnectProjectId! || "N/A"),
|
|
69
|
+
display: truncateString(config.walletConnectProjectId! || "N/A"),
|
|
110
70
|
},
|
|
111
|
-
{ label: "Slippage Tolerance", value: `${slippageTolerance}%` },
|
|
71
|
+
{ label: "Slippage Tolerance", value: `${config.slippageTolerance}%` },
|
|
112
72
|
{ label: "Debug Mode", value: debugMode ? "Enabled" : "Disabled" },
|
|
113
73
|
{ label: "Toast Notifications", value: toast ? "Enabled" : "Disabled" },
|
|
114
74
|
{
|
|
@@ -11,7 +11,7 @@ import { getTokenImageUrl } from "../../tokens.js"
|
|
|
11
11
|
import { TokenImage } from "./TokenImage.js"
|
|
12
12
|
import { ethAddress, zeroAddress } from "viem"
|
|
13
13
|
import type { FeeOption as APIFeeOption } from "../../widget/hooks/useSelectedFeeToken.js"
|
|
14
|
-
import { SelectedFeeToken } from "../../prepareSend.js"
|
|
14
|
+
import type { SelectedFeeToken } from "../../prepareSend.js"
|
|
15
15
|
|
|
16
16
|
const ZERO_ADDRESS = zeroAddress.toLowerCase()
|
|
17
17
|
const ETH_ADDRESS = ethAddress.toLowerCase()
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type React from "react"
|
|
2
2
|
import { useState, useEffect } from "react"
|
|
3
3
|
import { HelpCircle } from "lucide-react"
|
|
4
|
-
import {
|
|
4
|
+
import { useTrails } from "../providers/TrailsProvider.js"
|
|
5
5
|
|
|
6
6
|
// Convert decimal format to percentage for display
|
|
7
7
|
// Format: "0.05" (5%) -> "5"
|
|
@@ -17,6 +17,20 @@ const percentageToDecimal = (percentage: string): string => {
|
|
|
17
17
|
return (num / 100).toString()
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
// Local storage key for user's slippage preference
|
|
21
|
+
const SLIPPAGE_STORAGE_KEY = "trails-slippage-tolerance"
|
|
22
|
+
|
|
23
|
+
// Helper function to get current slippage tolerance (for use in SDK functions)
|
|
24
|
+
// Returns the user's stored preference or falls back to the provided default
|
|
25
|
+
export const getSlippageToleranceValue = (defaultValue: string): string => {
|
|
26
|
+
try {
|
|
27
|
+
const stored = localStorage.getItem(SLIPPAGE_STORAGE_KEY)
|
|
28
|
+
return stored || defaultValue
|
|
29
|
+
} catch (_error) {
|
|
30
|
+
return defaultValue
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
20
34
|
interface SlippageToleranceSettingsProps {
|
|
21
35
|
className?: string
|
|
22
36
|
}
|
|
@@ -24,14 +38,25 @@ interface SlippageToleranceSettingsProps {
|
|
|
24
38
|
export const SlippageToleranceSettings: React.FC<
|
|
25
39
|
SlippageToleranceSettingsProps
|
|
26
40
|
> = ({ className = "" }) => {
|
|
41
|
+
const config = useTrails()
|
|
27
42
|
const [displayValue, setDisplayValue] = useState("")
|
|
28
43
|
const [showTooltip, setShowTooltip] = useState(false)
|
|
29
44
|
|
|
30
|
-
// Initialize display value from
|
|
45
|
+
// Initialize display value from local storage or config
|
|
31
46
|
useEffect(() => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
47
|
+
try {
|
|
48
|
+
const stored = localStorage.getItem(SLIPPAGE_STORAGE_KEY)
|
|
49
|
+
if (stored) {
|
|
50
|
+
setDisplayValue(decimalToPercentage(stored))
|
|
51
|
+
} else {
|
|
52
|
+
// Default to config value
|
|
53
|
+
setDisplayValue(decimalToPercentage(String(config.slippageTolerance)))
|
|
54
|
+
}
|
|
55
|
+
} catch (_error) {
|
|
56
|
+
// Fallback to config if localStorage fails
|
|
57
|
+
setDisplayValue(decimalToPercentage(String(config.slippageTolerance)))
|
|
58
|
+
}
|
|
59
|
+
}, [config.slippageTolerance])
|
|
35
60
|
|
|
36
61
|
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
37
62
|
const value = e.target.value
|
|
@@ -49,9 +74,17 @@ export const SlippageToleranceSettings: React.FC<
|
|
|
49
74
|
|
|
50
75
|
const handleInputBlur = () => {
|
|
51
76
|
if (displayValue === "") {
|
|
52
|
-
// Reset to
|
|
53
|
-
|
|
54
|
-
|
|
77
|
+
// Reset to stored value or config default
|
|
78
|
+
try {
|
|
79
|
+
const stored = localStorage.getItem(SLIPPAGE_STORAGE_KEY)
|
|
80
|
+
if (stored) {
|
|
81
|
+
setDisplayValue(decimalToPercentage(stored))
|
|
82
|
+
} else {
|
|
83
|
+
setDisplayValue(decimalToPercentage(String(config.slippageTolerance)))
|
|
84
|
+
}
|
|
85
|
+
} catch (_error) {
|
|
86
|
+
setDisplayValue(decimalToPercentage(String(config.slippageTolerance)))
|
|
87
|
+
}
|
|
55
88
|
return
|
|
56
89
|
}
|
|
57
90
|
|
|
@@ -59,15 +92,27 @@ export const SlippageToleranceSettings: React.FC<
|
|
|
59
92
|
|
|
60
93
|
// Validate range (0.01% to 50%)
|
|
61
94
|
if (percentage < 0.01 || percentage > 50) {
|
|
62
|
-
// Reset to
|
|
63
|
-
|
|
64
|
-
|
|
95
|
+
// Reset to stored value or config default
|
|
96
|
+
try {
|
|
97
|
+
const stored = localStorage.getItem(SLIPPAGE_STORAGE_KEY)
|
|
98
|
+
if (stored) {
|
|
99
|
+
setDisplayValue(decimalToPercentage(stored))
|
|
100
|
+
} else {
|
|
101
|
+
setDisplayValue(decimalToPercentage(String(config.slippageTolerance)))
|
|
102
|
+
}
|
|
103
|
+
} catch (_error) {
|
|
104
|
+
setDisplayValue(decimalToPercentage(String(config.slippageTolerance)))
|
|
105
|
+
}
|
|
65
106
|
return
|
|
66
107
|
}
|
|
67
108
|
|
|
68
|
-
// Convert to decimal format and save
|
|
109
|
+
// Convert to decimal format and save to localStorage
|
|
69
110
|
const decimalValue = percentageToDecimal(displayValue)
|
|
70
|
-
|
|
111
|
+
try {
|
|
112
|
+
localStorage.setItem(SLIPPAGE_STORAGE_KEY, decimalValue)
|
|
113
|
+
} catch (error) {
|
|
114
|
+
console.warn("Failed to save slippage tolerance to localStorage:", error)
|
|
115
|
+
}
|
|
71
116
|
|
|
72
117
|
// Update display to show formatted value
|
|
73
118
|
setDisplayValue(percentage.toString())
|
|
@@ -83,7 +128,11 @@ export const SlippageToleranceSettings: React.FC<
|
|
|
83
128
|
const percentageStr = percentage.toString()
|
|
84
129
|
setDisplayValue(percentageStr)
|
|
85
130
|
const decimalValue = percentageToDecimal(percentageStr)
|
|
86
|
-
|
|
131
|
+
try {
|
|
132
|
+
localStorage.setItem(SLIPPAGE_STORAGE_KEY, decimalValue)
|
|
133
|
+
} catch (error) {
|
|
134
|
+
console.warn("Failed to save slippage tolerance to localStorage:", error)
|
|
135
|
+
}
|
|
87
136
|
}
|
|
88
137
|
|
|
89
138
|
return (
|
|
@@ -3,7 +3,7 @@ import { useAccount, useConnect, useDisconnect } from "wagmi"
|
|
|
3
3
|
import { walletConnect } from "wagmi/connectors"
|
|
4
4
|
import { QrCode } from "./QrCode.js"
|
|
5
5
|
import { TruncatedAddress } from "./TruncatedAddress.js"
|
|
6
|
-
import {
|
|
6
|
+
import { useTrails } from "../providers/TrailsProvider.js"
|
|
7
7
|
import { ScreenHeader } from "./ScreenHeader.js"
|
|
8
8
|
import { getWalletIcon, getWalletName } from "../../wallets.js"
|
|
9
9
|
import { logger } from "../../logger.js"
|
|
@@ -18,14 +18,14 @@ export interface WalletConnectProps {
|
|
|
18
18
|
|
|
19
19
|
// Local singleton to avoid multiple Core initializations from this screen
|
|
20
20
|
let wcConnectorSingleton: ReturnType<typeof walletConnect> | null = null
|
|
21
|
-
function getWalletConnectConnector(projectId
|
|
21
|
+
function getWalletConnectConnector(projectId: string) {
|
|
22
22
|
if (!wcConnectorSingleton) {
|
|
23
23
|
logger.console.log(
|
|
24
24
|
"[trails-sdk] [WalletConnect] Creating new connector with projectId:",
|
|
25
|
-
projectId
|
|
25
|
+
projectId,
|
|
26
26
|
)
|
|
27
27
|
wcConnectorSingleton = walletConnect({
|
|
28
|
-
projectId: projectId
|
|
28
|
+
projectId: projectId,
|
|
29
29
|
showQrModal: false,
|
|
30
30
|
})
|
|
31
31
|
}
|
|
@@ -35,16 +35,17 @@ function getWalletConnectConnector(projectId?: string) {
|
|
|
35
35
|
export const WalletConnectScreen: React.FC<WalletConnectProps> = ({
|
|
36
36
|
onBack,
|
|
37
37
|
onContinue,
|
|
38
|
-
projectId,
|
|
38
|
+
projectId: projectIdProp,
|
|
39
39
|
onReconnectPreviousWallet,
|
|
40
40
|
selectedWalletId,
|
|
41
41
|
}) => {
|
|
42
|
+
const config = useTrails()
|
|
43
|
+
const projectId = projectIdProp || config.walletConnectProjectId
|
|
42
44
|
const { connect, connectors, status } = useConnect() as any
|
|
43
45
|
const { disconnect } = useDisconnect()
|
|
44
46
|
const { isConnected, address, connector } = useAccount()
|
|
45
47
|
const [wcUri, setWcUri] = React.useState<string | null>(null)
|
|
46
48
|
const [showUri, setShowUri] = React.useState(false)
|
|
47
|
-
const [copied, setCopied] = React.useState(false)
|
|
48
49
|
const listenerRef = React.useRef<(() => void) | null>(null)
|
|
49
50
|
const debounceTimeoutRef = useRef<NodeJS.Timeout | null>(null)
|
|
50
51
|
|
|
@@ -58,21 +59,6 @@ export const WalletConnectScreen: React.FC<WalletConnectProps> = ({
|
|
|
58
59
|
setWcUri(uri)
|
|
59
60
|
}, 500) // 300ms debounce delay
|
|
60
61
|
}, [])
|
|
61
|
-
|
|
62
|
-
// Copy URI to clipboard
|
|
63
|
-
const handleCopyUri = useCallback(async () => {
|
|
64
|
-
if (!wcUri) return
|
|
65
|
-
try {
|
|
66
|
-
await navigator.clipboard.writeText(wcUri)
|
|
67
|
-
setCopied(true)
|
|
68
|
-
setTimeout(() => setCopied(false), 2000)
|
|
69
|
-
} catch (err) {
|
|
70
|
-
logger.console.error(
|
|
71
|
-
"[trails-sdk] [WalletConnect] Failed to copy URI",
|
|
72
|
-
err,
|
|
73
|
-
)
|
|
74
|
-
}
|
|
75
|
-
}, [wcUri])
|
|
76
62
|
const isWalletConnectConnector = React.useMemo(() => {
|
|
77
63
|
return connector?.name === "WalletConnect" && isConnected
|
|
78
64
|
}, [connector, isConnected])
|
|
@@ -84,13 +70,18 @@ export const WalletConnectScreen: React.FC<WalletConnectProps> = ({
|
|
|
84
70
|
(c.id || "").toLowerCase().includes("walletconnect"),
|
|
85
71
|
)
|
|
86
72
|
|
|
87
|
-
// Only auto-navigate
|
|
73
|
+
// Only auto-navigate back if we successfully connect a new wallet
|
|
88
74
|
// Don't auto-navigate if user was already connected when they entered this screen
|
|
89
75
|
useEffect(() => {
|
|
90
|
-
if (
|
|
91
|
-
|
|
76
|
+
if (
|
|
77
|
+
isConnected &&
|
|
78
|
+
status === "success" &&
|
|
79
|
+
!wasConnectedOnMount.current &&
|
|
80
|
+
onBack
|
|
81
|
+
) {
|
|
82
|
+
onBack()
|
|
92
83
|
}
|
|
93
|
-
}, [isConnected, status,
|
|
84
|
+
}, [isConnected, status, onBack])
|
|
94
85
|
|
|
95
86
|
const handleConnect = useCallback(
|
|
96
87
|
async (force: boolean = false) => {
|
|
@@ -101,7 +92,7 @@ export const WalletConnectScreen: React.FC<WalletConnectProps> = ({
|
|
|
101
92
|
})
|
|
102
93
|
if ((status === "pending" || status === "success") && !force) return
|
|
103
94
|
|
|
104
|
-
const makeConnector = () => getWalletConnectConnector(projectId)
|
|
95
|
+
const makeConnector = () => getWalletConnectConnector(projectId!)
|
|
105
96
|
const connector = wcConnectorFromConfig || makeConnector()
|
|
106
97
|
|
|
107
98
|
logger.console.log(
|
|
@@ -317,82 +308,29 @@ export const WalletConnectScreen: React.FC<WalletConnectProps> = ({
|
|
|
317
308
|
getWalletIcon("walletconnect")
|
|
318
309
|
}
|
|
319
310
|
/>
|
|
320
|
-
<
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
311
|
+
<button
|
|
312
|
+
onClick={() => setShowUri(!showUri)}
|
|
313
|
+
className="mt-2 text-xs text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 hover:underline cursor-pointer flex items-center gap-1"
|
|
314
|
+
>
|
|
315
|
+
{showUri ? "Hide URI" : "Show URI"}
|
|
316
|
+
<svg
|
|
317
|
+
className={`w-3 h-3 transition-transform ${showUri ? "rotate-180" : ""}`}
|
|
318
|
+
fill="none"
|
|
319
|
+
stroke="currentColor"
|
|
320
|
+
viewBox="0 0 24 24"
|
|
326
321
|
>
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
>
|
|
336
|
-
<path
|
|
337
|
-
strokeLinecap="round"
|
|
338
|
-
strokeLinejoin="round"
|
|
339
|
-
strokeWidth={2}
|
|
340
|
-
d="M5 13l4 4L19 7"
|
|
341
|
-
/>
|
|
342
|
-
</svg>
|
|
343
|
-
Copied!
|
|
344
|
-
</>
|
|
345
|
-
) : (
|
|
346
|
-
<>
|
|
347
|
-
<svg
|
|
348
|
-
className="w-3 h-3"
|
|
349
|
-
fill="none"
|
|
350
|
-
stroke="currentColor"
|
|
351
|
-
viewBox="0 0 24 24"
|
|
352
|
-
aria-hidden="true"
|
|
353
|
-
>
|
|
354
|
-
<path
|
|
355
|
-
strokeLinecap="round"
|
|
356
|
-
strokeLinejoin="round"
|
|
357
|
-
strokeWidth={2}
|
|
358
|
-
d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"
|
|
359
|
-
/>
|
|
360
|
-
</svg>
|
|
361
|
-
Copy URI
|
|
362
|
-
</>
|
|
363
|
-
)}
|
|
364
|
-
</button>
|
|
365
|
-
<button
|
|
366
|
-
type="button"
|
|
367
|
-
onClick={() => setShowUri(!showUri)}
|
|
368
|
-
className="text-xs text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 hover:underline cursor-pointer flex items-center gap-1"
|
|
369
|
-
>
|
|
370
|
-
{showUri ? "Hide URI" : "Show URI"}
|
|
371
|
-
<svg
|
|
372
|
-
className={`w-3 h-3 transition-transform ${showUri ? "rotate-180" : ""}`}
|
|
373
|
-
fill="none"
|
|
374
|
-
stroke="currentColor"
|
|
375
|
-
viewBox="0 0 24 24"
|
|
376
|
-
aria-hidden="true"
|
|
377
|
-
>
|
|
378
|
-
<path
|
|
379
|
-
strokeLinecap="round"
|
|
380
|
-
strokeLinejoin="round"
|
|
381
|
-
strokeWidth={2}
|
|
382
|
-
d="M19 9l-7 7-7-7"
|
|
383
|
-
/>
|
|
384
|
-
</svg>
|
|
385
|
-
</button>
|
|
386
|
-
</div>
|
|
322
|
+
<path
|
|
323
|
+
strokeLinecap="round"
|
|
324
|
+
strokeLinejoin="round"
|
|
325
|
+
strokeWidth={2}
|
|
326
|
+
d="M19 9l-7 7-7-7"
|
|
327
|
+
/>
|
|
328
|
+
</svg>
|
|
329
|
+
</button>
|
|
387
330
|
{showUri && (
|
|
388
|
-
<
|
|
389
|
-
type="button"
|
|
390
|
-
className="mt-2 text-xs text-gray-600 dark:text-gray-400 break-all cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 p-2 rounded transition-colors text-left w-full"
|
|
391
|
-
onClick={handleCopyUri}
|
|
392
|
-
title="Click to copy URI"
|
|
393
|
-
>
|
|
331
|
+
<p className="mt-2 text-xs text-gray-600 dark:text-gray-400 break-all">
|
|
394
332
|
{wcUri}
|
|
395
|
-
</
|
|
333
|
+
</p>
|
|
396
334
|
)}
|
|
397
335
|
</div>
|
|
398
336
|
) : (
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
import { getTokenInfo, getSupportedTokens } from "../../tokens.js"
|
|
9
9
|
import { getExplorerUrl } from "../../explorer.js"
|
|
10
10
|
import { logger } from "../../logger.js"
|
|
11
|
+
import { useTrails } from "../providers/TrailsProvider.js"
|
|
11
12
|
|
|
12
13
|
export type UseIntentTransactionHistoryParams = {
|
|
13
14
|
accountAddress?: string
|
|
@@ -34,6 +35,7 @@ export function useIntentTransactionHistory({
|
|
|
34
35
|
pageSize = 10,
|
|
35
36
|
enabled = true,
|
|
36
37
|
}: UseIntentTransactionHistoryParams): UseIntentTransactionHistoryReturn {
|
|
38
|
+
const trailsConfig = useTrails()
|
|
37
39
|
const [transactions, setTransactions] = useState<IntentTransaction[]>([])
|
|
38
40
|
const [loading, setLoading] = useState(false)
|
|
39
41
|
const [error, setError] = useState<string | null>(null)
|
|
@@ -53,6 +55,8 @@ export function useIntentTransactionHistory({
|
|
|
53
55
|
accountAddress,
|
|
54
56
|
pageSize,
|
|
55
57
|
page: pageNum,
|
|
58
|
+
apiKey: trailsConfig.trailsApiKey,
|
|
59
|
+
apiUrl: trailsConfig.trailsApiUrl!,
|
|
56
60
|
})
|
|
57
61
|
|
|
58
62
|
// Enrich transactions with token information
|
|
@@ -268,6 +272,8 @@ export function useIntentTransactionHistory({
|
|
|
268
272
|
pageSize: 10, // Fetch more to find both deposit and action txs
|
|
269
273
|
page: 0,
|
|
270
274
|
includeMetadata: true, // Need metadata to check transfer direction
|
|
275
|
+
apiKey: trailsConfig.trailsApiKey,
|
|
276
|
+
indexerUrl: trailsConfig.sequenceIndexerUrl!,
|
|
271
277
|
})
|
|
272
278
|
if (
|
|
273
279
|
originHistory?.transactions &&
|
|
@@ -329,6 +335,8 @@ export function useIntentTransactionHistory({
|
|
|
329
335
|
pageSize: 10, // Fetch more to find both deposit and action txs
|
|
330
336
|
page: 0,
|
|
331
337
|
includeMetadata: true, // Need metadata to check transfer direction
|
|
338
|
+
apiKey: trailsConfig.trailsApiKey,
|
|
339
|
+
indexerUrl: trailsConfig.sequenceIndexerUrl!,
|
|
332
340
|
})
|
|
333
341
|
if (
|
|
334
342
|
destinationHistory?.transactions &&
|
|
@@ -483,7 +491,7 @@ export function useIntentTransactionHistory({
|
|
|
483
491
|
setLoading(false)
|
|
484
492
|
}
|
|
485
493
|
},
|
|
486
|
-
[accountAddress, enabled, pageSize],
|
|
494
|
+
[accountAddress, enabled, pageSize, trailsConfig],
|
|
487
495
|
)
|
|
488
496
|
|
|
489
497
|
const refetch = () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useQuery } from "@tanstack/react-query"
|
|
2
|
-
import { useRef
|
|
2
|
+
import { useRef } from "react"
|
|
3
3
|
import type { TransactionReceipt } from "viem"
|
|
4
4
|
import { zeroAddress } from "viem"
|
|
5
5
|
import { useIndexerGatewayClient } from "../../indexerClient.js"
|
|
@@ -7,14 +7,13 @@ import { getTokenBalancesWithPrices } from "../../tokenBalances.js"
|
|
|
7
7
|
import { logger } from "../../logger.js"
|
|
8
8
|
import { useSupportedTokens } from "../../tokens.js"
|
|
9
9
|
import { useTrailsClient } from "../../trailsClient.js"
|
|
10
|
+
import { useTrails } from "../../widget/providers/TrailsProvider.js"
|
|
10
11
|
import { getExplorerUrl } from "../../explorer.js"
|
|
11
12
|
import { getFullErrorMessage, getPrettifiedErrorMessage } from "../../error.js"
|
|
12
13
|
import { prepareSend } from "../../prepareSend.js"
|
|
13
14
|
import { abortControllerRegistry } from "../../abortController.js"
|
|
14
15
|
import { TradeType } from "../../prepareSend.js"
|
|
15
16
|
import { getChainInfo } from "../../chains.js"
|
|
16
|
-
import type { TrailsClientConfig } from "../../trailsClient.js"
|
|
17
|
-
import type { IndexerGatewayConfig } from "../../indexerClient.js"
|
|
18
17
|
import type {
|
|
19
18
|
MetaTxnReceipt,
|
|
20
19
|
PrepareSendOptions,
|
|
@@ -23,7 +22,6 @@ import type { Chain } from "../../chains.js"
|
|
|
23
22
|
import type { SupportedToken } from "../../tokens.js"
|
|
24
23
|
import type { TransactionState } from "../../transactions.js"
|
|
25
24
|
import type { PrepareSendFees } from "../../prepareSend.js"
|
|
26
|
-
import type { SequenceEnv } from "../../config.js"
|
|
27
25
|
import { getTokenPrice } from "../../prices.js"
|
|
28
26
|
import { useCommitIntent, useExecuteIntent } from "../../mutations.js"
|
|
29
27
|
import type { CheckoutOnHandlers } from "./useCheckout.js"
|
|
@@ -77,6 +75,7 @@ export type UseQuoteProps = {
|
|
|
77
75
|
} | null
|
|
78
76
|
abortSignal?: AbortSignal
|
|
79
77
|
apiKey?: string | null
|
|
78
|
+
nodeGatewayEnv?: "prod" | "dev" | "local" | "cors-anywhere"
|
|
80
79
|
}
|
|
81
80
|
|
|
82
81
|
export type SwapReturn = {
|
|
@@ -154,9 +153,7 @@ export function useQuote({
|
|
|
154
153
|
nodeGatewayEnv,
|
|
155
154
|
abortSignal: externalAbortSignal,
|
|
156
155
|
apiKey,
|
|
157
|
-
}: Partial<
|
|
158
|
-
UseQuoteProps & { nodeGatewayEnv?: SequenceEnv }
|
|
159
|
-
> = {}): UseQuoteReturn {
|
|
156
|
+
}: Partial<UseQuoteProps> = {}): UseQuoteReturn {
|
|
160
157
|
// Set node gateway environment override for this quote session
|
|
161
158
|
if (nodeGatewayEnv) {
|
|
162
159
|
;(globalThis as any).__testNodeGatewayEnv = nodeGatewayEnv
|
|
@@ -185,17 +182,13 @@ export function useQuote({
|
|
|
185
182
|
})()
|
|
186
183
|
: abortControllerRef.current.signal
|
|
187
184
|
|
|
188
|
-
const
|
|
189
|
-
return apiKey ? { apiKey } : {}
|
|
190
|
-
}, [apiKey])
|
|
191
|
-
const indexerGatewayClientConfig = useMemo<IndexerGatewayConfig>(() => {
|
|
192
|
-
return apiKey ? { projectAccessKey: apiKey } : {}
|
|
193
|
-
}, [apiKey])
|
|
185
|
+
const { trailsApiKey, trailsApiUrl, sequenceIndexerUrl } = useTrails()
|
|
194
186
|
|
|
195
|
-
const trailsClient = useTrailsClient(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
)
|
|
187
|
+
const trailsClient = useTrailsClient({
|
|
188
|
+
apiKey: trailsApiKey,
|
|
189
|
+
hostname: trailsApiUrl,
|
|
190
|
+
})
|
|
191
|
+
const indexerGatewayClient = useIndexerGatewayClient()
|
|
199
192
|
|
|
200
193
|
const { supportedTokens } = useSupportedTokens()
|
|
201
194
|
|
|
@@ -388,6 +381,7 @@ export function useQuote({
|
|
|
388
381
|
commitIntentFn: commitIntentMutation.mutateAsync,
|
|
389
382
|
executeIntentFn: executeIntentMutation.mutateAsync,
|
|
390
383
|
checkoutOnHandlers,
|
|
384
|
+
sequenceIndexerUrl,
|
|
391
385
|
}
|
|
392
386
|
|
|
393
387
|
logger.console.log("[trails-sdk] options", options)
|
|
@@ -40,6 +40,7 @@ import { etherlink } from "viem/chains"
|
|
|
40
40
|
import { logger } from "../../logger.js"
|
|
41
41
|
import { getIsContract } from "../../contractUtils.js"
|
|
42
42
|
import { useTrailsClient } from "../../trailsClient.js"
|
|
43
|
+
import { useTrails } from "../providers/TrailsProvider.js"
|
|
43
44
|
import { useTokenList } from "./useTokenList.js"
|
|
44
45
|
import { useSelectedFeeToken } from "./useSelectedFeeToken.js"
|
|
45
46
|
|
|
@@ -433,6 +434,7 @@ export function useSendForm({
|
|
|
433
434
|
}, [selectedDestToken, defaultDestToken])
|
|
434
435
|
|
|
435
436
|
const trailsClient = useTrailsClient()
|
|
437
|
+
const { sequenceIndexerUrl } = useTrails()
|
|
436
438
|
|
|
437
439
|
// Get user's token balances for balance checking
|
|
438
440
|
const { filteredTokensFormatted } = useTokenList({
|
|
@@ -849,6 +851,7 @@ export function useSendForm({
|
|
|
849
851
|
checkoutOnHandlers,
|
|
850
852
|
selectedFeeToken: selectedFeeToken ?? undefined,
|
|
851
853
|
walletId,
|
|
854
|
+
sequenceIndexerUrl,
|
|
852
855
|
}
|
|
853
856
|
|
|
854
857
|
logger.console.log(
|
|
@@ -879,6 +882,7 @@ export function useSendForm({
|
|
|
879
882
|
selectedDestToken?.decimals,
|
|
880
883
|
recipient,
|
|
881
884
|
destinationTokenAddress,
|
|
885
|
+
sequenceIndexerUrl,
|
|
882
886
|
selectedDestToken?.symbol,
|
|
883
887
|
selectedDestinationChain?.id,
|
|
884
888
|
selectedToken?.contractAddress,
|
package/src/widget/index.tsx
CHANGED