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
@@ -1,257 +0,0 @@
1
- import { useQuery } from "@tanstack/react-query"
2
- import { useEffect } from "react"
3
- import { useTrailsClient } from "../../trailsClient.js"
4
- import { useDisplayCurrencyPreference } from "./useDisplayCurrencyPreference.js"
5
- import { MINUTE_MS, HOUR_MS } from "../../utils/time.js"
6
-
7
- interface UseExchangeRateOptions {
8
- fromCurrency?: string
9
- toCurrency?: string
10
- disabled?: boolean
11
- }
12
-
13
- interface UseExchangeRateResult {
14
- exchangeRate: number | undefined
15
- isLoading: boolean
16
- error: Error | null
17
- }
18
-
19
- interface ExchangeRateCache {
20
- value: number
21
- name: string
22
- symbol: string
23
- vsCurrency: string
24
- currencyType: string
25
- timestamp: number
26
- }
27
-
28
- const EXCHANGE_RATE_CACHE_KEY_PREFIX = "trails-exchange-rate-"
29
- const EXCHANGE_RATE_CACHE_DURATION = HOUR_MS // 1 hour in milliseconds
30
-
31
- /**
32
- * Get cached exchange rate from localStorage
33
- */
34
- function getCachedExchangeRate(currency: string): ExchangeRateCache | null {
35
- try {
36
- const key = `${EXCHANGE_RATE_CACHE_KEY_PREFIX}${currency.toUpperCase()}`
37
- const cached = localStorage.getItem(key)
38
- if (!cached) return null
39
-
40
- const data = JSON.parse(cached) as ExchangeRateCache
41
- const now = Date.now()
42
-
43
- // Check if cache is expired (older than 1 hour)
44
- if (now - data.timestamp > EXCHANGE_RATE_CACHE_DURATION) {
45
- localStorage.removeItem(key)
46
- return null
47
- }
48
-
49
- return data
50
- } catch (error) {
51
- console.warn("Failed to get cached exchange rate:", error)
52
- return null
53
- }
54
- }
55
-
56
- /**
57
- * Save exchange rate to localStorage cache
58
- */
59
- function setCachedExchangeRate(
60
- currency: string,
61
- data: {
62
- value: number
63
- name: string
64
- symbol: string
65
- vsCurrency: string
66
- currencyType: string
67
- },
68
- ): void {
69
- try {
70
- const key = `${EXCHANGE_RATE_CACHE_KEY_PREFIX}${currency.toUpperCase()}`
71
- const cacheData: ExchangeRateCache = {
72
- ...data,
73
- timestamp: Date.now(),
74
- }
75
- localStorage.setItem(key, JSON.stringify(cacheData))
76
- } catch (error) {
77
- console.warn("Failed to cache exchange rate:", error)
78
- }
79
- }
80
-
81
- /**
82
- * Wrapper hook for exchange rate fetching that abstracts the underlying implementation
83
- * This allows us to easily swap out the exchange rate provider in the future
84
- */
85
- export function useExchangeRate(
86
- options: UseExchangeRateOptions = {},
87
- ): UseExchangeRateResult {
88
- const { fromCurrency = "USD", toCurrency = "USD", disabled = false } = options
89
-
90
- const trailsClient = useTrailsClient()
91
-
92
- // Handle same currency case
93
- const isSameCurrency = fromCurrency === toCurrency
94
-
95
- // Determine which currency to fetch
96
- const targetCurrency = fromCurrency === "USD" ? toCurrency : fromCurrency
97
-
98
- const { data, isLoading, error } = useQuery({
99
- queryKey: ["exchangeRate", targetCurrency],
100
- queryFn: async () => {
101
- // Same currency, no API call needed
102
- if (isSameCurrency) {
103
- return { value: 1 }
104
- }
105
-
106
- // Check localStorage cache first
107
- const cached = getCachedExchangeRate(targetCurrency)
108
- if (cached) {
109
- return cached
110
- }
111
-
112
- // Fetch from API if not cached
113
- const response = await trailsClient.getExchangeRate({
114
- toCurrency: targetCurrency,
115
- })
116
-
117
- // Cache the response
118
- if (response.exchangeRate) {
119
- setCachedExchangeRate(targetCurrency, response.exchangeRate)
120
- }
121
-
122
- return response.exchangeRate
123
- },
124
- enabled: !disabled && !isSameCurrency,
125
- staleTime: 5 * MINUTE_MS, // Consider React Query cache stale after 5 minutes
126
- gcTime: HOUR_MS, // Keep in React Query cache for 1 hour
127
- })
128
-
129
- // Also update localStorage when data changes from other sources
130
- useEffect(() => {
131
- if (
132
- data &&
133
- !isSameCurrency &&
134
- data.value &&
135
- "name" in data &&
136
- "symbol" in data &&
137
- "vsCurrency" in data &&
138
- "currencyType" in data
139
- ) {
140
- setCachedExchangeRate(targetCurrency, data)
141
- }
142
- }, [data, isSameCurrency, targetCurrency])
143
-
144
- // Calculate the exchange rate based on the conversion direction
145
- let exchangeRate: number | undefined
146
-
147
- if (isSameCurrency) {
148
- exchangeRate = 1
149
- } else if (data?.value) {
150
- if (fromCurrency === "USD" && toCurrency !== "USD") {
151
- // USD to another currency - use the rate directly
152
- exchangeRate = data.value
153
- } else if (fromCurrency !== "USD" && toCurrency === "USD") {
154
- // Currency to USD - invert the rate
155
- exchangeRate = 1 / data.value
156
- }
157
- }
158
-
159
- return {
160
- exchangeRate,
161
- isLoading,
162
- error: error as Error | null,
163
- }
164
- }
165
-
166
- /**
167
- * Hook to get exchange rate from USD to user's preferred display currency
168
- */
169
- export function useUsdToDisplayCurrencyRate(): UseExchangeRateResult {
170
- const { getEffectiveCurrency } = useDisplayCurrencyPreference()
171
- const displayCurrency = getEffectiveCurrency()
172
-
173
- return useExchangeRate({
174
- fromCurrency: "USD",
175
- toCurrency: displayCurrency,
176
- disabled: displayCurrency === "USD",
177
- })
178
- }
179
-
180
- /**
181
- * Hook to convert USD amount to user's preferred display currency
182
- */
183
- export function useConvertUsdToDisplayCurrency(): {
184
- convert: (usdAmount: number) => number
185
- formatAmount: (usdAmount: number) => string
186
- displayCurrency: string
187
- exchangeRate: number | undefined
188
- isLoading: boolean
189
- } {
190
- const { getEffectiveCurrency } = useDisplayCurrencyPreference()
191
- const displayCurrency = getEffectiveCurrency()
192
- const { exchangeRate, isLoading } = useUsdToDisplayCurrencyRate()
193
-
194
- const convert = (usdAmount: number): number => {
195
- if (displayCurrency === "USD" || !exchangeRate) {
196
- return usdAmount
197
- }
198
- return usdAmount * exchangeRate
199
- }
200
-
201
- const formatAmount = (usdAmount: number): string => {
202
- const convertedAmount = convert(usdAmount)
203
-
204
- // Get currency info for proper formatting
205
- const currencyInfo = getCurrencyInfo(displayCurrency)
206
-
207
- return new Intl.NumberFormat("en-US", {
208
- style: "currency",
209
- currency: displayCurrency,
210
- minimumFractionDigits: currencyInfo.decimals,
211
- maximumFractionDigits: currencyInfo.decimals,
212
- }).format(convertedAmount)
213
- }
214
-
215
- return {
216
- convert,
217
- formatAmount,
218
- displayCurrency,
219
- exchangeRate,
220
- isLoading,
221
- }
222
- }
223
-
224
- // Helper to get currency info
225
- function getCurrencyInfo(currencyCode: string): {
226
- decimals: number
227
- symbol: string
228
- } {
229
- // Currencies with 0 decimals
230
- const zeroDecimalCurrencies = ["JPY", "KRW", "VND", "CLP", "ISK"]
231
-
232
- // Default to 2 decimals for most currencies
233
- const decimals = zeroDecimalCurrencies.includes(currencyCode) ? 0 : 2
234
-
235
- // Currency symbols mapping
236
- const symbols: Record<string, string> = {
237
- USD: "$",
238
- EUR: "€",
239
- GBP: "£",
240
- JPY: "¥",
241
- CNY: "¥",
242
- KRW: "₩",
243
- INR: "₹",
244
- CAD: "C$",
245
- AUD: "A$",
246
- CHF: "CHF",
247
- SEK: "kr",
248
- NOK: "kr",
249
- DKK: "kr",
250
- // Add more as needed
251
- }
252
-
253
- return {
254
- decimals,
255
- symbol: symbols[currencyCode] || currencyCode,
256
- }
257
- }
@@ -1,66 +0,0 @@
1
- import { useQuery } from "@tanstack/react-query"
2
- import { queryPersister } from "../../query/persister.js"
3
- import { useTrailsClient } from "../../trailsClient.js"
4
- import { DAY_MS } from "../../utils/time.js"
5
- import type { FiatCurrency } from "@0xtrails/api"
6
-
7
- const CURRENCY_LIST_CACHE_KEY = "0xtrails_fiat_currencies"
8
- const CURRENCY_LIST_CACHE_DURATION = DAY_MS // 24 hours
9
-
10
- interface CachedCurrencyData {
11
- currencies: FiatCurrency[]
12
- timestamp: number
13
- }
14
-
15
- function getCachedCurrencyList(): FiatCurrency[] | null {
16
- try {
17
- const cached = localStorage.getItem(CURRENCY_LIST_CACHE_KEY)
18
- if (!cached) return null
19
-
20
- const data: CachedCurrencyData = JSON.parse(cached)
21
- const now = Date.now()
22
-
23
- if (now - data.timestamp > CURRENCY_LIST_CACHE_DURATION) {
24
- localStorage.removeItem(CURRENCY_LIST_CACHE_KEY)
25
- return null
26
- }
27
-
28
- return data.currencies
29
- } catch {
30
- return null
31
- }
32
- }
33
-
34
- function setCachedCurrencyList(currencies: FiatCurrency[]): void {
35
- try {
36
- const data: CachedCurrencyData = {
37
- currencies,
38
- timestamp: Date.now(),
39
- }
40
- localStorage.setItem(CURRENCY_LIST_CACHE_KEY, JSON.stringify(data))
41
- } catch {
42
- // Ignore localStorage errors
43
- }
44
- }
45
-
46
- export function useFiatCurrencyList() {
47
- const trailsClient = useTrailsClient()
48
-
49
- return useQuery({
50
- queryKey: ["fiatCurrencyList"],
51
- queryFn: async () => {
52
- const cached = getCachedCurrencyList()
53
- if (cached) {
54
- return cached
55
- }
56
-
57
- const response = await trailsClient.getFiatCurrencyList()
58
- const currencies = response.currencies || []
59
- setCachedCurrencyList(currencies)
60
- return currencies
61
- },
62
- staleTime: CURRENCY_LIST_CACHE_DURATION,
63
- gcTime: CURRENCY_LIST_CACHE_DURATION,
64
- persister: queryPersister.persisterFn,
65
- })
66
- }