0xtrails 0.1.2 → 0.1.4

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.
Files changed (158) hide show
  1. package/dist/address.d.ts.map +1 -1
  2. package/dist/analytics.d.ts +86 -1
  3. package/dist/analytics.d.ts.map +1 -1
  4. package/dist/apiClient.d.ts +1 -1
  5. package/dist/apiClient.d.ts.map +1 -1
  6. package/dist/{ccip-BmFTEOaB.js → ccip-dLSEJjCf.js} +55 -55
  7. package/dist/cctpqueue.d.ts +1 -1
  8. package/dist/cctpqueue.d.ts.map +1 -1
  9. package/dist/chains.d.ts +9 -3
  10. package/dist/chains.d.ts.map +1 -1
  11. package/dist/constants.d.ts +1 -0
  12. package/dist/constants.d.ts.map +1 -1
  13. package/dist/decoders.d.ts +58 -0
  14. package/dist/decoders.d.ts.map +1 -0
  15. package/dist/ens.d.ts +13 -0
  16. package/dist/ens.d.ts.map +1 -0
  17. package/dist/error.d.ts +9 -0
  18. package/dist/error.d.ts.map +1 -1
  19. package/dist/{index-BPsVj7zK.js → index-BXbaLmtt.js} +28779 -25738
  20. package/dist/index.js +2 -2
  21. package/dist/intents.d.ts +4 -4
  22. package/dist/intents.d.ts.map +1 -1
  23. package/dist/lifi.d.ts +4 -0
  24. package/dist/lifi.d.ts.map +1 -0
  25. package/dist/metaTxns.d.ts +1 -1
  26. package/dist/metaTxns.d.ts.map +1 -1
  27. package/dist/mode.d.ts +1 -1
  28. package/dist/mode.d.ts.map +1 -1
  29. package/dist/preconditions.d.ts +1 -1
  30. package/dist/preconditions.d.ts.map +1 -1
  31. package/dist/prepareSend.d.ts +32 -24
  32. package/dist/prepareSend.d.ts.map +1 -1
  33. package/dist/prices.d.ts +3 -1
  34. package/dist/prices.d.ts.map +1 -1
  35. package/dist/proxyCaller.d.ts +0 -1
  36. package/dist/proxyCaller.d.ts.map +1 -1
  37. package/dist/relaySdk.d.ts.map +1 -1
  38. package/dist/relayer.d.ts.map +1 -1
  39. package/dist/tokenBalances.d.ts +1 -1
  40. package/dist/tokenBalances.d.ts.map +1 -1
  41. package/dist/tokens.d.ts +2 -1
  42. package/dist/tokens.d.ts.map +1 -1
  43. package/dist/trails.d.ts +4 -4
  44. package/dist/trails.d.ts.map +1 -1
  45. package/dist/transactions.d.ts +4 -0
  46. package/dist/transactions.d.ts.map +1 -1
  47. package/dist/utils.d.ts +6 -0
  48. package/dist/utils.d.ts.map +1 -1
  49. package/dist/wallets.d.ts +247 -5
  50. package/dist/wallets.d.ts.map +1 -1
  51. package/dist/widget/components/ChainFilterDropdown.d.ts +2 -0
  52. package/dist/widget/components/ChainFilterDropdown.d.ts.map +1 -1
  53. package/dist/widget/components/ConnectWallet.d.ts +1 -0
  54. package/dist/widget/components/ConnectWallet.d.ts.map +1 -1
  55. package/dist/widget/components/DebugScreensDropdown.d.ts.map +1 -1
  56. package/dist/widget/components/ErrorDisplay.d.ts +9 -0
  57. package/dist/widget/components/ErrorDisplay.d.ts.map +1 -0
  58. package/dist/widget/components/FundSendForm.d.ts +2 -2
  59. package/dist/widget/components/FundSendForm.d.ts.map +1 -1
  60. package/dist/widget/components/OriginTransferInformation.d.ts +10 -0
  61. package/dist/widget/components/OriginTransferInformation.d.ts.map +1 -0
  62. package/dist/widget/components/PaySendForm.d.ts +2 -2
  63. package/dist/widget/components/PaySendForm.d.ts.map +1 -1
  64. package/dist/widget/components/QrCode.d.ts +1 -1
  65. package/dist/widget/components/QrCode.d.ts.map +1 -1
  66. package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
  67. package/dist/widget/components/Receipt.d.ts.map +1 -1
  68. package/dist/widget/components/Receive.d.ts +12 -0
  69. package/dist/widget/components/Receive.d.ts.map +1 -0
  70. package/dist/widget/components/RefundAddressInput.d.ts +13 -0
  71. package/dist/widget/components/RefundAddressInput.d.ts.map +1 -0
  72. package/dist/widget/components/Swap.d.ts +47 -0
  73. package/dist/widget/components/Swap.d.ts.map +1 -0
  74. package/dist/widget/components/SwapDisplay.d.ts +9 -0
  75. package/dist/widget/components/SwapDisplay.d.ts.map +1 -0
  76. package/dist/widget/components/TokenList.d.ts +0 -2
  77. package/dist/widget/components/TokenList.d.ts.map +1 -1
  78. package/dist/widget/components/TokenSelector.d.ts +26 -0
  79. package/dist/widget/components/TokenSelector.d.ts.map +1 -0
  80. package/dist/widget/components/TransferPendingVertical.d.ts +2 -0
  81. package/dist/widget/components/TransferPendingVertical.d.ts.map +1 -1
  82. package/dist/widget/components/WalletConnect.d.ts.map +1 -1
  83. package/dist/widget/components/WalletConnectionPending.d.ts +12 -0
  84. package/dist/widget/components/WalletConnectionPending.d.ts.map +1 -0
  85. package/dist/widget/components/WalletList.d.ts.map +1 -1
  86. package/dist/widget/components/YellowWarningAnimation.d.ts +2 -0
  87. package/dist/widget/components/YellowWarningAnimation.d.ts.map +1 -0
  88. package/dist/widget/hooks/useAmountUsd.d.ts +1 -3
  89. package/dist/widget/hooks/useAmountUsd.d.ts.map +1 -1
  90. package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
  91. package/dist/widget/hooks/useDebugScreens.d.ts +22 -0
  92. package/dist/widget/hooks/useDebugScreens.d.ts.map +1 -0
  93. package/dist/widget/hooks/useSendForm.d.ts +12 -6
  94. package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
  95. package/dist/widget/hooks/useTokenList.d.ts +2 -3
  96. package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
  97. package/dist/widget/index.js +1 -1
  98. package/dist/widget/widget.d.ts.map +1 -1
  99. package/package.json +19 -15
  100. package/src/aave.ts +13 -13
  101. package/src/address.ts +3 -0
  102. package/src/analytics.ts +192 -8
  103. package/src/apiClient.ts +1 -1
  104. package/src/cctpqueue.ts +1 -1
  105. package/src/chains.ts +45 -7
  106. package/src/constants.ts +7 -4
  107. package/src/decoders.ts +310 -0
  108. package/src/ens.ts +32 -0
  109. package/src/error.ts +101 -1
  110. package/src/intents.ts +10 -2
  111. package/src/lifi.ts +58 -0
  112. package/src/metaTxns.ts +1 -1
  113. package/src/mode.ts +1 -1
  114. package/src/morpho.ts +3 -3
  115. package/src/pools.ts +18 -18
  116. package/src/preconditions.ts +1 -1
  117. package/src/prepareSend.ts +463 -113
  118. package/src/prices.ts +26 -1
  119. package/src/proxyCaller.ts +2 -14
  120. package/src/relaySdk.ts +1 -0
  121. package/src/relayer.ts +8 -0
  122. package/src/tokenBalances.ts +24 -17
  123. package/src/tokens.ts +147 -22
  124. package/src/trails.ts +4 -4
  125. package/src/transactions.ts +35 -17
  126. package/src/utils.ts +28 -0
  127. package/src/wallets.ts +275 -35
  128. package/src/widget/compiled.css +2 -2
  129. package/src/widget/components/ChainFilterDropdown.tsx +42 -33
  130. package/src/widget/components/ChainImage.tsx +1 -1
  131. package/src/widget/components/ConnectWallet.tsx +92 -128
  132. package/src/widget/components/DebugScreensDropdown.tsx +6 -0
  133. package/src/widget/components/ErrorDisplay.tsx +150 -0
  134. package/src/widget/components/FundSendForm.tsx +78 -11
  135. package/src/widget/components/OriginTransferInformation.tsx +59 -0
  136. package/src/widget/components/PaySendForm.tsx +80 -13
  137. package/src/widget/components/QRCodeDeposit.tsx +6 -6
  138. package/src/widget/components/QrCode.tsx +278 -17
  139. package/src/widget/components/QuoteDetails.tsx +93 -25
  140. package/src/widget/components/Receipt.tsx +296 -103
  141. package/src/widget/components/Receive.tsx +146 -0
  142. package/src/widget/components/RecentTokens.tsx +1 -1
  143. package/src/widget/components/RefundAddressInput.tsx +149 -0
  144. package/src/widget/components/Swap.tsx +769 -0
  145. package/src/widget/components/SwapDisplay.tsx +68 -0
  146. package/src/widget/components/TokenList.tsx +27 -363
  147. package/src/widget/components/TokenSelector.tsx +405 -0
  148. package/src/widget/components/TransferPendingVertical.tsx +162 -112
  149. package/src/widget/components/WalletConnect.tsx +9 -7
  150. package/src/widget/components/WalletConnectionPending.tsx +157 -0
  151. package/src/widget/components/WalletList.tsx +6 -5
  152. package/src/widget/components/YellowWarningAnimation.tsx +146 -0
  153. package/src/widget/hooks/useAmountUsd.ts +3 -8
  154. package/src/widget/hooks/useCheckout.ts +3 -2
  155. package/src/widget/hooks/useDebugScreens.ts +583 -0
  156. package/src/widget/hooks/useSendForm.ts +111 -35
  157. package/src/widget/hooks/useTokenList.ts +155 -122
  158. package/src/widget/widget.tsx +503 -523
@@ -0,0 +1,146 @@
1
+ import type React from "react"
2
+ import { useMemo } from "react"
3
+ import { QrCode } from "./QrCode.js"
4
+ import { ScreenHeader } from "./ScreenHeader.js"
5
+ import { getExplorerUrlForAddress } from "../../explorer.js"
6
+ import { ExternalLink } from "lucide-react"
7
+ import { truncateAddress } from "../../address.js"
8
+ import { useResolveEnsName } from "../../ens.js"
9
+
10
+ interface ReceiveProps {
11
+ accountAddress: string
12
+ onBack: () => void
13
+ isConnected?: boolean
14
+ onConnectWallet?: () => void
15
+ onPay?: () => void
16
+ toChainId?: number
17
+ }
18
+
19
+ export const Receive: React.FC<ReceiveProps> = ({
20
+ accountAddress,
21
+ onBack,
22
+ isConnected = false,
23
+ onConnectWallet,
24
+ onPay,
25
+ toChainId,
26
+ }) => {
27
+ // Use the provided address directly
28
+ const resolvedAddress = accountAddress
29
+
30
+ // Resolve ENS name from the address
31
+ const { ensName } = useResolveEnsName({
32
+ address: accountAddress,
33
+ })
34
+
35
+ // Generate QR code URL for the address
36
+ const qrCodeUrl = useMemo(() => {
37
+ if (!resolvedAddress) return ""
38
+ return `ethereum:${resolvedAddress}`
39
+ }, [resolvedAddress])
40
+
41
+ // Check if accountAddress is provided
42
+ if (!accountAddress) {
43
+ return (
44
+ <div className="space-y-6">
45
+ <ScreenHeader
46
+ onBack={onBack}
47
+ headerContent="Receive"
48
+ headerContentAlign="center"
49
+ />
50
+
51
+ <div className="flex flex-col justify-center min-h-full space-y-6 pt-8">
52
+ <div className="text-center p-6 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-700/50 rounded-lg">
53
+ <div className="flex items-center justify-center space-x-2 text-amber-600 dark:text-amber-400">
54
+ <svg
55
+ className="w-5 h-5"
56
+ fill="none"
57
+ viewBox="0 0 24 24"
58
+ stroke="currentColor"
59
+ >
60
+ <path
61
+ strokeLinecap="round"
62
+ strokeLinejoin="round"
63
+ strokeWidth={2}
64
+ d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z"
65
+ />
66
+ </svg>
67
+ <span className="font-medium">Account address is required</span>
68
+ </div>
69
+ <p className="mt-2 text-sm text-amber-600 dark:text-amber-400">
70
+ Please provide an account address as <code>toAddress</code> to
71
+ generate the receive QR code.
72
+ </p>
73
+ </div>
74
+ </div>
75
+ </div>
76
+ )
77
+ }
78
+
79
+ return (
80
+ <div className="space-y-2">
81
+ <ScreenHeader
82
+ onBack={onBack}
83
+ headerContent={`Pay ${ensName ? ensName : truncateAddress(resolvedAddress)}`}
84
+ headerContentAlign="center"
85
+ />
86
+
87
+ <div className="flex flex-col justify-center min-h-full space-y-6 pt-2">
88
+ {/* QR Code Section */}
89
+ <div className="space-y-3 p-4 bg-gray-50 dark:bg-gray-800 rounded-lg">
90
+ <div className="flex justify-center">
91
+ <div className="flex flex-col items-center">
92
+ <QrCode url={qrCodeUrl} size={300} />
93
+ </div>
94
+ </div>
95
+
96
+ {/* Address Display */}
97
+ <div className="flex flex-col items-center justify-center gap-1 pt-2">
98
+ <div className="flex items-center gap-1">
99
+ <span className="text-xs text-gray-500 dark:text-gray-400">
100
+ Address:
101
+ </span>
102
+ <a
103
+ href={getExplorerUrlForAddress({
104
+ address: resolvedAddress,
105
+ chainId: toChainId || 1,
106
+ })}
107
+ target="_blank"
108
+ rel="noopener noreferrer"
109
+ className="flex items-center gap-1 text-xs text-gray-500 dark:text-gray-400 hover:underline transition-all"
110
+ >
111
+ <span>{truncateAddress(resolvedAddress)}</span>
112
+ <ExternalLink className="w-3 h-3" />
113
+ </a>
114
+ </div>
115
+ </div>
116
+ </div>
117
+
118
+ {/* Connect Wallet Button - Only show when not connected */}
119
+ {!isConnected && onConnectWallet && (
120
+ <div className="flex justify-center">
121
+ <button
122
+ type="button"
123
+ onClick={onConnectWallet}
124
+ className="px-6 py-3 font-medium rounded-lg transition-colors duration-200 cursor-pointer bg-gray-100 hover:bg-gray-200 text-gray-600 hover:text-gray-900 dark:bg-gray-800 dark:hover:bg-gray-700 dark:text-gray-300 dark:hover:text-white"
125
+ >
126
+ Connect Wallet
127
+ </button>
128
+ </div>
129
+ )}
130
+
131
+ {/* Pay Button - Only show when connected */}
132
+ {isConnected && onPay && (
133
+ <div className="flex justify-center">
134
+ <button
135
+ type="button"
136
+ onClick={onPay}
137
+ className="px-6 py-3 font-medium rounded-lg transition-colors duration-200 cursor-pointer bg-blue-500 hover:bg-blue-600 text-white"
138
+ >
139
+ Pay
140
+ </button>
141
+ </div>
142
+ )}
143
+ </div>
144
+ </div>
145
+ )
146
+ }
@@ -27,7 +27,7 @@ export const RecentTokens: React.FC<RecentTokensProps> = ({
27
27
 
28
28
  return (
29
29
  <div className="mb-0">
30
- <h3 className="text-xs font-medium text-gray-500 dark:text-gray-500">
30
+ <h3 className="text-xs font-medium text-gray-500 dark:text-gray-500 text-left">
31
31
  Recently Used
32
32
  </h3>
33
33
  <div className="flex gap-2 overflow-x-auto pb-1 trails-scrollbar">
@@ -0,0 +1,149 @@
1
+ import { ChevronDown, ChevronRight } from "lucide-react"
2
+ import type React from "react"
3
+ import { useState, useEffect } from "react"
4
+ import type { Account } from "viem"
5
+ import { isAddress } from "viem"
6
+ import { TruncatedAddress } from "./TruncatedAddress.js"
7
+ import { useResolveEnsAddress } from "../../ens.js"
8
+
9
+ interface RefundAddressInputProps {
10
+ account: Account
11
+ isOpen: boolean
12
+ onToggle: () => void
13
+ refundAddress: string
14
+ onRefundAddressChange: (address: string) => void
15
+ chainId: number
16
+ }
17
+
18
+ export const RefundAddressInput: React.FC<RefundAddressInputProps> = ({
19
+ account,
20
+ isOpen,
21
+ onToggle,
22
+ refundAddress,
23
+ onRefundAddressChange,
24
+ chainId,
25
+ }) => {
26
+ const [inputValue, setInputValue] = useState(refundAddress)
27
+
28
+ // Resolve ENS names to addresses
29
+ const { ensAddress, isLoading } = useResolveEnsAddress({
30
+ textInput: inputValue,
31
+ })
32
+
33
+ // Update the refund address when ENS is resolved
34
+ useEffect(() => {
35
+ if (ensAddress && inputValue.endsWith(".eth")) {
36
+ onRefundAddressChange(ensAddress)
37
+ }
38
+ }, [ensAddress, inputValue, onRefundAddressChange])
39
+
40
+ const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
41
+ const value = e.target.value
42
+ setInputValue(value)
43
+ // Only update immediately if it's not an ENS name (let ENS resolution handle .eth names)
44
+ if (!value.endsWith(".eth")) {
45
+ onRefundAddressChange(value)
46
+ }
47
+ }
48
+
49
+ const handleUseAccount = () => {
50
+ setInputValue(account.address)
51
+ onRefundAddressChange(account.address)
52
+ }
53
+
54
+ // Check if the input is valid (either a valid address or a resolved ENS name)
55
+ const isValidAddress =
56
+ inputValue &&
57
+ (isAddress(inputValue) || (ensAddress && inputValue.endsWith(".eth")))
58
+
59
+ return (
60
+ <div className="space-y-2">
61
+ <button
62
+ type="button"
63
+ onClick={onToggle}
64
+ className="flex items-center space-x-1 text-xs text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300 cursor-pointer"
65
+ >
66
+ <span>Set refund address</span>
67
+ {isOpen ? (
68
+ <ChevronDown className="w-3 h-3" />
69
+ ) : (
70
+ <ChevronRight className="w-3 h-3" />
71
+ )}
72
+ </button>
73
+
74
+ {isOpen && (
75
+ <div className="space-y-2 p-3 trails-border-radius-container trails-bg-secondary trails-border">
76
+ <div className="flex justify-between items-center">
77
+ <label
78
+ htmlFor="refund-address"
79
+ className="text-sm font-medium text-gray-700 dark:text-gray-300"
80
+ >
81
+ Refund Address
82
+ </label>
83
+ <button
84
+ type="button"
85
+ onClick={handleUseAccount}
86
+ disabled={
87
+ inputValue.toLowerCase() === account.address.toLowerCase()
88
+ }
89
+ className={`px-2 py-1 text-xs cursor-pointer trails-border-radius-button transition-colors ${
90
+ inputValue.toLowerCase() === account.address.toLowerCase()
91
+ ? "bg-gray-400 cursor-not-allowed text-white"
92
+ : "bg-blue-500 hover:bg-blue-600 text-white"
93
+ }`}
94
+ >
95
+ Use Account
96
+ </button>
97
+ </div>
98
+
99
+ <input
100
+ id="refund-address"
101
+ type="text"
102
+ value={inputValue}
103
+ onChange={handleInputChange}
104
+ placeholder="0x... or name.eth"
105
+ className="block w-full px-3 py-2 border border-solid trails-border-radius-input focus:ring-2 focus:ring-blue-500 focus:border-blue-500 font-mono text-sm trails-input"
106
+ />
107
+
108
+ {inputValue && (
109
+ <div className="text-xs text-gray-500 dark:text-gray-400">
110
+ {isValidAddress ? (
111
+ <div className="space-y-1">
112
+ <div className="flex items-center space-x-2">
113
+ <span>Refund to:</span>
114
+ <TruncatedAddress
115
+ address={
116
+ inputValue.endsWith(".eth")
117
+ ? ensAddress || inputValue
118
+ : inputValue
119
+ }
120
+ chainId={chainId}
121
+ />
122
+ </div>
123
+ {inputValue.endsWith(".eth") && ensAddress && (
124
+ <div className="text-gray-400">
125
+ Resolved from: {inputValue}
126
+ </div>
127
+ )}
128
+ </div>
129
+ ) : inputValue.endsWith(".eth") && isLoading ? (
130
+ <div className="flex items-center space-x-2 text-blue-500">
131
+ <div className="animate-spin rounded-full h-3 w-3 border-b-2 border-blue-500"></div>
132
+ <span>Resolving ENS name...</span>
133
+ </div>
134
+ ) : (
135
+ <span className="text-red-500">Invalid address format</span>
136
+ )}
137
+ </div>
138
+ )}
139
+
140
+ <p className="text-xs text-gray-500 dark:text-gray-400">
141
+ If the transaction fails or cannot be completed, funds will be
142
+ refunded to this address. Please make sure that this address can
143
+ receive funds on both the origin and destination chain.
144
+ </p>
145
+ </div>
146
+ )}
147
+ </div>
148
+ )
149
+ }