@imtbl/sdk 1.4.0-alpha.2 → 1.4.1-alpha.1

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 (51) hide show
  1. package/dist/blockchain_data.js +2 -2
  2. package/dist/browser/checkout/BridgeWidget-cf957c15.js +1 -0
  3. package/dist/browser/checkout/OnRampWidget-83d73134.js +1 -0
  4. package/dist/browser/checkout/SaleWidget-ad8b7642.js +2 -0
  5. package/dist/browser/checkout/SpendingCapHero-0a0f9fd0.js +1 -0
  6. package/dist/browser/checkout/SwapWidget-7c0a1017.js +1 -0
  7. package/dist/browser/checkout/TopUpView-3b2e045d.js +1 -0
  8. package/dist/browser/checkout/WalletWidget-381ddb8f.js +1 -0
  9. package/dist/browser/checkout/{auto-track-1bf3a0ee.js → auto-track-8b6baf69.js} +1 -1
  10. package/dist/browser/checkout/balance-1493691b.js +1 -0
  11. package/dist/browser/checkout/index-1c33f972.js +1 -0
  12. package/dist/browser/checkout/{index-942c822d.js → index-287f0ec7.js} +1 -1
  13. package/dist/browser/checkout/{index-3272becd.js → index-531bae54.js} +1 -1
  14. package/dist/browser/checkout/{index-d9cfe478.js → index-696631eb.js} +9 -9
  15. package/dist/browser/checkout/{index-8562ab3b.js → index-b7b99467.js} +1 -1
  16. package/dist/browser/checkout/{index-9a5fbaa1.js → index-e7272f1c.js} +12 -12
  17. package/dist/browser/checkout/{index-6ee5fac7.js → index-feece362.js} +1 -1
  18. package/dist/browser/checkout/{index.umd-956dbfb2.js → index.umd-bcb0582f.js} +1 -1
  19. package/dist/browser/checkout/{retry-81ddd897.js → retry-86e4cf9a.js} +1 -1
  20. package/dist/browser/checkout/sdk.js +4 -4
  21. package/dist/browser/checkout/{useTransakEvents-8580b8ed.js → useTransakEvents-a01463cc.js} +2 -2
  22. package/dist/browser/checkout/widgets.js +1 -1
  23. package/dist/checkout.js +4 -4
  24. package/dist/config.js +1 -1
  25. package/dist/index.browser.js +4 -4
  26. package/dist/index.cjs +6 -6
  27. package/dist/index.js +6 -6
  28. package/dist/orderbook.js +1 -1
  29. package/dist/passport.js +3 -3
  30. package/dist/x.js +2 -2
  31. package/package.json +1 -1
  32. package/dist/browser/checkout/BridgeWidget-52ba2210.js +0 -2753
  33. package/dist/browser/checkout/BridgeWidget-fffec54f.js +0 -1
  34. package/dist/browser/checkout/OnRampWidget-04677711.js +0 -288
  35. package/dist/browser/checkout/OnRampWidget-b1c1cc52.js +0 -1
  36. package/dist/browser/checkout/SaleWidget-8b73504f.js +0 -1610
  37. package/dist/browser/checkout/SaleWidget-e9cc4cb2.js +0 -2
  38. package/dist/browser/checkout/SpendingCapHero-43c9cf8c.js +0 -9
  39. package/dist/browser/checkout/SpendingCapHero-af71a6f5.js +0 -1
  40. package/dist/browser/checkout/SwapWidget-45ff8dfa.js +0 -1
  41. package/dist/browser/checkout/SwapWidget-e52876ac.js +0 -1461
  42. package/dist/browser/checkout/TopUpView-590c2c4c.js +0 -365
  43. package/dist/browser/checkout/TopUpView-ff09517a.js +0 -1
  44. package/dist/browser/checkout/WalletWidget-9c4c62e4.js +0 -760
  45. package/dist/browser/checkout/WalletWidget-ed0bd774.js +0 -1
  46. package/dist/browser/checkout/balance-e5a26a9d.js +0 -1
  47. package/dist/browser/checkout/balance-e5d785aa.js +0 -182
  48. package/dist/browser/checkout/index-1405c4f4.js +0 -1
  49. package/dist/browser/checkout/index-4511315b.js +0 -5638
  50. package/dist/browser/checkout/retry-254e3478.js +0 -58
  51. package/dist/browser/checkout/useTransakEvents-54a554e5.js +0 -150
@@ -1,365 +0,0 @@
1
- import { jsx, jsxs } from 'react/jsx-runtime';
2
- import { Box, MenuItem, Heading } from '@biom3/react';
3
- import { createContext, useReducer, useEffect, useContext, useState } from 'react';
4
- import { V as ViewContext, E as EventTargetContext, u as useAnalytics, a as SimpleLayout, H as HeaderNavigation, F as FooterLogo, b as ViewActions, ae as SwapWidgetViews, o as orchestrationEvents, aq as BridgeWidgetViews, O as OnRampWidgetViews } from './index-4511315b.js';
5
- import { GasEstimateType, IMTBLWidgetEvents } from '@imtbl/checkout-sdk';
6
- import { CryptoFiat, CryptoFiatConfiguration } from '@imtbl/cryptofiat';
7
- import { useTranslation } from 'react-i18next';
8
- import { ethers } from 'ethers';
9
-
10
- var FiatSymbols;
11
- (function (FiatSymbols) {
12
- FiatSymbols["USD"] = "usd";
13
- })(FiatSymbols || (FiatSymbols = {}));
14
- const initialCryptoFiatState = {
15
- cryptoFiat: null,
16
- fiatSymbol: FiatSymbols.USD,
17
- tokenSymbols: [],
18
- conversions: new Map(),
19
- };
20
- var CryptoFiatActions;
21
- (function (CryptoFiatActions) {
22
- CryptoFiatActions["SET_CRYPTO_FIAT"] = "SET_CRYPTO_FIAT";
23
- CryptoFiatActions["SET_FIAT_SYMBOL"] = "SET_FIAT_SYMBOL";
24
- CryptoFiatActions["SET_TOKEN_SYMBOLS"] = "SET_TOKEN_SYMBOLS";
25
- CryptoFiatActions["SET_CONVERSIONS"] = "SET_CONVERSIONS";
26
- })(CryptoFiatActions || (CryptoFiatActions = {}));
27
- // eslint-disable-next-line @typescript-eslint/naming-convention
28
- const CryptoFiatContext = createContext({
29
- cryptoFiatState: initialCryptoFiatState,
30
- cryptoFiatDispatch: () => { },
31
- });
32
- const cryptoFiatReducer = (state, action) => {
33
- switch (action.payload.type) {
34
- case CryptoFiatActions.SET_CRYPTO_FIAT:
35
- return {
36
- ...state,
37
- cryptoFiat: action.payload.cryptoFiat,
38
- };
39
- case CryptoFiatActions.SET_FIAT_SYMBOL:
40
- return {
41
- ...state,
42
- fiatSymbol: action.payload.fiatSymbol,
43
- };
44
- case CryptoFiatActions.SET_TOKEN_SYMBOLS:
45
- return {
46
- ...state,
47
- tokenSymbols: action.payload.tokenSymbols,
48
- };
49
- case CryptoFiatActions.SET_CONVERSIONS:
50
- return {
51
- ...state,
52
- conversions: action.payload.conversions,
53
- };
54
- default:
55
- return state;
56
- }
57
- };
58
-
59
- const updateConversions = (cryptoToFiatResult, fiatSymbol) => {
60
- const conversionMap = new Map();
61
- // TODO: Consider using Object.keys(cryptoToFiatResult) instead of for...in
62
- // for...in includes properties from the prototype chain
63
- // eslint-disable-next-line no-restricted-syntax, guard-for-in
64
- for (const tokenSymbol in cryptoToFiatResult) {
65
- const conversion = cryptoToFiatResult[tokenSymbol];
66
- const usdAmount = conversion[fiatSymbol];
67
- if (usdAmount !== undefined) {
68
- conversionMap.set(tokenSymbol, usdAmount);
69
- }
70
- }
71
- return conversionMap;
72
- };
73
- const getCryptoToFiatConversion = async (cryptoFiat, fiatSymbol, tokenSymbols) => {
74
- try {
75
- if (tokenSymbols.length === 0)
76
- return new Map();
77
- const cryptoToFiatResult = await cryptoFiat.convert({
78
- tokenSymbols,
79
- fiatSymbol,
80
- });
81
- return updateConversions(cryptoToFiatResult, fiatSymbol);
82
- }
83
- catch (err) {
84
- return new Map();
85
- }
86
- };
87
-
88
- const DEFAULT_TOKEN_SYMBOLS = ['ETH', 'IMX'];
89
- function CryptoFiatProvider({ environment, children }) {
90
- const [cryptoFiatState, cryptoFiatDispatch] = useReducer(cryptoFiatReducer, initialCryptoFiatState);
91
- const { cryptoFiat, fiatSymbol, tokenSymbols } = cryptoFiatState;
92
- useEffect(() => {
93
- cryptoFiatDispatch({
94
- payload: {
95
- type: CryptoFiatActions.SET_CRYPTO_FIAT,
96
- cryptoFiat: new CryptoFiat(new CryptoFiatConfiguration({
97
- baseConfig: {
98
- environment,
99
- },
100
- })),
101
- },
102
- });
103
- }, []);
104
- useEffect(() => {
105
- if (!cryptoFiat || !fiatSymbol)
106
- return;
107
- (async () => {
108
- const conversions = await getCryptoToFiatConversion(cryptoFiat, fiatSymbol, [...new Set([...tokenSymbols, ...DEFAULT_TOKEN_SYMBOLS])]);
109
- cryptoFiatDispatch({
110
- payload: {
111
- type: CryptoFiatActions.SET_CONVERSIONS,
112
- conversions,
113
- },
114
- });
115
- })();
116
- }, [cryptoFiat, tokenSymbols, fiatSymbol]);
117
- return (
118
- // TODO: The object passed as the value prop to the Context provider changes every render.
119
- // To fix this consider wrapping it in a useMemo hook.
120
- // eslint-disable-next-line react/jsx-no-constructed-context-values
121
- jsx(CryptoFiatContext.Provider, { value: { cryptoFiatState, cryptoFiatDispatch }, children: children }));
122
- }
123
-
124
- const convertFeeToFiat = (fee, token, conversions) => {
125
- let feeAmountInFiat = -1;
126
- if (fee && token) {
127
- const formattedAmount = ethers.utils.formatUnits(fee, token.decimals);
128
- const gasFeeTokenConversion = conversions.get(token.symbol.toLocaleLowerCase());
129
- if (gasFeeTokenConversion) {
130
- const parsedAmount = parseFloat(formattedAmount);
131
- if (Number.isNaN(parsedAmount))
132
- return feeAmountInFiat;
133
- feeAmountInFiat = parsedAmount * gasFeeTokenConversion;
134
- }
135
- }
136
- return feeAmountInFiat;
137
- };
138
- // Formats a value to 2 decimal places unless the value is less than 0.01, in which case it will show the first non-zero digit of the decimal places
139
- function formatFiatDecimals(value) {
140
- if (value < 0) {
141
- return '-.--';
142
- }
143
- const str = value.toString();
144
- if (str.includes('e') || value === 0) {
145
- // In this scenario, converting the fee to fiat has given us an exponent from
146
- // parseFloat as the fee value is very low. If the value is low enough that converting
147
- // the fee to fiat has returned an exponent, then it is significantly low enough to
148
- // be considered essentially zero.
149
- return '0.00';
150
- }
151
- if (value < 0.01) {
152
- for (let i = 0; i < str.length; i++) {
153
- if (str[i] !== '0' && str[i] !== '.') {
154
- return value.toFixed(i - 1);
155
- }
156
- }
157
- }
158
- return value.toFixed(2);
159
- }
160
- const getOnRampFeeEstimation = (onRampFees) => {
161
- const { minPercentage, maxPercentage } = onRampFees;
162
- if (minPercentage === undefined || maxPercentage === undefined)
163
- return '-.--';
164
- return `${minPercentage}% to ${maxPercentage}`;
165
- };
166
- const getBridgeFeeEstimation = (bridgeFees, conversions) => {
167
- const { fees, token } = bridgeFees;
168
- const feeAmount = fees.totalFees;
169
- if (feeAmount === undefined)
170
- return '-.--';
171
- if (token === undefined)
172
- return '-.--';
173
- const feesInFiat = convertFeeToFiat(fees.totalFees, token, conversions);
174
- if (feesInFiat < 0)
175
- return '-.--';
176
- return formatFiatDecimals(feesInFiat);
177
- };
178
-
179
- function TopUpMenuItem({ testId, icon, heading, caption, onClick, renderFeeFunction, isDisabled, }) {
180
- return (jsx(Box, { testId: "top-up-view", sx: { paddingY: '1px' }, children: jsxs(MenuItem, { testId: `menu-item-${testId}`, size: "medium", emphasized: true, onClick: !isDisabled ? onClick : undefined, sx: isDisabled ? { opacity: '0.5', cursor: 'not-allowed' } : {}, children: [jsx(MenuItem.Icon, { icon: icon }), jsx(MenuItem.Label, { size: "medium", children: heading }), jsx(MenuItem.IntentIcon, {}), jsxs(MenuItem.Caption, { testId: `menu-item-caption-${testId}`, children: [caption, jsx("br", {}), isDisabled ? '' : renderFeeFunction('-.--', false)] })] }) }));
181
- }
182
-
183
- function TopUpView({ widgetEvent, checkout,
184
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
185
- provider, // Keep this for future use
186
- showOnrampOption, showSwapOption, showBridgeOption, tokenAddress, amount, analytics, onCloseButtonClick, onBackButtonClick, }) {
187
- const { t } = useTranslation();
188
- const { userJourney } = analytics;
189
- const { viewDispatch } = useContext(ViewContext);
190
- const { cryptoFiatState, cryptoFiatDispatch } = useContext(CryptoFiatContext);
191
- const { conversions, fiatSymbol } = cryptoFiatState;
192
- const { eventTargetState: { eventTarget } } = useContext(EventTargetContext);
193
- const [onRampFeesPercentage, setOnRampFeesPercentage] = useState('-.--');
194
- const swapFeesInFiat = '0.05';
195
- const [bridgeFeesInFiat, setBridgeFeesInFiat] = useState('-.--');
196
- const [isSwapAvailable, setIsSwapAvailable] = useState(true);
197
- const { page, track } = useAnalytics();
198
- useEffect(() => {
199
- page({
200
- userJourney,
201
- screen: 'TopUp',
202
- });
203
- }, []);
204
- useEffect(() => {
205
- if (!cryptoFiatDispatch)
206
- return;
207
- cryptoFiatDispatch({
208
- payload: {
209
- type: CryptoFiatActions.SET_TOKEN_SYMBOLS,
210
- tokenSymbols: DEFAULT_TOKEN_SYMBOLS,
211
- },
212
- });
213
- }, [cryptoFiatDispatch]);
214
- // Bridge fees estimation
215
- useEffect(() => {
216
- if (!checkout)
217
- return;
218
- (async () => {
219
- const bridgeEstimate = await checkout.gasEstimate({
220
- gasEstimateType: GasEstimateType.BRIDGE_TO_L2,
221
- });
222
- const est = await getBridgeFeeEstimation(bridgeEstimate, conversions);
223
- setBridgeFeesInFiat(est);
224
- })();
225
- }, [checkout !== undefined]);
226
- // Onramp fees estimation
227
- useEffect(() => {
228
- if (!checkout)
229
- return;
230
- (async () => {
231
- const onRampFeesEstimate = await checkout.getExchangeFeeEstimate();
232
- const onRampFees = getOnRampFeeEstimation(onRampFeesEstimate);
233
- setOnRampFeesPercentage(onRampFees);
234
- })();
235
- }, [checkout !== undefined]);
236
- // Check if swap is available
237
- useEffect(() => {
238
- if (!checkout)
239
- return;
240
- (async () => {
241
- setIsSwapAvailable(await checkout.isSwapAvailable());
242
- })();
243
- }, [checkout !== undefined]);
244
- const localTrack = (control, extras, controlType = 'Button') => {
245
- track({
246
- userJourney,
247
- screen: 'TopUp',
248
- control,
249
- controlType,
250
- extras,
251
- });
252
- };
253
- const onClickSwap = () => {
254
- if (widgetEvent === IMTBLWidgetEvents.IMTBL_SWAP_WIDGET_EVENT) {
255
- const data = {
256
- toTokenAddress: '',
257
- fromAmount: '',
258
- fromTokenAddress: '',
259
- };
260
- viewDispatch({
261
- payload: {
262
- type: ViewActions.UPDATE_VIEW,
263
- view: {
264
- type: SwapWidgetViews.SWAP,
265
- data,
266
- },
267
- },
268
- });
269
- localTrack('Swap', { ...data, widgetEvent });
270
- return;
271
- }
272
- const data = {
273
- fromTokenAddress: '',
274
- toTokenAddress: tokenAddress ?? '',
275
- amount: '',
276
- };
277
- orchestrationEvents.sendRequestSwapEvent(eventTarget, widgetEvent, data);
278
- localTrack('Swap', { ...data, widgetEvent });
279
- };
280
- const onClickBridge = () => {
281
- if (widgetEvent === IMTBLWidgetEvents.IMTBL_BRIDGE_WIDGET_EVENT) {
282
- const data = {
283
- fromTokenAddress: '',
284
- fromAmount: '',
285
- };
286
- viewDispatch({
287
- payload: {
288
- type: ViewActions.UPDATE_VIEW,
289
- view: {
290
- type: BridgeWidgetViews.WALLET_NETWORK_SELECTION,
291
- data,
292
- },
293
- },
294
- });
295
- localTrack('Bridge', { ...data, widgetEvent });
296
- return;
297
- }
298
- const data = {
299
- tokenAddress: '',
300
- amount: '',
301
- };
302
- orchestrationEvents.sendRequestBridgeEvent(eventTarget, widgetEvent, data);
303
- localTrack('Bridge', { ...data, widgetEvent });
304
- };
305
- const onClickOnRamp = () => {
306
- if (widgetEvent === IMTBLWidgetEvents.IMTBL_ONRAMP_WIDGET_EVENT) {
307
- const data = {
308
- tokenAddress: '',
309
- amount: '',
310
- };
311
- viewDispatch({
312
- payload: {
313
- type: ViewActions.UPDATE_VIEW,
314
- view: {
315
- type: OnRampWidgetViews.ONRAMP,
316
- data,
317
- },
318
- },
319
- });
320
- localTrack('OnRamp', { ...data, widgetEvent });
321
- return;
322
- }
323
- const data = {
324
- tokenAddress: tokenAddress ?? '',
325
- amount: amount ?? '',
326
- };
327
- orchestrationEvents.sendRequestOnrampEvent(eventTarget, widgetEvent, data);
328
- localTrack('OnRamp', { ...data, widgetEvent });
329
- };
330
- const renderFees = (txt) => (jsx(Box, { sx: { fontSize: 'base.text.caption.small.regular.fontSize' }, children: txt }));
331
- const topUpFeatures = [
332
- {
333
- testId: 'onramp',
334
- icon: 'Wallet',
335
- textConfigKey: 'views.TOP_UP_VIEW.topUpOptions.onramp',
336
- onClickEvent: onClickOnRamp,
337
- fee: () => renderFees(`${t('views.TOP_UP_VIEW.topUpOptions.onramp.subcaption')} ≈ ${onRampFeesPercentage}%`),
338
- isAvailable: true,
339
- isEnabled: showOnrampOption,
340
- }, {
341
- testId: 'swap',
342
- icon: 'Coins',
343
- textConfigKey: 'views.TOP_UP_VIEW.topUpOptions.swap',
344
- onClickEvent: onClickSwap,
345
- fee: () => renderFees(`${t('views.TOP_UP_VIEW.topUpOptions.swap.subcaption')} ≈ $${swapFeesInFiat} ${fiatSymbol.toUpperCase()}`),
346
- isAvailable: isSwapAvailable,
347
- isEnabled: showSwapOption,
348
- },
349
- {
350
- testId: 'bridge',
351
- icon: 'Minting',
352
- textConfigKey: 'views.TOP_UP_VIEW.topUpOptions.bridge',
353
- onClickEvent: onClickBridge,
354
- fee: () => renderFees(`${t('views.TOP_UP_VIEW.topUpOptions.bridge.subcaption')} ≈ $${bridgeFeesInFiat} ${fiatSymbol.toUpperCase()}`),
355
- isAvailable: true,
356
- isEnabled: showBridgeOption,
357
- },
358
- ];
359
- return (jsx(SimpleLayout, { header: (jsx(HeaderNavigation, { onBackButtonClick: onBackButtonClick, onCloseButtonClick: onCloseButtonClick, showBack: true })), footer: jsx(FooterLogo, {}), children: jsxs(Box, { sx: { paddingX: 'base.spacing.x4', paddingY: 'base.spacing.x4' }, children: [jsx(Heading, { size: "small", children: t('views.TOP_UP_VIEW.header.title') }), jsx(Box, { sx: { paddingY: 'base.spacing.x4' }, children: topUpFeatures
360
- .sort((a, b) => Number(b.isAvailable) - Number(a.isAvailable))
361
- .map((element) => element.isEnabled && (jsx(TopUpMenuItem, { testId: element.testId, icon: element.icon, heading: t(`${element.textConfigKey}.heading`), caption: !element.isAvailable
362
- ? t(`${element.textConfigKey}.disabledCaption`) : t(`${element.textConfigKey}.caption`), onClick: element.onClickEvent, renderFeeFunction: element.fee, isDisabled: !element.isAvailable }, t(`${element.textConfigKey}.heading`).toLowerCase()))) })] }) }));
363
- }
364
-
365
- export { CryptoFiatContext as C, TopUpView as T, CryptoFiatActions as a, CryptoFiatProvider as b };
@@ -1 +0,0 @@
1
- import{r as t,a7 as e,b9 as s,j as n,aV as o,W as i,w as a,u as r,V as c,E as d,a as l,bu as p,c as u,H as f,F as E,x as h,I as v,d as y,aN as m,z as w,bg as S,O as T}from"./index-9a5fbaa1.js";var g;!function(t){t.USD="usd"}(g||(g={}));const C={cryptoFiat:null,fiatSymbol:g.USD,tokenSymbols:[],conversions:new Map};var b;!function(t){t.SET_CRYPTO_FIAT="SET_CRYPTO_FIAT",t.SET_FIAT_SYMBOL="SET_FIAT_SYMBOL",t.SET_TOKEN_SYMBOLS="SET_TOKEN_SYMBOLS",t.SET_CONVERSIONS="SET_CONVERSIONS"}(b||(b={}));const _=t.createContext({cryptoFiatState:C,cryptoFiatDispatch:()=>{}}),O=(t,e)=>{switch(e.payload.type){case b.SET_CRYPTO_FIAT:return{...t,cryptoFiat:e.payload.cryptoFiat};case b.SET_FIAT_SYMBOL:return{...t,fiatSymbol:e.payload.fiatSymbol};case b.SET_TOKEN_SYMBOLS:return{...t,tokenSymbols:e.payload.tokenSymbols};case b.SET_CONVERSIONS:return{...t,conversions:e.payload.conversions};default:return t}};class x{baseConfig;constructor({baseConfig:t}){this.baseConfig=t}}const I={[e.SANDBOX]:"https://checkout-api.sandbox.immutable.com",[e.PRODUCTION]:"https://checkout-api.immutable.com"};class k{coinsCache;overridesCache;config;constructor(t){this.coinsCache=null,this.overridesCache=null,this.config=t.baseConfig}urlWithPath(t){return I[this.config.environment]+t}async fetchOverrides(){if(null!==this.overridesCache)return;const t=this.urlWithPath("/v1/fiat/coins/overrides"),e=await s.get(t);if(200!==e.status)throw new Error(`Error fetching coins overrides: ${e.status} ${e.statusText}`);this.overridesCache=new Map(Object.entries(e.data))}async fetchCoins(){if(null!==this.coinsCache)return;await this.fetchOverrides();const t=this.urlWithPath("/v1/fiat/coins/all"),e=await s.get(t);if(200!==e.status)throw new Error(`Error fetching coins list: ${e.status} ${e.statusText}`);const{data:n}=e;this.coinsCache=new Map;for(const t of n){const e=this.overridesCache.get(t.symbol.toLowerCase());this.coinsCache.set(t.symbol.toLowerCase(),e||t.id.toLowerCase())}}async convert({tokenSymbols:t,fiatSymbols:e=[]}){if(!t||0===t.length)throw new Error("Error missing token symbols to convert");const n=e.filter((t=>""!==t));0===n.length&&n.push("usd"),await this.fetchCoins();const o=t.map((t=>this.coinsCache.get(t.toLowerCase()))).filter((t=>""!==t&&void 0!==t)).join(","),i=n.join(",").toLowerCase(),a=this.urlWithPath(`/v1/fiat/conversion?ids=${o}&currencies=${i}`),r=await s.get(a);if(200!==r.status)throw new Error(`Error fetching prices: ${r.status} ${r.statusText}`);const{data:c}=r,d={};for(const e of t){const t=e.toLowerCase(),s=this.coinsCache.get(t);d[t]={},s&&(d[t]=c[s]||{})}return d}}const A=async(t,e,s)=>{try{if(0===s.length)return new Map;return((t,e)=>{const s=new Map;for(const n in t){const o=t[n][e];void 0!==o&&s.set(n,o)}return s})(await t.convert({tokenSymbols:s,fiatSymbol:e}),e)}catch(t){return new Map}},P=["ETH","IMX"];function F({environment:e,children:s}){const[o,i]=t.useReducer(O,C),{cryptoFiat:a,fiatSymbol:r,tokenSymbols:c}=o;return t.useEffect((()=>{i({payload:{type:b.SET_CRYPTO_FIAT,cryptoFiat:new k(new x({baseConfig:{environment:e}}))}})}),[]),t.useEffect((()=>{a&&r&&(async()=>{const t=await A(a,r,[...new Set([...c,...P])]);i({payload:{type:b.SET_CONVERSIONS,conversions:t}})})()}),[a,c,r]),n.jsx(_.Provider,{value:{cryptoFiatState:o,cryptoFiatDispatch:i},children:s})}const N=(t,e)=>{const{fees:s,token:n}=t;if(void 0===s.totalFees)return"-.--";if(void 0===n)return"-.--";const i=((t,e,s)=>{let n=-1;if(t&&e){const i=o(t,e.decimals),a=s.get(e.symbol.toLocaleLowerCase());if(a){const t=parseFloat(i);if(Number.isNaN(t))return n;n=t*a}}return n})(s.totalFees,n,e);return i<0?"-.--":function(t){if(t<0)return"-.--";const e=t.toString();if(e.includes("e")||0===t)return"0.00";if(t<.01)for(let s=0;s<e.length;s++)if("0"!==e[s]&&"."!==e[s])return t.toFixed(s-1);return t.toFixed(2)}(i)};function B({testId:t,icon:e,heading:s,caption:o,onClick:r,renderFeeFunction:c,isDisabled:d}){return n.jsx(i,{testId:"top-up-view",sx:{paddingY:"1px"},children:n.jsxs(a,{testId:`menu-item-${t}`,size:"medium",emphasized:!0,onClick:d?void 0:r,sx:d?{opacity:"0.5",cursor:"not-allowed"}:{},children:[n.jsx(a.Icon,{icon:e}),n.jsx(a.Label,{size:"medium",children:s}),n.jsx(a.IntentIcon,{}),n.jsxs(a.Caption,{testId:`menu-item-caption-${t}`,children:[o,n.jsx("br",{}),d?"":c("-.--",!1)]})]})})}function $({widgetEvent:e,checkout:s,provider:o,showOnrampOption:a,showSwapOption:g,showBridgeOption:C,tokenAddress:O,amount:x,analytics:I,onCloseButtonClick:k,onBackButtonClick:A}){const{t:F}=r(),{userJourney:$}=I,{viewDispatch:L}=t.useContext(c),{cryptoFiatState:U,cryptoFiatDispatch:W}=t.useContext(_),{conversions:j,fiatSymbol:M}=U,{eventTargetState:{eventTarget:R}}=t.useContext(d),[V,D]=t.useState("-.--"),[Y,K]=t.useState("-.--"),[z,G]=t.useState(!0),{page:q,track:J}=l();t.useEffect((()=>{q({userJourney:$,screen:"TopUp"})}),[]),t.useEffect((()=>{W&&W({payload:{type:b.SET_TOKEN_SYMBOLS,tokenSymbols:P}})}),[W]),t.useEffect((()=>{s&&(async()=>{const t=await s.gasEstimate({gasEstimateType:p.BRIDGE_TO_L2}),e=await N(t,j);K(e)})()}),[void 0!==s]),t.useEffect((()=>{s&&(async()=>{const t=(t=>{const{minPercentage:e,maxPercentage:s}=t;return void 0===e||void 0===s?"-.--":`${e}% to ${s}`})(await s.getExchangeFeeEstimate());D(t)})()}),[void 0!==s]),t.useEffect((()=>{s&&(async()=>{G(await s.isSwapAvailable())})()}),[void 0!==s]);const X=(t,e,s="Button")=>{J({userJourney:$,screen:"TopUp",control:t,controlType:s,extras:e})},H=t=>n.jsx(i,{sx:{fontSize:"base.text.caption.small.regular.fontSize"},children:t}),Q=[{testId:"onramp",icon:"Wallet",textConfigKey:"views.TOP_UP_VIEW.topUpOptions.onramp",onClickEvent:()=>{if(e===v.IMTBL_ONRAMP_WIDGET_EVENT){const t={tokenAddress:"",amount:""};return L({payload:{type:y.UPDATE_VIEW,view:{type:T.ONRAMP,data:t}}}),void X("OnRamp",{...t,widgetEvent:e})}const t={tokenAddress:O??"",amount:x??""};w.sendRequestOnrampEvent(R,e,t),X("OnRamp",{...t,widgetEvent:e})},fee:()=>H(`${F("views.TOP_UP_VIEW.topUpOptions.onramp.subcaption")} ≈ ${V}%`),isAvailable:!0,isEnabled:a},{testId:"swap",icon:"Coins",textConfigKey:"views.TOP_UP_VIEW.topUpOptions.swap",onClickEvent:()=>{if(e===v.IMTBL_SWAP_WIDGET_EVENT){const t={toTokenAddress:"",fromAmount:"",fromTokenAddress:""};return L({payload:{type:y.UPDATE_VIEW,view:{type:m.SWAP,data:t}}}),void X("Swap",{...t,widgetEvent:e})}const t={fromTokenAddress:"",toTokenAddress:O??"",amount:""};w.sendRequestSwapEvent(R,e,t),X("Swap",{...t,widgetEvent:e})},fee:()=>H(`${F("views.TOP_UP_VIEW.topUpOptions.swap.subcaption")} ≈ $0.05 ${M.toUpperCase()}`),isAvailable:z,isEnabled:g},{testId:"bridge",icon:"Minting",textConfigKey:"views.TOP_UP_VIEW.topUpOptions.bridge",onClickEvent:()=>{if(e===v.IMTBL_BRIDGE_WIDGET_EVENT){const t={fromTokenAddress:"",fromAmount:""};return L({payload:{type:y.UPDATE_VIEW,view:{type:S.WALLET_NETWORK_SELECTION,data:t}}}),void X("Bridge",{...t,widgetEvent:e})}const t={tokenAddress:"",amount:""};w.sendRequestBridgeEvent(R,e,t),X("Bridge",{...t,widgetEvent:e})},fee:()=>H(`${F("views.TOP_UP_VIEW.topUpOptions.bridge.subcaption")} ≈ $${Y} ${M.toUpperCase()}`),isAvailable:!0,isEnabled:C}];return n.jsx(u,{header:n.jsx(f,{onBackButtonClick:A,onCloseButtonClick:k,showBack:!0}),footer:n.jsx(E,{}),children:n.jsxs(i,{sx:{paddingX:"base.spacing.x4",paddingY:"base.spacing.x4"},children:[n.jsx(h,{size:"small",children:F("views.TOP_UP_VIEW.header.title")}),n.jsx(i,{sx:{paddingY:"base.spacing.x4"},children:Q.sort(((t,e)=>Number(e.isAvailable)-Number(t.isAvailable))).map((t=>t.isEnabled&&n.jsx(B,{testId:t.testId,icon:t.icon,heading:F(`${t.textConfigKey}.heading`),caption:t.isAvailable?F(`${t.textConfigKey}.caption`):F(`${t.textConfigKey}.disabledCaption`),onClick:t.onClickEvent,renderFeeFunction:t.fee,isDisabled:!t.isAvailable},F(`${t.textConfigKey}.heading`).toLowerCase())))})]})})}export{_ as C,$ as T,b as a,F as b};