0xtrails 0.12.0 → 0.12.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.
Files changed (205) hide show
  1. package/dist/analytics.d.ts +65 -50
  2. package/dist/analytics.d.ts.map +1 -1
  3. package/dist/{ccip-DtfgR432.js → ccip-62W6LwH2.js} +28 -28
  4. package/dist/chains.d.ts.map +1 -1
  5. package/dist/error.d.ts +2 -0
  6. package/dist/error.d.ts.map +1 -1
  7. package/dist/estimate.d.ts.map +1 -1
  8. package/dist/fees.d.ts.map +1 -1
  9. package/dist/{index-CHiCSmCD.js → index-C0QTNYIA.js} +43750 -41806
  10. package/dist/index.d.ts +5 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +199 -171
  13. package/dist/localeUtils.d.ts.map +1 -1
  14. package/dist/meld/components/MeldCountriesList.d.ts +0 -2
  15. package/dist/meld/components/MeldCountriesList.d.ts.map +1 -1
  16. package/dist/meld/components/MeldFundMethods.d.ts.map +1 -1
  17. package/dist/meld/components/MeldTokensList.d.ts.map +1 -1
  18. package/dist/meld/utils/meld.d.ts +2 -52
  19. package/dist/meld/utils/meld.d.ts.map +1 -1
  20. package/dist/poolUtils.d.ts.map +1 -1
  21. package/dist/prepareSend.d.ts.map +1 -1
  22. package/dist/prices.d.ts +1 -2
  23. package/dist/prices.d.ts.map +1 -1
  24. package/dist/query/balance.fetchers.d.ts +2 -2
  25. package/dist/query/balance.fetchers.d.ts.map +1 -1
  26. package/dist/query/fiat.fetchers.d.ts +11 -0
  27. package/dist/query/fiat.fetchers.d.ts.map +1 -0
  28. package/dist/query/fiat.hooks.d.ts +18 -0
  29. package/dist/query/fiat.hooks.d.ts.map +1 -0
  30. package/dist/query/fiat.queries.d.ts +24 -0
  31. package/dist/query/fiat.queries.d.ts.map +1 -0
  32. package/dist/query/meld.fetchers.d.ts +19 -0
  33. package/dist/query/meld.fetchers.d.ts.map +1 -0
  34. package/dist/query/meld.hooks.d.ts +4 -0
  35. package/dist/query/meld.hooks.d.ts.map +1 -0
  36. package/dist/query/meld.queries.d.ts +61 -0
  37. package/dist/query/meld.queries.d.ts.map +1 -0
  38. package/dist/recover.d.ts.map +1 -1
  39. package/dist/tokens.d.ts.map +1 -1
  40. package/dist/transactionIntent/deposits/depositOrchestrator.d.ts.map +1 -1
  41. package/dist/transactionIntent/deposits/gaslessDeposit.d.ts.map +1 -1
  42. package/dist/transactionIntent/deposits/standardDeposit.d.ts +7 -1
  43. package/dist/transactionIntent/deposits/standardDeposit.d.ts.map +1 -1
  44. package/dist/transactionIntent/handlers/intentHandler.d.ts +2 -0
  45. package/dist/transactionIntent/handlers/intentHandler.d.ts.map +1 -1
  46. package/dist/transactionIntent/quote/normalizeQuote.d.ts +2 -2
  47. package/dist/transactionIntent/quote/normalizeQuote.d.ts.map +1 -1
  48. package/dist/transactionIntent/quote/quoteHelpers.d.ts +1 -1
  49. package/dist/transactionIntent/quote/quoteHelpers.d.ts.map +1 -1
  50. package/dist/transactionIntent/types.d.ts +2 -0
  51. package/dist/transactionIntent/types.d.ts.map +1 -1
  52. package/dist/transactionIntent/utils/balanceChecker.d.ts +3 -1
  53. package/dist/transactionIntent/utils/balanceChecker.d.ts.map +1 -1
  54. package/dist/transactions.d.ts +2 -9
  55. package/dist/transactions.d.ts.map +1 -1
  56. package/dist/umd/trails.min.js +206 -152
  57. package/dist/utils/fiat.d.ts +8 -0
  58. package/dist/utils/fiat.d.ts.map +1 -0
  59. package/dist/utils/format.d.ts.map +1 -1
  60. package/dist/utils/passthrough.d.ts +5 -2
  61. package/dist/utils/passthrough.d.ts.map +1 -1
  62. package/dist/utils/validation.d.ts +33 -0
  63. package/dist/utils/validation.d.ts.map +1 -1
  64. package/dist/utils.d.ts.map +1 -1
  65. package/dist/walletUtils.d.ts +1 -1
  66. package/dist/walletUtils.d.ts.map +1 -1
  67. package/dist/widget/components/ClassicSwap.d.ts.map +1 -1
  68. package/dist/widget/components/DepositTracker.d.ts.map +1 -1
  69. package/dist/widget/components/Earn.d.ts +2 -0
  70. package/dist/widget/components/Earn.d.ts.map +1 -1
  71. package/dist/widget/components/FeeOption.d.ts.map +1 -1
  72. package/dist/widget/components/Fund.d.ts.map +1 -1
  73. package/dist/widget/components/FundMethods.d.ts.map +1 -1
  74. package/dist/widget/components/HookModalContent.d.ts.map +1 -1
  75. package/dist/widget/components/MeldForm.d.ts.map +1 -1
  76. package/dist/widget/components/MeldHistory.d.ts.map +1 -1
  77. package/dist/widget/components/MeldStepsFlow.d.ts.map +1 -1
  78. package/dist/widget/components/OFTProgressBar.d.ts +2 -0
  79. package/dist/widget/components/OFTProgressBar.d.ts.map +1 -1
  80. package/dist/widget/components/OnRampProviderSelector.d.ts.map +1 -1
  81. package/dist/widget/components/OnrampHistoryRow.d.ts.map +1 -1
  82. package/dist/widget/components/Pay.d.ts.map +1 -1
  83. package/dist/widget/components/PercentageMaxButtons.d.ts.map +1 -1
  84. package/dist/widget/components/PoolDeposit.d.ts +2 -0
  85. package/dist/widget/components/PoolDeposit.d.ts.map +1 -1
  86. package/dist/widget/components/QuoteDetails.d.ts.map +1 -1
  87. package/dist/widget/components/Receipt.d.ts.map +1 -1
  88. package/dist/widget/components/SlippageToleranceSettings.d.ts.map +1 -1
  89. package/dist/widget/components/Swap.d.ts +2 -0
  90. package/dist/widget/components/Swap.d.ts.map +1 -1
  91. package/dist/widget/components/TransferPendingVertical.d.ts.map +1 -1
  92. package/dist/widget/components/Withdraw.d.ts.map +1 -1
  93. package/dist/widget/hooks/useAmountUsd.d.ts.map +1 -1
  94. package/dist/widget/hooks/useCustomTokenSearch.d.ts.map +1 -1
  95. package/dist/widget/hooks/useDisplayCurrencyPreference.d.ts.map +1 -1
  96. package/dist/widget/hooks/useFiatOnRampCurrencies.d.ts +3 -21
  97. package/dist/widget/hooks/useFiatOnRampCurrencies.d.ts.map +1 -1
  98. package/dist/widget/hooks/useMeldTransactionHistory.d.ts.map +1 -1
  99. package/dist/widget/hooks/useOnRampCountryDefaults.d.ts +0 -18
  100. package/dist/widget/hooks/useOnRampCountryDefaults.d.ts.map +1 -1
  101. package/dist/widget/hooks/useOnRampPaymentMethods.d.ts +2 -18
  102. package/dist/widget/hooks/useOnRampPaymentMethods.d.ts.map +1 -1
  103. package/dist/widget/hooks/useOnRampQuote.d.ts.map +1 -1
  104. package/dist/widget/hooks/useQuote.d.ts +5 -1
  105. package/dist/widget/hooks/useQuote.d.ts.map +1 -1
  106. package/dist/widget/hooks/useSendForm.d.ts +3 -1
  107. package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
  108. package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
  109. package/dist/widget/hooks/useTokenWithFreshBalance.d.ts +3 -2
  110. package/dist/widget/hooks/useTokenWithFreshBalance.d.ts.map +1 -1
  111. package/dist/widget/index.js +1 -1
  112. package/dist/widget/types/commonProps.d.ts +2 -0
  113. package/dist/widget/types/commonProps.d.ts.map +1 -1
  114. package/dist/widget/utils/transactionFailure.d.ts +20 -0
  115. package/dist/widget/utils/transactionFailure.d.ts.map +1 -0
  116. package/dist/widget/widget.d.ts +44 -3
  117. package/dist/widget/widget.d.ts.map +1 -1
  118. package/dist/widget/workers/intentExecutionWorker.d.ts.map +1 -1
  119. package/package.json +22 -22
  120. package/src/analytics.ts +115 -79
  121. package/src/chains.ts +0 -1
  122. package/src/error.ts +11 -0
  123. package/src/estimate.ts +12 -7
  124. package/src/fees.ts +0 -1
  125. package/src/index.ts +11 -0
  126. package/src/localeUtils.ts +3 -1
  127. package/src/meld/components/MeldCountriesList.tsx +30 -15
  128. package/src/meld/components/MeldFundMethods.tsx +8 -4
  129. package/src/meld/components/MeldTokensList.tsx +90 -2
  130. package/src/meld/utils/meld.ts +3 -400
  131. package/src/poolUtils.ts +5 -19
  132. package/src/prepareSend.ts +32 -5
  133. package/src/prices.ts +7 -33
  134. package/src/query/balance.fetchers.ts +128 -168
  135. package/src/query/fiat.fetchers.ts +33 -0
  136. package/src/query/fiat.hooks.ts +71 -0
  137. package/src/query/fiat.queries.ts +67 -0
  138. package/src/query/meld.fetchers.ts +97 -0
  139. package/src/query/meld.hooks.ts +18 -0
  140. package/src/query/meld.queries.ts +184 -0
  141. package/src/recover.ts +6 -1
  142. package/src/tokens.ts +31 -6
  143. package/src/transactionIntent/deposits/depositOrchestrator.ts +2 -0
  144. package/src/transactionIntent/deposits/gaslessDeposit.ts +9 -2
  145. package/src/transactionIntent/deposits/standardDeposit.ts +35 -14
  146. package/src/transactionIntent/handlers/intentHandler.ts +134 -138
  147. package/src/transactionIntent/quote/normalizeQuote.ts +31 -22
  148. package/src/transactionIntent/quote/quoteHelpers.ts +24 -7
  149. package/src/transactionIntent/types.ts +2 -0
  150. package/src/transactionIntent/utils/balanceChecker.ts +10 -4
  151. package/src/transactions.ts +22 -13
  152. package/src/umd.tsx +1 -1
  153. package/src/utils/fiat.ts +32 -0
  154. package/src/utils/format.ts +1 -3
  155. package/src/utils/passthrough.ts +19 -3
  156. package/src/utils/validation.ts +88 -0
  157. package/src/utils.ts +2 -1
  158. package/src/walletUtils.ts +2 -2
  159. package/src/widget/components/AccountIntentTransactionHistory.tsx +2 -2
  160. package/src/widget/components/ClassicSwap.tsx +10 -4
  161. package/src/widget/components/DepositTracker.tsx +2 -5
  162. package/src/widget/components/Earn.tsx +6 -0
  163. package/src/widget/components/FeeOption.tsx +15 -8
  164. package/src/widget/components/Fund.tsx +16 -11
  165. package/src/widget/components/FundMethods.tsx +255 -192
  166. package/src/widget/components/HookModalContent.tsx +4 -0
  167. package/src/widget/components/MeldForm.tsx +44 -42
  168. package/src/widget/components/MeldHistory.tsx +4 -3
  169. package/src/widget/components/MeldStepsFlow.tsx +33 -71
  170. package/src/widget/components/OFTProgressBar.tsx +32 -12
  171. package/src/widget/components/OnRampProviderSelector.tsx +2 -1
  172. package/src/widget/components/OnrampHistoryRow.tsx +2 -1
  173. package/src/widget/components/Pay.tsx +8 -2
  174. package/src/widget/components/PercentageMaxButtons.tsx +5 -3
  175. package/src/widget/components/PoolDeposit.tsx +6 -0
  176. package/src/widget/components/PoolWithdraw.tsx +1 -1
  177. package/src/widget/components/QuoteDetails.tsx +5 -4
  178. package/src/widget/components/Receipt.tsx +4 -3
  179. package/src/widget/components/SlippageToleranceSettings.tsx +3 -2
  180. package/src/widget/components/Swap.tsx +2 -0
  181. package/src/widget/components/TransferPendingVertical.tsx +21 -28
  182. package/src/widget/components/UserPreferences.tsx +1 -1
  183. package/src/widget/components/Withdraw.tsx +20 -14
  184. package/src/widget/hooks/useAmountUsd.ts +3 -15
  185. package/src/widget/hooks/useCustomTokenSearch.tsx +2 -6
  186. package/src/widget/hooks/useDisplayCurrencyPreference.tsx +1 -2
  187. package/src/widget/hooks/useFiatOnRampCurrencies.ts +11 -76
  188. package/src/widget/hooks/useMeldTransactionHistory.ts +24 -89
  189. package/src/widget/hooks/useOnRampCountryDefaults.ts +3 -49
  190. package/src/widget/hooks/useOnRampPaymentMethods.ts +21 -100
  191. package/src/widget/hooks/useOnRampQuote.ts +2 -5
  192. package/src/widget/hooks/useQuote.ts +10 -12
  193. package/src/widget/hooks/useSendForm.ts +6 -0
  194. package/src/widget/hooks/useTokenList.ts +3 -6
  195. package/src/widget/hooks/useTokenWithFreshBalance.ts +141 -11
  196. package/src/widget/types/commonProps.ts +2 -0
  197. package/src/widget/utils/transactionFailure.ts +52 -0
  198. package/src/widget/widget.tsx +137 -59
  199. package/src/widget/workers/intentExecutionWorker.ts +3 -1
  200. package/dist/widget/hooks/useExchangeRate.d.ts +0 -31
  201. package/dist/widget/hooks/useExchangeRate.d.ts.map +0 -1
  202. package/dist/widget/hooks/useFiatCurrencyList.d.ts +0 -3
  203. package/dist/widget/hooks/useFiatCurrencyList.d.ts.map +0 -1
  204. package/src/widget/hooks/useExchangeRate.ts +0 -257
  205. package/src/widget/hooks/useFiatCurrencyList.ts +0 -66
package/src/analytics.ts CHANGED
@@ -8,6 +8,7 @@ import { getUserLocale } from "./localeUtils.js"
8
8
  import packageJson from "../package.json" with { type: "json" }
9
9
  import type { OnrampTrackingData } from "./widget/types/analytics.js"
10
10
  import type { FundMethod } from "./transactionIntent/types.js"
11
+ import { isValidNumber, isNonNegativeNumber } from "./utils/validation.js"
11
12
 
12
13
  import { normalizeAddress } from "./utils/address.js"
13
14
  let checkoutIdSingleton: string | null = null
@@ -141,9 +142,15 @@ export function hashUserAddress(address: string) {
141
142
  })
142
143
  }
143
144
 
145
+ declare global {
146
+ interface Window {
147
+ _pseudonymize?: typeof pseudonymize
148
+ }
149
+ }
150
+
144
151
  if (typeof window !== "undefined") {
145
152
  // for debugging
146
- ;(window as any)._pseudonymize = pseudonymize
153
+ window._pseudonymize = pseudonymize
147
154
  }
148
155
 
149
156
  export const EventType = {
@@ -189,7 +196,23 @@ export const EventType = {
189
196
 
190
197
  export type EventTypes = keyof typeof EventType
191
198
  export type Event = DatabeatEvent<EventTypes>
192
- export type EventProps = any
199
+ export type AnalyticsPropValue = unknown
200
+ export type AnalyticsProps = Record<string, AnalyticsPropValue>
201
+ export type EventProps = {
202
+ event: EventTypes
203
+ props: AnalyticsProps
204
+ }
205
+
206
+ function toDatabeatProps(props: AnalyticsProps): Record<string, string> {
207
+ const normalized: Record<string, string> = {}
208
+
209
+ for (const [key, value] of Object.entries(props)) {
210
+ if (value === undefined || value === null) continue
211
+ normalized[key] = typeof value === "string" ? value : String(value)
212
+ }
213
+
214
+ return normalized
215
+ }
193
216
 
194
217
  abstract class BaseAnalytics {
195
218
  protected sequenceProjectAccessKey: string | undefined
@@ -209,36 +232,37 @@ abstract class BaseAnalytics {
209
232
  ) {
210
233
  if (!userAddress) return
211
234
 
212
- // Check if Databeat instance exists and can get user ID
213
- if ("databeat" in this && (this as any).databeat) {
214
- const currentUserId = (this as any).databeat.getUserId()
235
+ const currentUserId = this.getCurrentUserId()
215
236
 
216
- // Check if userId matches the expected hashed address format (52 chars like the hash)
217
- // Example: "10249047220fb6b1a68f5ef6d62f109d82f71dffd587e183fb"
218
- const isHashedAddressFormat =
219
- currentUserId &&
220
- typeof currentUserId === "string" &&
221
- currentUserId.length > 20
237
+ // Check if userId matches the expected hashed address format (52 chars like the hash)
238
+ // Example: "10249047220fb6b1a68f5ef6d62f109d82f71dffd587e183fb"
239
+ const isHashedAddressFormat =
240
+ currentUserId &&
241
+ typeof currentUserId === "string" &&
242
+ currentUserId.length > 20
222
243
 
223
- const isIdentified =
224
- currentUserId && currentUserId !== "anonymous" && isHashedAddressFormat
244
+ const isIdentified =
245
+ currentUserId && currentUserId !== "anonymous" && isHashedAddressFormat
225
246
 
226
- if (!isIdentified) {
227
- logger.console.log(
228
- `[trails-sdk] DEBUG: Auto-identifying from ${eventName}`,
229
- {
230
- userAddress,
231
- currentUserId,
232
- currentUserIdLength: currentUserId?.length,
233
- isHashedAddressFormat,
234
- timestamp: new Date().toISOString(),
235
- },
236
- )
237
- this.identifyUser({ address: userAddress })
238
- }
247
+ if (!isIdentified) {
248
+ logger.console.log(
249
+ `[trails-sdk] DEBUG: Auto-identifying from ${eventName}`,
250
+ {
251
+ userAddress,
252
+ currentUserId,
253
+ currentUserIdLength: currentUserId?.length,
254
+ isHashedAddressFormat,
255
+ timestamp: new Date().toISOString(),
256
+ },
257
+ )
258
+ this.identifyUser({ address: userAddress })
239
259
  }
240
260
  }
241
261
 
262
+ protected getCurrentUserId(): string | undefined {
263
+ return undefined
264
+ }
265
+
242
266
  abstract identifyUser(data: { address: string }): void
243
267
 
244
268
  private getCommonProps(): Record<string, string> {
@@ -344,7 +368,7 @@ abstract class BaseAnalytics {
344
368
  trackWidgetScreen(data: {
345
369
  screen: string
346
370
  userAddress?: string
347
- [key: string]: any
371
+ [key: string]: AnalyticsPropValue
348
372
  }) {
349
373
  // Auto-identify if userAddress provided but no ident set
350
374
  this.autoIdentifyIfNeeded(data.userAddress, "trackWidgetScreen")
@@ -465,7 +489,7 @@ abstract class BaseAnalytics {
465
489
  } else if (typeof usdAmount === "string") {
466
490
  // Try to parse as a plain number (no locale detection)
467
491
  numValue = Number(usdAmount)
468
- if (Number.isNaN(numValue)) {
492
+ if (!isValidNumber(numValue)) {
469
493
  logger.console.warn(
470
494
  "[trails-sdk] Invalid USD amount string, expected a number:",
471
495
  { usdAmount, context },
@@ -477,7 +501,7 @@ abstract class BaseAnalytics {
477
501
  }
478
502
 
479
503
  // Check for invalid numbers
480
- if (!Number.isFinite(numValue) || Number.isNaN(numValue) || numValue < 0) {
504
+ if (!isNonNegativeNumber(numValue)) {
481
505
  logger.console.warn(
482
506
  "[trails-sdk] Invalid USD amount detected, not sending to analytics:",
483
507
  {
@@ -591,6 +615,7 @@ abstract class BaseAnalytics {
591
615
  destinationTokenAmountUsd?: string | number
592
616
  originTokenDecimals?: number
593
617
  destinationTokenDecimals?: number
618
+ destinationTokenSymbol?: string
594
619
  originChainId?: number
595
620
  destinationChainId?: number
596
621
  tradeType?: string
@@ -601,7 +626,7 @@ abstract class BaseAnalytics {
601
626
  onramp?: OnrampTrackingData | null
602
627
  walletId?: string
603
628
  destinationCalldata?: string
604
- [key: string]: any
629
+ [key: string]: AnalyticsPropValue
605
630
  }) {
606
631
  // Auto-identify if userAddress provided but no ident set
607
632
  this.autoIdentifyIfNeeded(data.userAddress, "trackPaymentCompleted")
@@ -728,7 +753,7 @@ abstract class BaseAnalytics {
728
753
  fundMethod?: FundMethod
729
754
  originChainId?: number
730
755
  destinationChainId?: number
731
- [key: string]: any
756
+ [key: string]: AnalyticsPropValue
732
757
  }) {
733
758
  this.track({
734
759
  event: EventType.PAYMENT_ERROR,
@@ -753,7 +778,7 @@ abstract class BaseAnalytics {
753
778
  walletType: string
754
779
  address: string
755
780
  chainId: number
756
- [key: string]: any
781
+ [key: string]: AnalyticsPropValue
757
782
  }) {
758
783
  this.track({
759
784
  event: EventType.WALLET_CONNECTED,
@@ -766,7 +791,7 @@ abstract class BaseAnalytics {
766
791
  })
767
792
  }
768
793
 
769
- trackWalletDisconnected(data?: { [key: string]: any }) {
794
+ trackWalletDisconnected(data?: { [key: string]: AnalyticsPropValue }) {
770
795
  this.track({
771
796
  event: EventType.WALLET_DISCONNECTED,
772
797
  props: {
@@ -787,7 +812,7 @@ abstract class BaseAnalytics {
787
812
  fundMethod?: FundMethod
788
813
  originTokenSymbol?: string
789
814
  destinationTokenSymbol?: string
790
- [key: string]: any
815
+ [key: string]: AnalyticsPropValue
791
816
  }) {
792
817
  // Auto-identify if userAddress provided but no ident set
793
818
  this.autoIdentifyIfNeeded(data.userAddress, "trackIntentQuoteRequested")
@@ -838,7 +863,7 @@ abstract class BaseAnalytics {
838
863
  fromAmountMin?: string
839
864
  toAmount?: string
840
865
  toAmountMin?: string
841
- [key: string]: any
866
+ [key: string]: AnalyticsPropValue
842
867
  }) {
843
868
  // Auto-identify if userAddress provided but no ident set
844
869
  this.autoIdentifyIfNeeded(data.userAddress, "trackIntentQuoteReceived")
@@ -895,7 +920,7 @@ abstract class BaseAnalytics {
895
920
  fundMethod?: FundMethod
896
921
  originTokenSymbol?: string
897
922
  destinationTokenSymbol?: string
898
- [key: string]: any
923
+ [key: string]: AnalyticsPropValue
899
924
  }) {
900
925
  this.track({
901
926
  event: EventType.INTENT_QUOTE_ERROR,
@@ -919,7 +944,7 @@ abstract class BaseAnalytics {
919
944
  userAddress?: string
920
945
  originTokenSymbol?: string
921
946
  destinationTokenSymbol?: string
922
- [key: string]: any
947
+ [key: string]: AnalyticsPropValue
923
948
  }) {
924
949
  this.track({
925
950
  event: EventType.INTENT_COMMIT_STARTED,
@@ -944,7 +969,7 @@ abstract class BaseAnalytics {
944
969
  userAddress?: string
945
970
  originTokenSymbol?: string
946
971
  destinationTokenSymbol?: string
947
- [key: string]: any
972
+ [key: string]: AnalyticsPropValue
948
973
  }) {
949
974
  this.track({
950
975
  event: EventType.INTENT_COMMIT_COMPLETED,
@@ -974,7 +999,7 @@ abstract class BaseAnalytics {
974
999
  fundMethod?: FundMethod
975
1000
  originTokenSymbol?: string
976
1001
  destinationTokenSymbol?: string
977
- [key: string]: any
1002
+ [key: string]: AnalyticsPropValue
978
1003
  }) {
979
1004
  this.track({
980
1005
  event: EventType.INTENT_COMMIT_ERROR,
@@ -1005,7 +1030,7 @@ abstract class BaseAnalytics {
1005
1030
  mode?: string
1006
1031
  fundMethod?: FundMethod
1007
1032
  depositTokenAmountUsd?: string
1008
- [key: string]: any
1033
+ [key: string]: AnalyticsPropValue
1009
1034
  }) {
1010
1035
  // Auto-identify if userAddress provided but no ident set
1011
1036
  this.autoIdentifyIfNeeded(data.userAddress, "trackTransactionStarted")
@@ -1035,7 +1060,7 @@ abstract class BaseAnalytics {
1035
1060
  mode?: string
1036
1061
  fundMethod?: FundMethod
1037
1062
  depositTokenAmountUsd?: string
1038
- [key: string]: any
1063
+ [key: string]: AnalyticsPropValue
1039
1064
  }) {
1040
1065
  this.track({
1041
1066
  event: EventType.TRANSACTION_SIGNED,
@@ -1062,7 +1087,7 @@ abstract class BaseAnalytics {
1062
1087
  mode?: string
1063
1088
  fundMethod?: FundMethod
1064
1089
  depositTokenAmountUsd?: string
1065
- [key: string]: any
1090
+ [key: string]: AnalyticsPropValue
1066
1091
  }) {
1067
1092
  this.track({
1068
1093
  event: EventType.TRANSACTION_SUBMITTED,
@@ -1090,7 +1115,7 @@ abstract class BaseAnalytics {
1090
1115
  mode?: string
1091
1116
  fundMethod?: FundMethod
1092
1117
  depositTokenAmountUsd?: string
1093
- [key: string]: any
1118
+ [key: string]: AnalyticsPropValue
1094
1119
  }) {
1095
1120
  this.track({
1096
1121
  event: EventType.TRANSACTION_CONFIRMED,
@@ -1118,7 +1143,7 @@ abstract class BaseAnalytics {
1118
1143
  intentAddress?: string
1119
1144
  mode?: string
1120
1145
  fundMethod?: FundMethod
1121
- [key: string]: any
1146
+ [key: string]: AnalyticsPropValue
1122
1147
  }) {
1123
1148
  this.track({
1124
1149
  event: EventType.TRANSACTION_ERROR,
@@ -1143,7 +1168,7 @@ abstract class BaseAnalytics {
1143
1168
  chainId?: number
1144
1169
  mode?: string
1145
1170
  fundMethod?: FundMethod
1146
- [key: string]: any
1171
+ [key: string]: AnalyticsPropValue
1147
1172
  }) {
1148
1173
  this.track({
1149
1174
  event: EventType.RELAYER_CALL_STARTED,
@@ -1168,7 +1193,7 @@ abstract class BaseAnalytics {
1168
1193
  chainId?: number
1169
1194
  mode?: string
1170
1195
  fundMethod?: FundMethod
1171
- [key: string]: any
1196
+ [key: string]: AnalyticsPropValue
1172
1197
  }) {
1173
1198
  this.track({
1174
1199
  event: EventType.RELAYER_CALL_COMPLETED,
@@ -1194,7 +1219,7 @@ abstract class BaseAnalytics {
1194
1219
  chainId?: number
1195
1220
  mode?: string
1196
1221
  fundMethod?: FundMethod
1197
- [key: string]: any
1222
+ [key: string]: AnalyticsPropValue
1198
1223
  }) {
1199
1224
  this.track({
1200
1225
  event: EventType.RELAYER_CALL_ERROR,
@@ -1221,7 +1246,7 @@ abstract class BaseAnalytics {
1221
1246
  countryCode?: string
1222
1247
  walletAddress?: string
1223
1248
  sessionId?: string
1224
- [key: string]: any
1249
+ [key: string]: AnalyticsPropValue
1225
1250
  }) {
1226
1251
  this.track({
1227
1252
  event: EventType.ONRAMP_QUOTE_REQUESTED,
@@ -1253,7 +1278,7 @@ abstract class BaseAnalytics {
1253
1278
  quotesCount?: number
1254
1279
  responseTime?: number
1255
1280
  walletAddress?: string
1256
- [key: string]: any
1281
+ [key: string]: AnalyticsPropValue
1257
1282
  }) {
1258
1283
  this.track({
1259
1284
  event: EventType.ONRAMP_QUOTE_RECEIVED,
@@ -1280,7 +1305,7 @@ abstract class BaseAnalytics {
1280
1305
  countryCode?: string
1281
1306
  responseTime?: number
1282
1307
  walletAddress?: string
1283
- [key: string]: any
1308
+ [key: string]: AnalyticsPropValue
1284
1309
  }) {
1285
1310
  this.track({
1286
1311
  event: EventType.ONRAMP_QUOTE_ERROR,
@@ -1302,7 +1327,7 @@ abstract class BaseAnalytics {
1302
1327
  label?: string
1303
1328
  value?: string | number
1304
1329
  userAddress?: string
1305
- [key: string]: any
1330
+ [key: string]: AnalyticsPropValue
1306
1331
  }) {
1307
1332
  const userAddress = data.userAddress
1308
1333
  this.autoIdentifyIfNeeded(userAddress, "trackWidgetClick")
@@ -1328,7 +1353,7 @@ abstract class BaseAnalytics {
1328
1353
  sourceAmount?: string
1329
1354
  destinationCurrencyCode?: string
1330
1355
  paymentMethodType?: string
1331
- [key: string]: any
1356
+ [key: string]: AnalyticsPropValue
1332
1357
  }) {
1333
1358
  this.track({
1334
1359
  event: EventType.ONRAMP_WIDGET_SESSION,
@@ -1350,8 +1375,8 @@ class Analytics extends BaseAnalytics {
1350
1375
 
1351
1376
  constructor(
1352
1377
  server: string,
1353
- auth: any,
1354
- config: any,
1378
+ auth: { jwt: string },
1379
+ config: object,
1355
1380
  sequenceProjectAccessKey?: string,
1356
1381
  ) {
1357
1382
  super(sequenceProjectAccessKey)
@@ -1392,9 +1417,18 @@ class Analytics extends BaseAnalytics {
1392
1417
  this.databeat.identify()
1393
1418
  }
1394
1419
 
1420
+ protected getCurrentUserId(): string | undefined {
1421
+ return this.databeat.getUserId()
1422
+ }
1423
+
1395
1424
  track(event: EventProps) {
1425
+ const databeatEvent: Event = {
1426
+ ...event,
1427
+ props: toDatabeatProps(event.props),
1428
+ }
1429
+
1396
1430
  return this.databeat
1397
- .track(event)
1431
+ .track(databeatEvent)
1398
1432
  .catch(() => {})
1399
1433
  .then(() => this.logEvent(event))
1400
1434
  }
@@ -1569,7 +1603,7 @@ export const trackPageview = () => {
1569
1603
  export const trackWidgetScreen = (data: {
1570
1604
  screen: string
1571
1605
  userAddress?: string
1572
- [key: string]: any
1606
+ [key: string]: AnalyticsPropValue
1573
1607
  }) => {
1574
1608
  const analytics = getAnalytics()
1575
1609
  analytics.trackWidgetScreen(data)
@@ -1610,7 +1644,7 @@ export const trackPaymentCompleted = (data: {
1610
1644
  swapProvider?: string
1611
1645
  bridgeProvider?: string
1612
1646
  onramp?: OnrampTrackingData | null
1613
- [key: string]: any
1647
+ [key: string]: AnalyticsPropValue
1614
1648
  }) => {
1615
1649
  const analytics = getAnalytics()
1616
1650
  analytics.trackPaymentCompleted(data)
@@ -1622,7 +1656,7 @@ export const trackPaymentError = (data: {
1622
1656
  intentAddress?: string
1623
1657
  mode?: string
1624
1658
  fundMethod?: FundMethod
1625
- [key: string]: any
1659
+ [key: string]: AnalyticsPropValue
1626
1660
  }) => {
1627
1661
  const analytics = getAnalytics()
1628
1662
  analytics.trackPaymentError(data)
@@ -1633,14 +1667,16 @@ export const trackWalletConnected = (data: {
1633
1667
  walletType: string
1634
1668
  address: string
1635
1669
  chainId: number
1636
- [key: string]: any
1670
+ [key: string]: AnalyticsPropValue
1637
1671
  }) => {
1638
1672
  const analytics = getAnalytics()
1639
1673
  analytics.identifyUser({ address: data.address })
1640
1674
  analytics.trackWalletConnected(data)
1641
1675
  }
1642
1676
 
1643
- export const trackWalletDisconnected = (data?: { [key: string]: any }) => {
1677
+ export const trackWalletDisconnected = (data?: {
1678
+ [key: string]: AnalyticsPropValue
1679
+ }) => {
1644
1680
  const analytics = getAnalytics()
1645
1681
  analytics.unidentifyUser()
1646
1682
  analytics.trackWalletDisconnected(data)
@@ -1654,7 +1690,7 @@ export const trackIntentQuoteRequested = (data: {
1654
1690
  userAddress?: string
1655
1691
  mode?: string
1656
1692
  fundMethod?: FundMethod
1657
- [key: string]: any
1693
+ [key: string]: AnalyticsPropValue
1658
1694
  }) => {
1659
1695
  const analytics = getAnalytics()
1660
1696
  analytics.trackIntentQuoteRequested(data)
@@ -1681,7 +1717,7 @@ export const trackIntentQuoteReceived = (data: {
1681
1717
  fundMethod?: FundMethod
1682
1718
  originPreconditionAmount?: string
1683
1719
  destinationPreconditionAmount?: string
1684
- [key: string]: any
1720
+ [key: string]: AnalyticsPropValue
1685
1721
  }) => {
1686
1722
  const analytics = getAnalytics()
1687
1723
  analytics.trackIntentQuoteReceived(data)
@@ -1696,7 +1732,7 @@ export const trackIntentQuoteError = (data: {
1696
1732
  destinationTokenAddress?: string
1697
1733
  mode?: string
1698
1734
  fundMethod?: FundMethod
1699
- [key: string]: any
1735
+ [key: string]: AnalyticsPropValue
1700
1736
  }) => {
1701
1737
  const analytics = getAnalytics()
1702
1738
  analytics.trackIntentQuoteError(data)
@@ -1709,7 +1745,7 @@ export const trackIntentCommitStarted = (data: {
1709
1745
  destinationChainId?: number
1710
1746
  mode?: string
1711
1747
  fundMethod?: FundMethod
1712
- [key: string]: any
1748
+ [key: string]: AnalyticsPropValue
1713
1749
  }) => {
1714
1750
  const analytics = getAnalytics()
1715
1751
  analytics.trackIntentCommitStarted(data)
@@ -1722,7 +1758,7 @@ export const trackIntentCommitCompleted = (data: {
1722
1758
  destinationChainId?: number
1723
1759
  mode?: string
1724
1760
  fundMethod?: FundMethod
1725
- [key: string]: any
1761
+ [key: string]: AnalyticsPropValue
1726
1762
  }) => {
1727
1763
  const analytics = getAnalytics()
1728
1764
  analytics.trackIntentCommitCompleted(data)
@@ -1736,7 +1772,7 @@ export const trackIntentCommitError = (data: {
1736
1772
  destinationChainId?: number
1737
1773
  mode?: string
1738
1774
  fundMethod?: FundMethod
1739
- [key: string]: any
1775
+ [key: string]: AnalyticsPropValue
1740
1776
  }) => {
1741
1777
  const analytics = getAnalytics()
1742
1778
  analytics.trackIntentCommitError(data)
@@ -1750,7 +1786,7 @@ export const trackTransactionStarted = (data: {
1750
1786
  intentAddress?: string
1751
1787
  mode?: string
1752
1788
  fundMethod?: FundMethod
1753
- [key: string]: any
1789
+ [key: string]: AnalyticsPropValue
1754
1790
  }) => {
1755
1791
  const analytics = getAnalytics()
1756
1792
  analytics.trackTransactionStarted(data)
@@ -1762,7 +1798,7 @@ export const trackTransactionSigned = (data: {
1762
1798
  intentAddress?: string
1763
1799
  mode?: string
1764
1800
  fundMethod?: FundMethod
1765
- [key: string]: any
1801
+ [key: string]: AnalyticsPropValue
1766
1802
  }) => {
1767
1803
  const analytics = getAnalytics()
1768
1804
  analytics.trackTransactionSigned(data)
@@ -1775,7 +1811,7 @@ export const trackTransactionSubmitted = (data: {
1775
1811
  intentAddress?: string
1776
1812
  mode?: string
1777
1813
  fundMethod?: FundMethod
1778
- [key: string]: any
1814
+ [key: string]: AnalyticsPropValue
1779
1815
  }) => {
1780
1816
  const analytics = getAnalytics()
1781
1817
  analytics.trackTransactionSubmitted(data)
@@ -1788,7 +1824,7 @@ export const trackTransactionConfirmed = (data: {
1788
1824
  intentAddress?: string
1789
1825
  mode?: string
1790
1826
  fundMethod?: FundMethod
1791
- [key: string]: any
1827
+ [key: string]: AnalyticsPropValue
1792
1828
  }) => {
1793
1829
  const analytics = getAnalytics()
1794
1830
  analytics.trackTransactionConfirmed(data)
@@ -1801,7 +1837,7 @@ export const trackTransactionError = (data: {
1801
1837
  intentAddress?: string
1802
1838
  mode?: string
1803
1839
  fundMethod?: FundMethod
1804
- [key: string]: any
1840
+ [key: string]: AnalyticsPropValue
1805
1841
  }) => {
1806
1842
  const analytics = getAnalytics()
1807
1843
  analytics.trackTransactionError(data)
@@ -1814,7 +1850,7 @@ export const trackRelayerCallStarted = (data: {
1814
1850
  chainId?: number
1815
1851
  mode?: string
1816
1852
  fundMethod?: FundMethod
1817
- [key: string]: any
1853
+ [key: string]: AnalyticsPropValue
1818
1854
  }) => {
1819
1855
  const analytics = getAnalytics()
1820
1856
  analytics.trackRelayerCallStarted(data)
@@ -1826,7 +1862,7 @@ export const trackRelayerCallCompleted = (data: {
1826
1862
  chainId?: number
1827
1863
  mode?: string
1828
1864
  fundMethod?: FundMethod
1829
- [key: string]: any
1865
+ [key: string]: AnalyticsPropValue
1830
1866
  }) => {
1831
1867
  const analytics = getAnalytics()
1832
1868
  analytics.trackRelayerCallCompleted(data)
@@ -1839,7 +1875,7 @@ export const trackRelayerCallError = (data: {
1839
1875
  chainId?: number
1840
1876
  mode?: string
1841
1877
  fundMethod?: FundMethod
1842
- [key: string]: any
1878
+ [key: string]: AnalyticsPropValue
1843
1879
  }) => {
1844
1880
  const analytics = getAnalytics()
1845
1881
  analytics.trackRelayerCallError(data)
@@ -1853,7 +1889,7 @@ export const trackOnrampQuoteRequested = (data: {
1853
1889
  countryCode?: string
1854
1890
  walletAddress?: string
1855
1891
  sessionId?: string
1856
- [key: string]: any
1892
+ [key: string]: AnalyticsPropValue
1857
1893
  }) => {
1858
1894
  const analytics = getAnalytics()
1859
1895
  analytics.trackOnrampQuoteRequested(data)
@@ -1876,7 +1912,7 @@ export const trackOnrampQuoteReceived = (data: {
1876
1912
  quotesCount?: number
1877
1913
  responseTime?: number
1878
1914
  walletAddress?: string
1879
- [key: string]: any
1915
+ [key: string]: AnalyticsPropValue
1880
1916
  }) => {
1881
1917
  const analytics = getAnalytics()
1882
1918
  analytics.trackOnrampQuoteReceived(data)
@@ -1892,7 +1928,7 @@ export const trackOnrampQuoteError = (data: {
1892
1928
  countryCode?: string
1893
1929
  responseTime?: number
1894
1930
  walletAddress?: string
1895
- [key: string]: any
1931
+ [key: string]: AnalyticsPropValue
1896
1932
  }) => {
1897
1933
  const analytics = getAnalytics()
1898
1934
  analytics.trackOnrampQuoteError(data)
@@ -1904,7 +1940,7 @@ export const trackWidgetClick = (data: {
1904
1940
  label?: string
1905
1941
  value?: string | number
1906
1942
  userAddress?: string
1907
- [key: string]: any
1943
+ [key: string]: AnalyticsPropValue
1908
1944
  }) => {
1909
1945
  const analytics = getAnalytics()
1910
1946
  analytics.trackWidgetClick(data)
@@ -1921,7 +1957,7 @@ export const trackOnrampWidgetSession = (data: {
1921
1957
  sourceAmount?: string
1922
1958
  destinationCurrencyCode?: string
1923
1959
  paymentMethodType?: string
1924
- [key: string]: any
1960
+ [key: string]: AnalyticsPropValue
1925
1961
  }) => {
1926
1962
  const analytics = getAnalytics()
1927
1963
  analytics.trackOnrampWidgetSession(data)
package/src/chains.ts CHANGED
@@ -54,7 +54,6 @@ export function isDevEnvironment(): boolean {
54
54
  trailsApiUrl?.includes("dev2-trails-api.sequence-dev.app") === true ||
55
55
  trailsApiUrl?.includes("localhost") === true
56
56
 
57
- logger.console.log("[trails-sdk] isDevEnvironment:", isDev)
58
57
  return isDev
59
58
  }
60
59
 
package/src/error.ts CHANGED
@@ -21,6 +21,10 @@ export function getErrorString(err: unknown): string {
21
21
  return err instanceof Error ? err.message : (err?.toString() ?? "")
22
22
  }
23
23
 
24
+ export function getIsAlreadyExecutingError(err: unknown): boolean {
25
+ return getFullErrorMessage(err).includes("EXECUTING")
26
+ }
27
+
24
28
  export function getIsUserRejectionError(
25
29
  err: unknown,
26
30
  ): err is UserRejectionError {
@@ -43,6 +47,13 @@ export function getIsUserRejectionError(
43
47
  return isRejected
44
48
  }
45
49
 
50
+ export function getIsPopupBlockedError(err: unknown) {
51
+ const isPopupBlocked = /Failed to initialize request/gi.test(
52
+ getErrorString(err).toLowerCase(),
53
+ )
54
+ return isPopupBlocked
55
+ }
56
+
46
57
  export function getIsBalanceTooLowError(err: unknown) {
47
58
  const isBalanceTooLow =
48
59
  /have enough balance|not enough balance|insufficient balance|insufficient funds|not enough funds|too low/gi.test(
package/src/estimate.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  import { type PublicClient, formatUnits } from "viem"
2
2
  import { getChainInfo, getChainRpcClient } from "./chains.js"
3
3
  import { logger } from "./logger.js"
4
+ import {
5
+ isValidNumber,
6
+ isPositiveNumber,
7
+ isNonNegativeNumber,
8
+ } from "./utils/validation.js"
4
9
 
5
10
  // Default minimum gas limit for deposit transactions
6
11
  // Used as fallback when gas estimation is not available
@@ -249,7 +254,7 @@ export function calculateMaxNativeAmount(
249
254
  const balance = parseFloat(userBalanceFormatted)
250
255
 
251
256
  // Check for invalid balance
252
- if (Number.isNaN(balance) || !Number.isFinite(balance) || balance <= 0) {
257
+ if (!isPositiveNumber(balance)) {
253
258
  return "0"
254
259
  }
255
260
 
@@ -261,7 +266,7 @@ export function calculateMaxNativeAmount(
261
266
  const gasCost = parseFloat(gasCostFormatted)
262
267
 
263
268
  // Check for invalid gas cost
264
- if (Number.isNaN(gasCost) || !Number.isFinite(gasCost) || gasCost < 0) {
269
+ if (!isNonNegativeNumber(gasCost)) {
265
270
  return userBalanceFormatted
266
271
  }
267
272
 
@@ -273,8 +278,8 @@ export function calculateMaxNativeAmount(
273
278
  // Validate buffer percentage
274
279
  const safeBufferPercentage =
275
280
  typeof bufferPercentage === "number" &&
276
- Number.isFinite(bufferPercentage) &&
277
- bufferPercentage >= 0
281
+ isNonNegativeNumber(bufferPercentage) &&
282
+ bufferPercentage <= 100
278
283
  ? bufferPercentage
279
284
  : 50
280
285
 
@@ -282,7 +287,7 @@ export function calculateMaxNativeAmount(
282
287
  const gasWithBuffer = gasCost * (1 + safeBufferPercentage / 100)
283
288
 
284
289
  // Check for overflow
285
- if (!Number.isFinite(gasWithBuffer)) {
290
+ if (!isValidNumber(gasWithBuffer)) {
286
291
  return "0"
287
292
  }
288
293
 
@@ -290,7 +295,7 @@ export function calculateMaxNativeAmount(
290
295
  const maxAmount = balance - gasWithBuffer
291
296
 
292
297
  // Check for invalid result
293
- if (Number.isNaN(maxAmount) || !Number.isFinite(maxAmount)) {
298
+ if (!isValidNumber(maxAmount)) {
294
299
  return "0"
295
300
  }
296
301
 
@@ -358,7 +363,7 @@ export async function getDefaultGasCostEstimate(
358
363
  )
359
364
  try {
360
365
  const balanceNum = parseFloat(balance)
361
- if (Number.isNaN(balanceNum) || balanceNum <= 0) {
366
+ if (!isPositiveNumber(balanceNum)) {
362
367
  logger.console.log(
363
368
  "[trails-sdk][gas-estimation] Invalid balance, returning 0",
364
369
  )
package/src/fees.ts CHANGED
@@ -42,7 +42,6 @@ export const ROUTE_PROVIDER_INFO: Record<
42
42
  ZEROX: { name: "0x", url: "https://0x.org/" },
43
43
  SUSHI: { name: "Sushi", url: "https://www.sushi.com/" },
44
44
  LZ_OFT: { name: "LayerZero OFT", url: "https://layerzero.network/" },
45
- LZ_STARGATE: { name: "Stargate", url: "https://layerzero.network/" },
46
45
  }
47
46
 
48
47
  export interface TrailsFeeBreakdown {