@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,760 +0,0 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { createContext, useContext, useState, useEffect, useMemo, useCallback, useReducer } from 'react';
3
- import { TokenFilterTypes, IMTBLWidgetEvents, CheckoutErrorType, NetworkFilterTypes } from '@imtbl/checkout-sdk';
4
- import { V as ViewContext, b as ViewActions, W as WalletWidgetViews, C as ConnectLoaderContext, u as useAnalytics, h as formatZeroAmount, E as EventTargetContext, j as isPassportProvider, k as getL2ChainId, l as getL1ChainId, t as tokenValueFormat, U as UserJourney, o as orchestrationEvents, Z as ZERO_BALANCE_STRING, m as isNativeToken, n as sendNetworkSwitchEvent, S as SharedViews, p as sortNetworksCompareFn, q as networkIcon, r as logoColour, D as DEFAULT_BALANCE_RETRY_POLICY, w as sortTokensByAmount, x as calculateCryptoToFiat, a as SimpleLayout, H as HeaderNavigation, B as ButtonNavigationStyles, y as sendWalletWidgetCloseEvent, F as FooterLogo, z as sendDisconnectWalletEvent, A as heroBackGroundStyles, G as heroImageStyles, I as heroImageBottomAlign, c as SimpleTextBody, J as FAQS_LINK, v as viewReducer, i as initialViewState, L as LoadingView, K as ErrorView } from './index-4511315b.js';
5
- import { useTranslation } from 'react-i18next';
6
- import { Box, Body, ButtCon, MenuItem, Heading, HorizontalMenu, Button, Link } from '@biom3/react';
7
- import { C as CryptoFiatContext, a as CryptoFiatActions, b as CryptoFiatProvider, T as TopUpView } from './TopUpView-590c2c4c.js';
8
- import { r as retry, u as useInterval } from './retry-254e3478.js';
9
- import '@biom3/design-tokens';
10
- import '@imtbl/react-analytics';
11
- import 'react-dom/client';
12
- import '@ethersproject/providers';
13
- import 'i18next';
14
- import '@imtbl/config';
15
- import 'ethers';
16
- import 'i18next-browser-languagedetector';
17
- import '@imtbl/cryptofiat';
18
-
19
- const initialWalletState = {
20
- walletProviderName: null,
21
- network: null,
22
- tokenBalances: [],
23
- supportedTopUps: null,
24
- };
25
- var WalletActions;
26
- (function (WalletActions) {
27
- WalletActions["SET_WALLET_PROVIDER_NAME"] = "SET_WALLET_PROVIDER_NAME";
28
- WalletActions["SET_NETWORK"] = "SET_NETWORK";
29
- WalletActions["SET_TOKEN_BALANCES"] = "SET_TOKEN_BALANCES";
30
- WalletActions["SET_SUPPORTED_TOP_UPS"] = "SUPPORTED_TOP_UPS";
31
- })(WalletActions || (WalletActions = {}));
32
- // eslint-disable-next-line @typescript-eslint/naming-convention
33
- const WalletContext = createContext({
34
- walletState: initialWalletState,
35
- walletDispatch: () => { },
36
- });
37
- WalletContext.displayName = 'WalletContext'; // help with debugging Context in browser
38
- const walletReducer = (state, action) => {
39
- switch (action.payload.type) {
40
- case WalletActions.SET_WALLET_PROVIDER_NAME:
41
- return {
42
- ...state,
43
- walletProviderName: action.payload.walletProviderName,
44
- };
45
- case WalletActions.SET_NETWORK:
46
- return {
47
- ...state,
48
- network: action.payload.network,
49
- };
50
- case WalletActions.SET_TOKEN_BALANCES:
51
- return {
52
- ...state,
53
- tokenBalances: action.payload.tokenBalances,
54
- };
55
- case WalletActions.SET_SUPPORTED_TOP_UPS:
56
- return {
57
- ...state,
58
- supportedTopUps: {
59
- isSwapEnabled: action.payload.supportedTopUps.isSwapEnabled ?? true,
60
- isOnRampEnabled: action.payload.supportedTopUps.isOnRampEnabled ?? true,
61
- isBridgeEnabled: action.payload.supportedTopUps.isBridgeEnabled ?? true,
62
- isSwapAvailable: action.payload.supportedTopUps.isSwapAvailable ?? true,
63
- },
64
- };
65
- default:
66
- return state;
67
- }
68
- };
69
-
70
- const fetchTokenSymbols = async (checkout, chainId) => {
71
- const tokenAllowList = await checkout.getTokenAllowList({
72
- type: TokenFilterTypes.ALL,
73
- chainId,
74
- });
75
- const symbolSet = new Set();
76
- tokenAllowList.tokens.forEach((token) => {
77
- symbolSet.add(token.symbol);
78
- });
79
- return Array.from(symbolSet);
80
- };
81
-
82
- const totalTokenBalanceStyle = {
83
- display: 'flex',
84
- flexDirection: 'row',
85
- justifyContent: 'space-between',
86
- paddingX: 'base.spacing.x3',
87
- paddingY: 'base.spacing.x2',
88
- };
89
- const totalTokenBalanceValueStyle = {
90
- display: 'flex',
91
- direction: 'row',
92
- columnGap: 'base.spacing.x1',
93
- alignItems: 'center',
94
- };
95
- const coinInfoButtonStyle = {
96
- height: 'base.icon.size.250',
97
- width: 'base.icon.size.250',
98
- minWidth: 'base.icon.size.250',
99
- fill: 'base.color.accent.4',
100
- cursor: 'pointer',
101
- };
102
-
103
- function TotalTokenBalance(props) {
104
- const { t } = useTranslation();
105
- const { viewDispatch } = useContext(ViewContext);
106
- const { totalBalance, loading } = props;
107
- return (jsxs(Box, { sx: totalTokenBalanceStyle, children: [jsxs(Box, { sx: totalTokenBalanceValueStyle, children: [jsx(Body, { size: "medium", children: t('views.WALLET_BALANCES.totalTokenBalance.heading') }), jsx(Box, { sx: { pl: 'base.spacing.x1' }, children: jsx(ButtCon, { testId: "coin-info-icon", variant: "tertiary", icon: "Information", sx: coinInfoButtonStyle, onClick: () => viewDispatch({
108
- payload: {
109
- type: ViewActions.UPDATE_VIEW,
110
- view: { type: WalletWidgetViews.COIN_INFO },
111
- },
112
- }) }) })] }), jsxs(Box, { sx: totalTokenBalanceValueStyle, children: [jsx(Body, { testId: "total-token-balance-value", weight: "bold", shimmer: loading ? 1 : 0, shimmerSx: { minw: '100px' }, children: t('views.WALLET_BALANCES.totalTokenBalance.totalHeading') }), !loading && (jsxs(Body, { testId: "total-token-balance", weight: "bold", children: ["\u2248 USD $", totalBalance.toFixed(2)] }))] })] }));
113
- }
114
-
115
- const ShowMenuItem = (show) => ({
116
- display: show ? '' : 'none',
117
- });
118
-
119
- function BalanceItem({ balanceInfo, bridgeToL2OnClick, }) {
120
- const { connectLoaderState } = useContext(ConnectLoaderContext);
121
- const { track } = useAnalytics();
122
- const { checkout, provider } = connectLoaderState;
123
- const fiatAmount = `≈ USD $${formatZeroAmount(balanceInfo.fiatAmount)}`;
124
- const { walletState } = useContext(WalletContext);
125
- const { supportedTopUps, network } = walletState;
126
- const [isOnRampEnabled, setIsOnRampEnabled] = useState();
127
- const [isBridgeEnabled, setIsBridgeEnabled] = useState();
128
- const [isSwapEnabled, setIsSwapEnabled] = useState();
129
- const { eventTargetState: { eventTarget }, } = useContext(EventTargetContext);
130
- const [onRampAllowedTokens, setOnRampAllowedTokens] = useState([]);
131
- const isPassport = isPassportProvider(provider);
132
- useEffect(() => {
133
- const getOnRampAllowedTokens = async () => {
134
- if (!checkout)
135
- return;
136
- const onRampAllowedTokensResult = await checkout.getTokenAllowList({
137
- type: TokenFilterTypes.ONRAMP,
138
- chainId: getL2ChainId(checkout.config),
139
- });
140
- setOnRampAllowedTokens(onRampAllowedTokensResult.tokens);
141
- };
142
- getOnRampAllowedTokens();
143
- }, [checkout]);
144
- useEffect(() => {
145
- if (!network || !supportedTopUps || !checkout)
146
- return;
147
- const enableAddCoin = network.chainId === getL2ChainId(checkout.config)
148
- && (supportedTopUps?.isOnRampEnabled ?? true);
149
- setIsOnRampEnabled(enableAddCoin);
150
- const enableMoveCoin = (network.chainId === getL1ChainId(checkout.config)
151
- || network.chainId === getL2ChainId(checkout.config))
152
- && (supportedTopUps?.isBridgeEnabled ?? true);
153
- setIsBridgeEnabled(enableMoveCoin);
154
- const enableSwapCoin = network.chainId === getL2ChainId(checkout.config)
155
- && (supportedTopUps?.isSwapEnabled ?? true)
156
- && (supportedTopUps?.isSwapAvailable ?? true);
157
- setIsSwapEnabled(enableSwapCoin);
158
- }, [network, supportedTopUps, checkout, isPassport]);
159
- const showAddMenuItem = useMemo(() => Boolean(isOnRampEnabled
160
- && onRampAllowedTokens.length > 0
161
- && onRampAllowedTokens.find((token) => token.address?.toLowerCase() === balanceInfo.address?.toLowerCase())), [isOnRampEnabled, onRampAllowedTokens]);
162
- return (jsxs(MenuItem, { testId: `balance-item-${balanceInfo.symbol}`, emphasized: true, children: [jsx(MenuItem.FramedIcon, { icon: "Coins", circularFrame: true }), jsx(MenuItem.Label, { children: balanceInfo.symbol }), jsx(MenuItem.Caption, { children: balanceInfo.description }), jsx(MenuItem.PriceDisplay, { testId: `balance-item-${balanceInfo.symbol}`, use: jsx(Heading, { size: "xSmall" }), price: tokenValueFormat(balanceInfo.balance), fiatAmount: fiatAmount }), (isOnRampEnabled || isSwapEnabled || isBridgeEnabled) && (jsxs(MenuItem.OverflowPopoverMenu, { size: "small", testId: "token-menu", onClick: () => {
163
- track({
164
- userJourney: UserJourney.WALLET,
165
- screen: 'WalletBalances',
166
- control: 'BalanceItem',
167
- controlType: 'Button',
168
- extras: {
169
- tokenSymbol: balanceInfo.symbol,
170
- tokenAddress: balanceInfo.address,
171
- },
172
- });
173
- }, children: [jsxs(MenuItem, { testId: "balance-item-add-option", sx: ShowMenuItem(showAddMenuItem), onClick: () => {
174
- track({
175
- userJourney: UserJourney.WALLET,
176
- screen: 'WalletBalances',
177
- control: 'AddTokens',
178
- controlType: 'Button',
179
- extras: {
180
- tokenSymbol: balanceInfo.symbol,
181
- tokenAddress: balanceInfo.address,
182
- },
183
- });
184
- orchestrationEvents.sendRequestOnrampEvent(eventTarget, IMTBLWidgetEvents.IMTBL_WALLET_WIDGET_EVENT, {
185
- tokenAddress: balanceInfo.address ?? '',
186
- amount: '',
187
- });
188
- }, children: [jsx(MenuItem.Icon, { icon: "Add" }), jsx(MenuItem.Label, { children: `Add ${balanceInfo.symbol}` })] }), jsxs(MenuItem, { testId: "balance-item-swap-option", sx: ShowMenuItem(isSwapEnabled), onClick: () => {
189
- track({
190
- userJourney: UserJourney.WALLET,
191
- screen: 'WalletBalances',
192
- control: 'SwapTokens',
193
- controlType: 'Button',
194
- extras: {
195
- tokenSymbol: balanceInfo.symbol,
196
- tokenAddress: balanceInfo.address,
197
- },
198
- });
199
- orchestrationEvents.sendRequestSwapEvent(eventTarget, IMTBLWidgetEvents.IMTBL_WALLET_WIDGET_EVENT, {
200
- fromTokenAddress: balanceInfo.address ?? '',
201
- toTokenAddress: '',
202
- amount: '',
203
- });
204
- }, children: [jsx(MenuItem.Icon, { icon: "Exchange" }), jsx(MenuItem.Label, { children: `Swap ${balanceInfo.symbol}` })] }), jsxs(MenuItem, { testId: "balance-item-move-option", sx: ShowMenuItem(isBridgeEnabled), onClick: () => {
205
- track({
206
- userJourney: UserJourney.WALLET,
207
- screen: 'WalletBalances',
208
- control: 'MoveTokens',
209
- controlType: 'Button',
210
- extras: {
211
- tokenSymbol: balanceInfo.symbol,
212
- tokenAddress: balanceInfo.address,
213
- },
214
- });
215
- bridgeToL2OnClick(balanceInfo.address);
216
- }, children: [jsx(MenuItem.Icon, { icon: "Minting" }), jsx(MenuItem.Label, { children: `Move ${balanceInfo.symbol}` })] })] }))] }));
217
- }
218
-
219
- const tokenBalanceListStyle = {
220
- width: '100%',
221
- height: '100%',
222
- display: 'flex',
223
- flexDirection: 'column',
224
- rowGap: 'base.spacing.x2',
225
- };
226
- const noTokensStyle = {
227
- width: '100%',
228
- height: '100%',
229
- display: 'flex',
230
- justifyContent: 'center',
231
- alignItems: 'center',
232
- };
233
-
234
- const filterZeroBalances = (balanceInfoItems) => balanceInfoItems.filter((balance) => balance.balance !== ZERO_BALANCE_STRING || isNativeToken(balance.address));
235
- function TokenBalanceList({ balanceInfoItems, bridgeToL2OnClick, }) {
236
- const { t } = useTranslation();
237
- const filteredBalances = filterZeroBalances(balanceInfoItems);
238
- return (jsxs(Box, { sx: tokenBalanceListStyle, children: [filteredBalances.length === 0
239
- && (jsx(Box, { sx: noTokensStyle, children: jsx(Body, { testId: "no-tokens-found", children: t('views.WALLET_BALANCES.tokenBalancesList.noTokensFound') }) })), filteredBalances.map((balance) => (jsx(BalanceItem, { balanceInfo: balance, bridgeToL2OnClick: bridgeToL2OnClick }, balance.id)))] }));
240
- }
241
-
242
- const networkMenuStyles = {
243
- display: 'flex',
244
- flexDirection: 'column',
245
- alignItems: 'flex-start',
246
- paddingTop: 'base.spacing.x4',
247
- };
248
- const activeNetworkButtonStyle = {
249
- fontWeight: 'base.text.caption.small.bold.fontWeight',
250
- borderColor: 'base.color.translucent.emphasis.1000',
251
- borderStyle: 'solid',
252
- borderWidth: 'base.border.size.200',
253
- };
254
- const networkButtonStyle = {
255
- fontWeight: 'base.text.caption.small.bold.fontWeight',
256
- };
257
- const logoStyle = (logoColor, isActive) => ({
258
- paddingRight: 'base.spacing.x1',
259
- width: '22px',
260
- fill: isActive ? logoColor : 'base.color.brand.4',
261
- });
262
- const networkHeadingStyle = {
263
- paddingX: 'base.spacing.x3',
264
- paddingY: 'base.spacing.x2',
265
- };
266
-
267
- function NetworkMenu() {
268
- const { t } = useTranslation();
269
- const { connectLoaderState } = useContext(ConnectLoaderContext);
270
- const { eventTargetState: { eventTarget } } = useContext(EventTargetContext);
271
- const { checkout, provider } = connectLoaderState;
272
- const { viewDispatch } = useContext(ViewContext);
273
- const { walletState, walletDispatch } = useContext(WalletContext);
274
- const { network } = walletState;
275
- const [allowedNetworks, setNetworks] = useState([]);
276
- const { track } = useAnalytics();
277
- const switchNetwork = useCallback(async (chainId) => {
278
- if (!checkout || !provider || !network || network.chainId === chainId)
279
- return;
280
- track({
281
- userJourney: UserJourney.WALLET,
282
- screen: 'WalletBalances',
283
- control: 'SwitchNetwork',
284
- controlType: 'Button',
285
- extras: {
286
- chainId,
287
- },
288
- });
289
- try {
290
- const switchNetworkResult = await checkout.switchNetwork({
291
- provider,
292
- chainId,
293
- });
294
- sendNetworkSwitchEvent(eventTarget, switchNetworkResult.provider, switchNetworkResult.network);
295
- }
296
- catch (err) {
297
- if (err.type === CheckoutErrorType.USER_REJECTED_REQUEST_ERROR) ;
298
- else {
299
- viewDispatch({
300
- payload: {
301
- type: ViewActions.UPDATE_VIEW,
302
- view: { type: SharedViews.ERROR_VIEW, error: err },
303
- },
304
- });
305
- }
306
- }
307
- }, [checkout, provider, network, walletDispatch, viewDispatch]);
308
- useEffect(() => {
309
- (async () => {
310
- if (checkout) {
311
- const allowedNetworksResponse = await checkout.getNetworkAllowList({
312
- type: NetworkFilterTypes.ALL,
313
- });
314
- setNetworks(allowedNetworksResponse?.networks ?? []);
315
- }
316
- else {
317
- setNetworks([]);
318
- }
319
- })();
320
- }, [checkout]);
321
- return (jsxs(Box, { testId: "network-menu", sx: networkMenuStyles, children: [jsx(Body, { testId: "network-heading", size: "medium", sx: networkHeadingStyle, children: t('views.WALLET_BALANCES.networkStatus.heading') }), jsx(HorizontalMenu, { children: checkout
322
- && allowedNetworks
323
- ?.sort((a, b) => sortNetworksCompareFn(a, b, checkout.config))
324
- .map((networkItem) => (jsxs(HorizontalMenu.Button, { testId: `${networkItem.name}-network-button`, sx: networkItem.chainId === network?.chainId
325
- ? activeNetworkButtonStyle
326
- : networkButtonStyle, size: "small", onClick: () => switchNetwork(networkItem.chainId), children: [jsx(Button.Icon, { icon: networkIcon[networkItem.chainId], iconVariant: "bold", sx: logoStyle(logoColour[networkItem.chainId], networkItem.chainId === network?.chainId) }), networkItem.name] }, networkItem.chainId))) })] }));
327
- }
328
-
329
- const walletBalanceOuterContainerStyles = {
330
- display: 'flex',
331
- flexDirection: 'column',
332
- rowGap: 'base.spacing.x2',
333
- paddingX: 'base.spacing.x2',
334
- flex: 1,
335
- };
336
- const walletBalanceContainerStyles = {
337
- backgroundColor: 'base.color.neutral.800',
338
- paddingX: 'base.spacing.x1',
339
- borderRadius: 'base.borderRadius.x6',
340
- flex: 1,
341
- };
342
- const walletBalanceLoadingIconStyles = {
343
- display: 'flex',
344
- flexDirection: 'column',
345
- rowGap: 'base.spacing.x2',
346
- };
347
- const walletBalanceListContainerStyles = (showNetworkMenu, showAddCoins) => {
348
- /**
349
- * Need fixed height set to enable vertical scrolling within div
350
- * */
351
- let height = 460;
352
- if (showNetworkMenu) {
353
- height -= 104; // - network menu height
354
- }
355
- if (showAddCoins) {
356
- height -= 98; // - add coins button height
357
- }
358
- const heightpx = `${height}px`;
359
- return {
360
- height: heightpx,
361
- overflowY: 'auto',
362
- borderRadius: 'base.borderRadius.x6',
363
- };
364
- };
365
-
366
- const getTokenBalances = async (checkout, provider, chainId) => {
367
- if (!checkout || !provider || !chainId)
368
- return [];
369
- const walletAddress = await provider.getSigner().getAddress();
370
- // Do not catch the error so that the caller can decide
371
- // how to handle the experience.
372
- const getAllBalancesResult = await retry(() => checkout.getAllBalances({
373
- provider,
374
- walletAddress,
375
- chainId,
376
- }), DEFAULT_BALANCE_RETRY_POLICY);
377
- if (!getAllBalancesResult)
378
- return [];
379
- const sortedTokens = sortTokensByAmount(checkout.config, getAllBalancesResult.balances, chainId);
380
- return sortedTokens;
381
- };
382
- const formatTokenId = (chainId, symbol, address) => {
383
- if (!address)
384
- return `${chainId.toString()}-${symbol.toLowerCase()}`;
385
- return `${chainId.toString()}-${symbol.toLowerCase()}-${address.toLowerCase()}`;
386
- };
387
- const mapTokenBalancesWithConversions = (chainId, balances, conversions) => balances.map((balance) => ({
388
- id: formatTokenId(chainId, balance.token.symbol, balance.token.address),
389
- balance: balance.formattedBalance,
390
- fiatAmount: calculateCryptoToFiat(balance.formattedBalance, balance.token.symbol, conversions),
391
- symbol: balance.token.symbol,
392
- address: balance.token.address,
393
- description: balance.token.name,
394
- }));
395
-
396
- function WalletBalances({ balancesLoading, }) {
397
- const { t } = useTranslation();
398
- const { connectLoaderState } = useContext(ConnectLoaderContext);
399
- const { checkout, provider } = connectLoaderState;
400
- const { cryptoFiatState, cryptoFiatDispatch } = useContext(CryptoFiatContext);
401
- const { walletState } = useContext(WalletContext);
402
- const { eventTargetState: { eventTarget } } = useContext(EventTargetContext);
403
- const { viewDispatch } = useContext(ViewContext);
404
- const [totalFiatAmount, setTotalFiatAmount] = useState(0.0);
405
- const { network, supportedTopUps, tokenBalances, } = walletState;
406
- const { conversions } = cryptoFiatState;
407
- const isPassport = isPassportProvider(provider);
408
- const showNetworkMenu = !isPassport;
409
- const { track, page } = useAnalytics();
410
- const balanceInfos = useMemo(() => mapTokenBalancesWithConversions(network?.chainId, tokenBalances, conversions), [tokenBalances, conversions, network?.chainId]);
411
- useEffect(() => {
412
- page({
413
- userJourney: UserJourney.WALLET,
414
- screen: 'WalletBalances',
415
- });
416
- }, []);
417
- useEffect(() => {
418
- (async () => {
419
- if (!checkout)
420
- return;
421
- if (!cryptoFiatDispatch)
422
- return;
423
- if (!network)
424
- return;
425
- const tokenSymbols = await fetchTokenSymbols(checkout, network.chainId);
426
- cryptoFiatDispatch({
427
- payload: {
428
- type: CryptoFiatActions.SET_TOKEN_SYMBOLS,
429
- tokenSymbols,
430
- },
431
- });
432
- })();
433
- }, [checkout, cryptoFiatDispatch, network?.chainId]);
434
- useEffect(() => {
435
- let totalAmount = 0.0;
436
- balanceInfos.forEach((balance) => {
437
- const fiatAmount = parseFloat(balance.fiatAmount);
438
- if (!Number.isNaN(fiatAmount))
439
- totalAmount += fiatAmount;
440
- });
441
- setTotalFiatAmount(totalAmount);
442
- }, [balanceInfos]);
443
- const showAddCoins = useMemo(() => {
444
- if (!checkout || !network)
445
- return false;
446
- return (network.chainId === getL2ChainId(checkout.config)
447
- && Boolean(supportedTopUps?.isBridgeEnabled
448
- || supportedTopUps?.isSwapEnabled
449
- || supportedTopUps?.isOnRampEnabled));
450
- }, [checkout, network, supportedTopUps]);
451
- const handleAddCoinsClick = () => {
452
- track({
453
- userJourney: UserJourney.WALLET,
454
- screen: 'WalletBalances',
455
- control: 'AddCoins',
456
- controlType: 'Button',
457
- });
458
- viewDispatch({
459
- payload: {
460
- type: ViewActions.UPDATE_VIEW,
461
- view: { type: SharedViews.TOP_UP_VIEW },
462
- },
463
- });
464
- };
465
- const handleBridgeToL2OnClick = (address) => {
466
- orchestrationEvents.sendRequestBridgeEvent(eventTarget, IMTBLWidgetEvents.IMTBL_WALLET_WIDGET_EVENT, {
467
- tokenAddress: address ?? '',
468
- amount: '',
469
- });
470
- };
471
- return (jsx(SimpleLayout, { testId: "wallet-balances", header: (jsx(HeaderNavigation, { title: t('views.WALLET_BALANCES.header.title'), rightActions: (jsx(ButtCon, { icon: "SettingsCog", sx: ButtonNavigationStyles(), iconVariant: "bold", onClick: () => {
472
- track({
473
- userJourney: UserJourney.WALLET,
474
- screen: 'WalletBalances',
475
- control: 'Settings',
476
- controlType: 'Button',
477
- });
478
- viewDispatch({
479
- payload: {
480
- type: ViewActions.UPDATE_VIEW,
481
- view: { type: WalletWidgetViews.SETTINGS },
482
- },
483
- });
484
- }, testId: "settings-button" })), onCloseButtonClick: () => sendWalletWidgetCloseEvent(eventTarget) })), footer: jsx(FooterLogo, {}), children: jsxs(Box, { sx: walletBalanceOuterContainerStyles, children: [jsxs(Box, { sx: walletBalanceContainerStyles, children: [showNetworkMenu && jsx(NetworkMenu, {}), jsx(TotalTokenBalance, { totalBalance: totalFiatAmount, loading: balancesLoading }), jsxs(Box, { sx: walletBalanceListContainerStyles(showNetworkMenu, showAddCoins), children: [balancesLoading && (jsxs(Box, { sx: walletBalanceLoadingIconStyles, children: [jsx(MenuItem, { shimmer: true, emphasized: true, testId: "balance-item-shimmer--1" }), jsx(MenuItem, { shimmer: true, emphasized: true, testId: "balance-item-shimmer--2" }), jsx(MenuItem, { shimmer: true, emphasized: true, testId: "balance-item-shimmer--3" })] })), !balancesLoading && (jsx(TokenBalanceList, { balanceInfoItems: balanceInfos, bridgeToL2OnClick: handleBridgeToL2OnClick }))] })] }), showAddCoins && (jsxs(MenuItem, { testId: "add-coins", emphasized: true, onClick: handleAddCoinsClick, children: [jsx(MenuItem.FramedIcon, { icon: "Add" }), jsx(MenuItem.Label, { children: t('views.WALLET_BALANCES.addCoins') })] }))] }) }));
485
- }
486
-
487
- const walletAddressContainerStyle = {
488
- width: '100%',
489
- height: '88px',
490
- display: 'flex',
491
- flexDirection: 'row',
492
- justifyContent: 'space-between',
493
- padding: '24px 11px 24px 32px',
494
- backgroundColor: 'base.color.translucent.emphasis.400',
495
- borderRadius: 'base.borderRadius.x6',
496
- };
497
- const walletAddressLayoutStyle = {
498
- width: '100%',
499
- display: 'flex',
500
- };
501
- const walletAddressTextLayoutStyle = {
502
- width: '318px',
503
- display: 'flex',
504
- flexDirection: 'column',
505
- };
506
- const truncatedTextStyle = {
507
- overflow: 'hidden',
508
- textOverflow: 'ellipsis',
509
- whiteSpace: 'nowrap',
510
- };
511
-
512
- const isCopiedStyle = {
513
- background: 'base.color.status.success.bright',
514
- fill: 'base.color.status.success.bright',
515
- };
516
-
517
- function CopyButton({ textToCopy, }) {
518
- const [isCopied, setIsCopied] = useState(false);
519
- const { track } = useAnalytics();
520
- const handleCopy = () => {
521
- if (textToCopy != null) {
522
- track({
523
- userJourney: UserJourney.WALLET,
524
- screen: 'Settings',
525
- control: 'CopyWalletAddress',
526
- controlType: 'Button',
527
- });
528
- navigator.clipboard.writeText(textToCopy);
529
- }
530
- setIsCopied(true);
531
- setTimeout(() => {
532
- setIsCopied(false);
533
- }, 3000);
534
- };
535
- return (jsx(Box, { children: textToCopy && (jsx(Box, { sx: {
536
- cursor: 'pointer',
537
- }, children: jsx(ButtCon, { sx: isCopied
538
- ? isCopiedStyle
539
- : {}, onClick: handleCopy, size: "small", icon: isCopied ? 'Tick' : 'CopyText' }) })) }));
540
- }
541
-
542
- function WalletAddress({ provider }) {
543
- const [walletAddress, setWalletAddress] = useState('');
544
- useEffect(() => {
545
- if (!provider)
546
- return;
547
- (async () => {
548
- const address = await provider.getSigner().getAddress();
549
- setWalletAddress(address);
550
- })();
551
- }, [provider]);
552
- return (jsx(Box, { sx: walletAddressContainerStyle, children: jsxs(Box, { sx: walletAddressLayoutStyle, children: [jsxs(Box, { sx: walletAddressTextLayoutStyle, children: [jsx(Heading, { size: "xSmall", children: "Wallet address" }), jsx(Body, { testId: "wallet-address", size: "xSmall", sx: truncatedTextStyle, children: walletAddress })] }), jsx(CopyButton, { textToCopy: walletAddress })] }) }));
553
- }
554
-
555
- const settingsBoxStyle = {
556
- display: 'flex',
557
- flexDirection: 'column',
558
- rowGap: 'base.spacing.x2',
559
- marginX: 'base.spacing.x2',
560
- };
561
- const settingsDisconnectButtonStyle = { marginTop: '32px' };
562
-
563
- function Settings() {
564
- const { t } = useTranslation();
565
- const { connectLoaderState } = useContext(ConnectLoaderContext);
566
- const { provider } = connectLoaderState;
567
- const { eventTargetState: { eventTarget } } = useContext(EventTargetContext);
568
- const { page } = useAnalytics();
569
- useEffect(() => {
570
- page({
571
- userJourney: UserJourney.WALLET,
572
- screen: 'Settings',
573
- });
574
- }, []);
575
- return (jsx(SimpleLayout, { testId: "wallet-balances", header: (jsx(HeaderNavigation, { showBack: true, title: t('views.SETTINGS.header.title'), onCloseButtonClick: () => sendWalletWidgetCloseEvent(eventTarget) })), footer: jsx(FooterLogo, {}), children: jsxs(Box, { sx: settingsBoxStyle, children: [jsx(WalletAddress, { provider: provider }), jsx(Button, { testId: "disconnect-button", variant: "secondary", sx: settingsDisconnectButtonStyle, onClick: () => sendDisconnectWalletEvent(eventTarget), children: t('views.SETTINGS.disconnectButton.label') })] }) }));
576
- }
577
-
578
- function IMXCoinsHero() {
579
- return (jsx(Box, { sx: { ...heroBackGroundStyles, background: 'base.color.translucent.emphasis.100' }, children: jsx(Box, { sx: { ...heroImageStyles, ...heroImageBottomAlign }, children: jsxs("svg", { width: "430", height: "211", viewBox: "0 0 430 211", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [jsx("path", { d: "M213 120C132.857 120 65.7181 139.009 1 175.641V211H431V178.515C365.165 140.107 295.216 120 213 120Z", fill: "url(#paint0_linear_4525_125520)" }), jsx("path", { d: "M428.5 210.5H383C383 123 114 113.5 236 120.5C333.6 126.1 405 163.833 428.5 182V210.5Z", fill: "#2D0034", fillOpacity: "0.2" }), jsx("path", { d: "M131.005 34.0566L130.576 32.4244L128.944 32.8537L129.373 34.4858L131.005 34.0566Z", fill: "white" }), jsx("path", { d: "M77.1152 45.7678L76.5627 43.6667L74.4617 44.2193L75.0142 46.3203L77.1152 45.7678Z", fill: "white" }), jsx("path", { d: "M264.238 30.1945L262.093 29.8494L261.748 31.9942L263.893 32.3394L264.238 30.1945Z", fill: "white" }), jsx("path", { d: "M348.157 2.3323L348.776 1.04626L347.49 0.427149L346.871 1.71319L348.157 2.3323Z", fill: "white" }), jsx("path", { d: "M342.606 56.5062L342.054 54.4052L339.953 54.9577L340.505 57.0587L342.606 56.5062Z", fill: "white" }), jsx("path", { d: "M348.381 55.0847L349 53.7986L347.714 53.1795L347.095 54.4656L348.381 55.0847Z", fill: "white" }), jsx("path", { d: "M107.606 18.8096L106.681 17.7229L105.594 18.6483L106.52 19.735L107.606 18.8096Z", fill: "white" }), jsx("path", { d: "M233.14 2.3323L233.759 1.04626L232.473 0.427149L231.854 1.71319L233.14 2.3323Z", fill: "white" }), jsx("path", { d: "M2.97844e-07 176.149C62.5366 139.802 135.143 119 212.584 119C292.029 119 366.384 140.892 430 179", stroke: "black" }), jsx("path", { d: "M70.97 142.773C76.3142 146.15 87.6289 137.839 96.242 124.208C104.855 110.578 107.505 96.7911 102.161 93.414C96.8167 90.037 85.5021 98.3487 76.889 111.979C68.2758 125.609 65.6258 139.396 70.97 142.773Z", fill: "#F191FA", stroke: "black", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M76.8602 112.001C79.353 108.055 82.0686 104.564 84.8088 101.664L94.3989 126.977C86.0698 138.949 75.925 145.933 70.9515 142.793C65.6033 139.413 68.2536 125.631 76.8692 111.994L76.8602 112.001Z", fill: "black" }), jsx("path", { d: "M96.2211 124.237C104.836 110.608 107.486 96.8249 102.138 93.4455L109.009 97.785C114.357 101.164 111.707 114.947 103.092 128.576C94.4778 142.205 83.1639 150.512 77.8146 147.141L70.9434 142.801C76.2916 146.181 87.6066 137.866 96.2211 124.237Z", fill: "#D8EFF4", stroke: "black", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M98.2141 120.884C99.3274 118.901 100.309 116.925 101.153 115.003L108.025 119.342C107.181 121.264 106.2 123.233 105.085 125.224L98.2141 120.884Z", fill: "#F191FA" }), jsx("path", { d: "M102.311 112.191C104.156 107.325 105.052 102.898 104.877 99.4899L111.748 103.829C111.923 107.238 111.035 111.665 109.182 116.531L102.311 112.191Z", fill: "black" }), jsx("path", { d: "M96.2211 124.237C104.836 110.608 107.486 96.8249 102.138 93.4455L109.009 97.785C114.357 101.164 111.707 114.947 103.092 128.576C94.4778 142.205 83.1639 150.512 77.8146 147.141L70.9434 142.801C76.2916 146.181 87.6066 137.866 96.2211 124.237Z", stroke: "black", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M341.833 142.899C353.278 131.542 356.039 115.768 348 107.668C339.962 99.5669 324.167 102.207 312.723 113.564C301.278 124.921 298.517 140.695 306.555 148.795C314.594 156.896 330.388 154.256 341.833 142.899Z", fill: "#F191FA", stroke: "black", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M341.813 142.853C353.26 131.495 356.014 115.719 347.977 107.616L352.129 111.801C360.166 119.903 357.412 135.68 345.965 147.037C334.519 158.395 318.726 161.037 310.688 152.934L306.536 148.75C314.574 156.852 330.375 154.211 341.813 142.853Z", fill: "#96DAF4", stroke: "black", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M344.451 139.969C345.913 138.216 347.189 136.39 348.264 134.524L352.416 138.709C351.341 140.575 350.065 142.4 348.603 144.153L344.451 139.969Z", fill: "#D8EFF4" }), jsx("path", { d: "M349.72 131.746C352.022 126.818 352.967 121.785 352.442 117.302L356.594 121.486C357.119 125.97 356.174 131.002 353.872 135.93L349.72 131.746Z", fill: "black" }), jsx("path", { d: "M341.813 142.853C353.26 131.495 356.014 115.719 347.977 107.616L352.129 111.801C360.166 119.903 357.412 135.68 345.965 147.037C334.519 158.395 318.726 161.037 310.688 152.934L306.536 148.75C314.574 156.852 330.375 154.211 341.813 142.853Z", stroke: "black", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M155.769 157.057C169.703 165.169 185.654 163.751 191.396 153.888C197.138 144.026 190.497 129.454 176.563 121.342C162.629 113.229 146.679 114.648 140.937 124.51C135.195 134.373 141.836 148.944 155.769 157.057Z", fill: "#F191FA", stroke: "black", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M155.809 157.026C169.744 165.14 185.695 163.714 191.439 153.852L188.473 158.946C182.729 168.808 166.778 170.234 152.843 162.12C138.908 154.006 132.266 139.436 138.01 129.574L140.976 124.48C135.232 134.342 141.876 148.919 155.809 157.026Z", fill: "#96DAF4", stroke: "black", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M159.278 158.826C161.349 159.785 163.443 160.544 165.524 161.099L162.558 166.193C160.477 165.639 158.383 164.879 156.311 163.921L159.278 158.826Z", fill: "#D8EFF4" }), jsx("path", { d: "M168.585 161.786C173.941 162.733 179.047 162.342 183.241 160.674L180.275 165.768C176.08 167.436 170.975 167.827 165.619 166.88L168.585 161.786Z", fill: "black" }), jsx("path", { d: "M155.809 157.026C169.744 165.14 185.695 163.714 191.439 153.852L188.473 158.946C182.729 168.808 166.778 170.234 152.843 162.12C138.908 154.006 132.266 139.436 138.01 129.574L140.976 124.48C135.232 134.342 141.876 148.919 155.809 157.026Z", stroke: "black", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M234.03 133.525C249.631 129.452 260.983 121.192 259.386 115.075C257.79 108.959 243.848 107.301 228.248 111.374C212.647 115.446 201.294 123.706 202.891 129.823C204.488 135.94 218.429 137.597 234.03 133.525Z", fill: "#F191FA", stroke: "black", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M234.031 133.533C249.63 129.462 260.98 121.198 259.388 115.083L261.44 122.943C263.04 129.058 251.682 137.322 236.083 141.393C220.484 145.464 206.542 143.808 204.942 137.685L202.89 129.825C204.49 135.94 218.433 137.604 234.031 133.533Z", fill: "#D8EFF4", stroke: "black", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M237.663 132.44C239.836 131.754 241.896 130.986 243.826 130.154L245.878 138.014C243.948 138.838 241.888 139.606 239.715 140.3L237.663 132.44Z", fill: "#F191FA" }), jsx("path", { d: "M246.588 128.896C251.257 126.601 254.941 123.976 257.13 121.367L259.182 129.227C256.985 131.836 253.309 134.461 248.64 136.756L246.588 128.896Z", fill: "black" }), jsx("path", { d: "M234.031 133.533C249.63 129.462 260.98 121.198 259.388 115.083L261.44 122.943C263.04 129.058 251.682 137.322 236.083 141.393C220.484 145.464 206.542 143.808 204.942 137.685L202.89 129.825C204.49 135.94 218.433 137.604 234.031 133.533Z", stroke: "black", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M189.995 60.1335C175.063 54.0502 161.025 53.8648 158.64 59.7194C156.255 65.5739 166.426 75.2515 181.358 81.3348C196.29 87.418 210.328 87.6034 212.713 81.7488C215.098 75.8943 204.927 66.2167 189.995 60.1335Z", fill: "#F191FA", stroke: "black", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M181.375 81.3031C196.307 87.3891 210.345 87.5729 212.731 81.7174L209.667 89.2437C207.281 95.0992 193.243 94.9154 178.311 88.8293C163.379 82.7433 153.208 73.0653 155.594 67.2098L158.658 59.6835C156.272 65.5391 166.443 75.217 181.375 81.3031Z", fill: "#D8EFF4", stroke: "black", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M185.032 82.6694C187.186 83.4191 189.294 84.0389 191.339 84.5366L188.275 92.0629C186.23 91.5652 184.122 90.9454 181.968 90.1957L185.032 82.6694Z", fill: "#96DAF4" }), jsx("path", { d: "M194.301 85.1776C199.418 86.1391 203.932 86.2438 207.256 85.4671L204.192 92.9934C200.868 93.762 196.353 93.6654 191.237 92.7038L194.301 85.1776Z", fill: "black" }), jsx("path", { d: "M181.375 81.3031C196.307 87.3891 210.345 87.5729 212.731 81.7174L209.667 89.2437C207.281 95.0992 193.243 94.9154 178.311 88.8293C163.379 82.7433 153.208 73.0653 155.594 67.2098L158.658 59.6835C156.272 65.5391 166.443 75.217 181.375 81.3031Z", stroke: "black", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M331.022 121.427C326.722 126.062 313.654 120.93 301.833 109.965C290.012 99 283.915 86.3538 288.214 81.719C292.513 77.0841 305.581 82.2158 317.402 93.1808C329.223 104.146 335.321 116.792 331.022 121.427Z", fill: "#F191FA", stroke: "black", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M317.436 93.1948C314.014 90.0206 310.494 87.3431 307.102 85.2426L304.325 112.168C315.446 121.604 327.043 125.752 331.044 121.441C335.347 116.803 329.25 104.162 317.425 93.1905L317.436 93.1948Z", fill: "black" }), jsx("path", { d: "M301.861 109.987C290.039 99.0235 283.942 86.3817 288.244 81.7437L282.716 87.7004C278.413 92.3385 284.51 104.98 296.332 115.944C308.154 126.907 321.22 132.035 325.526 127.404L331.054 121.447C326.752 126.085 313.683 120.951 301.861 109.987Z", fill: "#D8EFF4", stroke: "black", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("path", { d: "M299.075 107.258C297.49 105.627 296.034 103.969 294.725 102.327L289.197 108.284C290.506 109.926 291.959 111.577 293.546 113.215L299.075 107.258Z", fill: "#F191FA" }), jsx("path", { d: "M292.885 99.9066C289.854 95.6761 287.853 91.6272 287.147 88.2883L281.619 94.2451C282.324 97.584 284.318 101.636 287.357 105.863L292.885 99.9066Z", fill: "black" }), jsx("path", { d: "M301.861 109.987C290.039 99.0235 283.942 86.3817 288.244 81.7437L282.716 87.7004C278.413 92.3385 284.51 104.98 296.332 115.944C308.154 126.907 321.22 132.035 325.526 127.404L331.054 121.447C326.752 126.085 313.683 120.951 301.861 109.987Z", stroke: "black", strokeLinecap: "round", strokeLinejoin: "round" }), jsx("defs", { children: jsxs("linearGradient", { id: "paint0_linear_4525_125520", x1: "191", y1: "124.403", x2: "247.716", y2: "304.676", gradientUnits: "userSpaceOnUse", children: [jsx("stop", { stopColor: "#AD48BA" }), jsx("stop", { offset: "0.65625", stopColor: "#D178FF", stopOpacity: "0.24" })] }) })] }) }) }));
580
- }
581
-
582
- function CoinInfo() {
583
- const { t } = useTranslation();
584
- const { connectLoaderState: { provider } } = useContext(ConnectLoaderContext);
585
- const isPassport = isPassportProvider(provider);
586
- const { page } = useAnalytics();
587
- useEffect(() => {
588
- page({
589
- userJourney: UserJourney.WALLET,
590
- screen: 'CoinInfo',
591
- });
592
- }, []);
593
- return (jsxs(SimpleLayout, { testId: "coin-info", header: jsx(HeaderNavigation, { showBack: true, transparent: true }), footer: jsx(FooterLogo, {}), heroContent: jsx(IMXCoinsHero, {}), floatHeader: true, children: [!isPassport && (jsx(SimpleTextBody, { heading: t('views.COIN_INFO.metamask.heading'), children: t('views.COIN_INFO.metamask.body') })), isPassport && (jsxs(SimpleTextBody, { heading: t('views.COIN_INFO.passport.heading'), children: [t('views.COIN_INFO.passport.body1'), jsx(Link, { onClick: () => window.open(FAQS_LINK), children: t('views.COIN_INFO.passport.linkText') }), t('views.COIN_INFO.passport.body2')] }))] }));
594
- }
595
-
596
- const REFRESH_BALANCE_INTERVAL_MS = 30000; // 30 seconds -- keep app less chatty
597
- const useBalance = ({ checkout, provider, refreshCallback, errorCallback, }) => {
598
- const [balancesLoading, setBalancesLoading] = useState(true);
599
- const refreshBalances = useCallback(async (
600
- // If silent is true, the balances will not be set to loading
601
- silent = false) => {
602
- if (!checkout || !provider)
603
- return;
604
- try {
605
- const network = await checkout.getNetworkInfo({
606
- provider,
607
- });
608
- /* If the provider's network is not supported, return out of this and let the
609
- connect loader handle the switch network functionality */
610
- if (!network.isSupported) {
611
- return;
612
- }
613
- if (!silent) {
614
- setBalancesLoading(true);
615
- }
616
- const balances = await getTokenBalances(checkout, provider, network.chainId);
617
- if (!silent) {
618
- setBalancesLoading(false);
619
- }
620
- refreshCallback(balances);
621
- // Ignore errors given that this is a background refresh
622
- // and the logic will retry anyways.
623
- }
624
- catch (error) {
625
- if (DEFAULT_BALANCE_RETRY_POLICY.nonRetryable(error)) {
626
- errorCallback(error);
627
- }
628
- if (!silent) {
629
- setBalancesLoading(false);
630
- }
631
- }
632
- }, [checkout, provider]);
633
- useInterval(() => refreshBalances(true), REFRESH_BALANCE_INTERVAL_MS);
634
- return {
635
- balancesLoading,
636
- refreshBalances,
637
- };
638
- };
639
-
640
- function WalletWidget(props) {
641
- const { t } = useTranslation();
642
- const errorActionText = t('views.ERROR_VIEW.actionText');
643
- const loadingText = t('views.LOADING_VIEW.text');
644
- const { eventTargetState: { eventTarget }, } = useContext(EventTargetContext);
645
- const { config: { environment, isOnRampEnabled, isSwapEnabled, isBridgeEnabled, }, } = props;
646
- const { connectLoaderState: { checkout, provider }, } = useContext(ConnectLoaderContext);
647
- const [viewState, viewDispatch] = useReducer(viewReducer, {
648
- ...initialViewState,
649
- history: [],
650
- });
651
- const [walletState, walletDispatch] = useReducer(walletReducer, initialWalletState);
652
- const walletReducerValues = useMemo(() => ({ walletState, walletDispatch }), [walletState, walletDispatch]);
653
- const viewReducerValues = useMemo(() => ({ viewState, viewDispatch }), [viewState, viewDispatch]);
654
- const { balancesLoading, refreshBalances } = useBalance({
655
- checkout,
656
- provider,
657
- refreshCallback: (balances) => {
658
- walletDispatch({
659
- payload: {
660
- type: WalletActions.SET_TOKEN_BALANCES,
661
- tokenBalances: balances,
662
- },
663
- });
664
- },
665
- errorCallback: (error) => {
666
- // eslint-disable-next-line no-console
667
- console.error(error);
668
- viewDispatch({
669
- payload: {
670
- type: ViewActions.UPDATE_VIEW,
671
- view: {
672
- type: SharedViews.ERROR_VIEW,
673
- error: new Error('Unable to fetch balances'),
674
- },
675
- },
676
- });
677
- },
678
- });
679
- /* Set Config into WalletState */
680
- useEffect(() => {
681
- (async () => {
682
- if (!checkout)
683
- return;
684
- let checkSwapAvailable;
685
- try {
686
- checkSwapAvailable = await checkout.isSwapAvailable();
687
- }
688
- catch (err) {
689
- checkSwapAvailable = false;
690
- }
691
- walletDispatch({
692
- payload: {
693
- type: WalletActions.SET_SUPPORTED_TOP_UPS,
694
- supportedTopUps: {
695
- isBridgeEnabled,
696
- isSwapEnabled,
697
- isOnRampEnabled,
698
- isSwapAvailable: checkSwapAvailable,
699
- },
700
- },
701
- });
702
- })();
703
- }, [isBridgeEnabled, isSwapEnabled, isOnRampEnabled, environment]);
704
- const initialiseWallet = async () => {
705
- if (!checkout || !provider)
706
- return;
707
- try {
708
- const network = await checkout.getNetworkInfo({
709
- provider,
710
- });
711
- /* If the provider's network is not supported, return out of this and let the
712
- connect loader handle the switch network functionality */
713
- if (!network.isSupported) {
714
- return;
715
- }
716
- /** Fetch the user's balances based on their connected provider and correct network */
717
- refreshBalances();
718
- viewDispatch({
719
- payload: {
720
- type: ViewActions.UPDATE_VIEW,
721
- view: { type: WalletWidgetViews.WALLET_BALANCES },
722
- },
723
- });
724
- walletDispatch({
725
- payload: {
726
- type: WalletActions.SET_NETWORK,
727
- network,
728
- },
729
- });
730
- }
731
- catch (error) {
732
- viewDispatch({
733
- payload: {
734
- type: ViewActions.UPDATE_VIEW,
735
- view: {
736
- type: SharedViews.ERROR_VIEW,
737
- error,
738
- },
739
- },
740
- });
741
- }
742
- };
743
- useEffect(() => {
744
- if (!checkout || !provider)
745
- return;
746
- initialiseWallet();
747
- }, [checkout, provider]);
748
- const errorAction = async () => {
749
- viewDispatch({
750
- payload: {
751
- type: ViewActions.UPDATE_VIEW,
752
- view: { type: WalletWidgetViews.WALLET_BALANCES },
753
- },
754
- });
755
- await initialiseWallet();
756
- };
757
- return (jsx(ViewContext.Provider, { value: viewReducerValues, children: jsx(CryptoFiatProvider, { environment: environment, children: jsxs(WalletContext.Provider, { value: walletReducerValues, children: [viewState.view.type === SharedViews.LOADING_VIEW && (jsx(LoadingView, { loadingText: loadingText })), viewState.view.type === WalletWidgetViews.WALLET_BALANCES && (jsx(WalletBalances, { balancesLoading: balancesLoading })), viewState.view.type === WalletWidgetViews.SETTINGS && jsx(Settings, {}), viewState.view.type === WalletWidgetViews.COIN_INFO && (jsx(CoinInfo, {})), viewState.view.type === SharedViews.ERROR_VIEW && (jsx(ErrorView, { actionText: errorActionText, onActionClick: errorAction, onCloseClick: () => sendWalletWidgetCloseEvent(eventTarget) })), viewState.view.type === SharedViews.TOP_UP_VIEW && (jsx(TopUpView, { analytics: { userJourney: UserJourney.WALLET }, widgetEvent: IMTBLWidgetEvents.IMTBL_WALLET_WIDGET_EVENT, checkout: checkout, provider: provider, showOnrampOption: isOnRampEnabled, showSwapOption: isSwapEnabled, showBridgeOption: isBridgeEnabled, onCloseButtonClick: () => sendWalletWidgetCloseEvent(eventTarget) }))] }) }) }));
758
- }
759
-
760
- export { WalletWidget as default };