@imtbl/checkout-widgets 2.10.3 → 2.10.4-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 (28) hide show
  1. package/dist/browser/{AddTokensWidget-CyYchEqL.js → AddTokensWidget-DfSlhpE2.js} +24 -24
  2. package/dist/browser/{BridgeWidget-BGv6pl-L.js → BridgeWidget-Bsfpyy6Q.js} +32 -32
  3. package/dist/browser/{CommerceWidget-BmxPzB_7.js → CommerceWidget-XxW5BnE_.js} +182 -182
  4. package/dist/browser/{FeesBreakdown-CTf-10x4.js → FeesBreakdown-BOeME08j.js} +2 -2
  5. package/dist/browser/{OnRampWidget-DHnrE80i.js → OnRampWidget-rrRpGMDQ.js} +40 -26
  6. package/dist/browser/{SaleWidget-BXzTLbHG.js → SaleWidget-BrlvBL0k.js} +45 -45
  7. package/dist/browser/{SpendingCapHero-DgeQK3YA.js → SpendingCapHero-CqZM_goS.js} +1 -1
  8. package/dist/browser/{SwapWidget-Bh2dRzCk.js → SwapWidget-XujPvLEA.js} +12 -12
  9. package/dist/browser/{TokenImage-D9BGjc4I.js → TokenImage-C1ydXYvS.js} +1 -1
  10. package/dist/browser/{TopUpView-DQ6NHIsB.js → TopUpView-Dy08ST9w.js} +4 -4
  11. package/dist/browser/{WalletApproveHero-C8PSw4WQ.js → WalletApproveHero-DpusLgi-.js} +2 -2
  12. package/dist/browser/{WalletWidget-ADG2A7wv.js → WalletWidget-h9GOBkvG.js} +11 -11
  13. package/dist/browser/{auto-track-WjZIebqK.js → auto-track-BnaNIxVw.js} +1 -1
  14. package/dist/browser/{index-CsK_1Pd3.js → index-B2p6QzbD.js} +1 -1
  15. package/dist/browser/{index-BjDgJAyF.js → index-B8cGCT2t.js} +1 -1
  16. package/dist/browser/{index-C8Pybl6W.js → index-BPK6WOYV.js} +348 -338
  17. package/dist/browser/{index-DMgRiK35.js → index-CGuYsKf3.js} +1 -1
  18. package/dist/browser/{index-D0vMQXbJ.js → index-DPXcD0g5.js} +2 -2
  19. package/dist/browser/{index-CTeRLgch.js → index-DX1fX6Eo.js} +1 -1
  20. package/dist/browser/{index-BegaQ_Gy.js → index-Djwk1xmm.js} +1 -1
  21. package/dist/browser/{index-DOBGPXKx.js → index-Dora0f5e.js} +1 -1
  22. package/dist/browser/index.js +1 -1
  23. package/dist/browser/{index.umd-TcVSRaL8.js → index.umd-DM76_p44.js} +1 -1
  24. package/dist/browser/{useInterval-CI7WTOt5.js → useInterval-DsmMsnMZ.js} +1 -1
  25. package/dist/types/components/Transak/useTransakIframe.d.ts +3 -6
  26. package/package.json +7 -7
  27. package/src/components/Transak/useTransakIframe.ts +39 -24
  28. package/src/widgets/on-ramp/views/OnRampMain.tsx +56 -26
@@ -1,4 +1,4 @@
1
- import { ec as __assign } from './index-C8Pybl6W.js';
1
+ import { ec as __assign } from './index-BPK6WOYV.js';
2
2
  import { i as isPlanEventEnabled } from './is-plan-event-enabled-mXX0dwl-.js';
3
3
 
4
4
  function disabledActionDestinations(plan, settings) {
@@ -1,4 +1,4 @@
1
- import { e5 as __awaiter, e6 as __generator } from './index-C8Pybl6W.js';
1
+ import { e5 as __awaiter, e6 as __generator } from './index-BPK6WOYV.js';
2
2
 
3
3
  function loadLegacyVideoPlugins(analytics) {
4
4
  return __awaiter(this, void 0, void 0, function () {
@@ -7,7 +7,7 @@ function loadLegacyVideoPlugins(analytics) {
7
7
  switch (_a.label) {
8
8
  case 0: return [4 /*yield*/, import(
9
9
  // @ts-expect-error
10
- './index.umd-TcVSRaL8.js').then(function (n) { return n.i; })
10
+ './index.umd-DM76_p44.js').then(function (n) { return n.i; })
11
11
  // This is super gross, but we need to support the `window.analytics.plugins` namespace
12
12
  // that is linked in the segment docs in order to be backwards compatible with ajs-classic
13
13
  // @ts-expect-error
@@ -1,4 +1,4 @@
1
- import { e4 as getAugmentedNamespace, az as commonjsGlobal } from './index-C8Pybl6W.js';
1
+ import { e4 as getAugmentedNamespace, az as commonjsGlobal } from './index-BPK6WOYV.js';
2
2
 
3
3
  var dist$1 = {};
4
4
 
@@ -1,4 +1,4 @@
1
- import { dX as se$1, dY as T$2, dZ as oe$1, d_ as R$1, d$ as a$2, e0 as te$1, e1 as p$1, e2 as ne$1, e3 as y$1 } from './index-C8Pybl6W.js';
1
+ import { dX as se$1, dY as T$2, dZ as oe$1, d_ as R$1, d$ as a$2, e0 as te$1, e1 as p$1, e2 as ne$1, e3 as y$1 } from './index-BPK6WOYV.js';
2
2
 
3
3
  /**
4
4
  * @license
@@ -1,4 +1,4 @@
1
- import { eq as gracefulDecodeURIComponent, ei as isPlainObject } from './index-C8Pybl6W.js';
1
+ import { eq as gracefulDecodeURIComponent, ei as isPlainObject } from './index-BPK6WOYV.js';
2
2
 
3
3
  /**
4
4
  * Returns an object containing only the properties prefixed by the input
@@ -1 +1 @@
1
- export { er as WidgetsFactory } from './index-C8Pybl6W.js';
1
+ export { er as WidgetsFactory } from './index-BPK6WOYV.js';
@@ -1,4 +1,4 @@
1
- import { ay as getDefaultExportFromCjs } from './index-C8Pybl6W.js';
1
+ import { ay as getDefaultExportFromCjs } from './index-BPK6WOYV.js';
2
2
 
3
3
  function _mergeNamespaces(n, m) {
4
4
  m.forEach(function (e) {
@@ -1,4 +1,4 @@
1
- import { r as reactExports, dW as useBrowserLayoutEffect } from './index-C8Pybl6W.js';
1
+ import { b as reactExports, dW as useBrowserLayoutEffect } from './index-BPK6WOYV.js';
2
2
 
3
3
  // Inspired by https://usehooks-ts.com/react-hook/use-interval
4
4
  function useInterval(callback, delay) {
@@ -19,19 +19,16 @@ type UseTransakIframeProps = {
19
19
  transakParams: TransakNFTCheckoutParams;
20
20
  onError?: () => void;
21
21
  };
22
- export declare const TRANSAK_WIDGET_BASE_URL: {
23
- sandbox: string;
24
- production: string;
25
- };
26
22
  export declare const TRANSAK_API_BASE_URL: {
27
23
  sandbox: string;
28
24
  production: string;
29
25
  };
30
- export declare const TRANSAK_ENVIRONMENT: {
26
+ export declare const TRANSAK_API_KEY: {
31
27
  sandbox: string;
32
28
  production: string;
33
29
  };
34
- export declare const TRANSAK_API_KEY: {
30
+ export declare const IMMUTABLE_API_BASE_URL: {
31
+ development: string;
35
32
  sandbox: string;
36
33
  production: string;
37
34
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imtbl/checkout-widgets",
3
- "version": "2.10.3",
3
+ "version": "2.10.4-alpha.1",
4
4
  "browserslist": {
5
5
  "production": [
6
6
  ">0.2%",
@@ -18,12 +18,12 @@
18
18
  "@biom3/design-tokens": "^0.4.5",
19
19
  "@biom3/react": "^0.29.4",
20
20
  "@emotion/react": "^11.11.3",
21
- "@imtbl/bridge-sdk": "2.10.3",
22
- "@imtbl/checkout-sdk": "2.10.3",
23
- "@imtbl/config": "2.10.3",
24
- "@imtbl/cryptofiat": "2.10.3",
25
- "@imtbl/dex-sdk": "2.10.3",
26
- "@imtbl/passport": "2.10.3",
21
+ "@imtbl/bridge-sdk": "2.10.4-alpha.1",
22
+ "@imtbl/checkout-sdk": "2.10.4-alpha.1",
23
+ "@imtbl/config": "2.10.4-alpha.1",
24
+ "@imtbl/cryptofiat": "2.10.4-alpha.1",
25
+ "@imtbl/dex-sdk": "2.10.4-alpha.1",
26
+ "@imtbl/passport": "2.10.4-alpha.1",
27
27
  "@imtbl/react-analytics": "0.3.4-alpha",
28
28
  "@rive-app/react-canvas-lite": "^4.9.0",
29
29
  "@walletconnect/ethereum-provider": "^2.11.1",
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/naming-convention */
1
2
  import { useCallback, useEffect, useState } from 'react';
2
3
  import { Environment } from '@imtbl/config';
3
4
 
@@ -28,28 +29,22 @@ type UseTransakIframeProps = {
28
29
 
29
30
  const MAX_GAS_LIMIT = '30000000';
30
31
 
31
- // TODO: Move to common config file inside Checkout SDK while refactoring onRamp
32
- // TODO: Get transak config from checkout SDK
33
- export const TRANSAK_WIDGET_BASE_URL = {
34
- [Environment.SANDBOX]: 'https://global-stg.transak.com',
35
- [Environment.PRODUCTION]: 'https://global.transak.com/',
36
- };
37
-
38
32
  export const TRANSAK_API_BASE_URL = {
39
33
  [Environment.SANDBOX]: 'https://api-stg.transak.com',
40
34
  [Environment.PRODUCTION]: 'https://api.transak.com',
41
35
  };
42
36
 
43
- export const TRANSAK_ENVIRONMENT = {
44
- [Environment.SANDBOX]: 'STAGING',
45
- [Environment.PRODUCTION]: 'PRODUCTION',
46
- };
47
-
48
37
  export const TRANSAK_API_KEY = {
49
38
  [Environment.SANDBOX]: 'd14b44fb-0f84-4db5-affb-e044040d724b',
50
39
  [Environment.PRODUCTION]: 'ad1bca70-d917-4628-bb0f-5609537498bc',
51
40
  };
52
41
 
42
+ export const IMMUTABLE_API_BASE_URL = {
43
+ development: 'https://api.dev.immutable.com',
44
+ [Environment.SANDBOX]: 'https://api.sandbox.immutable.com',
45
+ [Environment.PRODUCTION]: 'https://api.immutable.com',
46
+ };
47
+
53
48
  export const useTransakIframe = (props: UseTransakIframeProps) => {
54
49
  const {
55
50
  contractId, environment, transakParams, onError,
@@ -64,7 +59,10 @@ export const useTransakIframe = (props: UseTransakIframeProps) => {
64
59
  estimatedGasLimit,
65
60
  cryptoCurrencyCode,
66
61
  excludeFiatCurrencies,
67
- ...restWidgetParams
62
+ exchangeScreenTitle,
63
+ email,
64
+ walletAddress,
65
+ partnerOrderId,
68
66
  } = transakParams;
69
67
 
70
68
  // FIXME: defaulting to first nft in the list
@@ -104,21 +102,38 @@ export const useTransakIframe = (props: UseTransakIframeProps) => {
104
102
 
105
103
  const { id: nftTransactionId } = await response.json();
106
104
 
107
- const baseWidgetUrl = `${TRANSAK_WIDGET_BASE_URL[environment]}?`;
108
- const queryParams = new URLSearchParams({
109
- apiKey: TRANSAK_API_KEY[environment],
110
- environment: TRANSAK_ENVIRONMENT[environment],
111
- isNFT: 'true',
112
- nftTransactionId,
113
- themeColor: '0D0D0D',
114
- ...restWidgetParams,
115
- });
105
+ const requestBody: Record<string, unknown> = {
106
+ api_key: TRANSAK_API_KEY[environment],
107
+ nft_transaction_id: nftTransactionId,
108
+ theme_color: '0D0D0D',
109
+ exchange_screen_title: exchangeScreenTitle,
110
+ wallet_address: walletAddress,
111
+ partner_order_id: partnerOrderId,
112
+ };
113
+
114
+ if (email) {
115
+ requestBody.email = email;
116
+ }
116
117
 
117
118
  if (excludeFiatCurrencies) {
118
- queryParams.append('excludeFiatCurrencies', excludeFiatCurrencies.join(','));
119
+ requestBody.exclude_fiat_currencies = excludeFiatCurrencies.join(',');
120
+ }
121
+
122
+ const widgetUrlResponse = await fetch(`${IMMUTABLE_API_BASE_URL[environment]}/checkout/v1/widget-url`, {
123
+ method: 'POST',
124
+ headers: {
125
+ // eslint-disable-next-line @typescript-eslint/naming-convention
126
+ 'Content-Type': 'application/json',
127
+ },
128
+ body: JSON.stringify(requestBody),
129
+ });
130
+
131
+ if (!widgetUrlResponse.ok) {
132
+ throw new Error('Failed to get widget URL');
119
133
  }
120
134
 
121
- return `${baseWidgetUrl}${queryParams.toString()}`;
135
+ const { url } = await widgetUrlResponse.json();
136
+ return url;
122
137
  } catch {
123
138
  onError?.();
124
139
  }
@@ -5,7 +5,9 @@ import {
5
5
  useContext, useEffect, useMemo, useRef, useState,
6
6
  } from 'react';
7
7
  import {
8
+ Checkout,
8
9
  ExchangeType, IMTBLWidgetEvents,
10
+ WrappedBrowserProvider,
9
11
  } from '@imtbl/checkout-sdk';
10
12
  import url from 'url';
11
13
  import { useTranslation } from 'react-i18next';
@@ -47,6 +49,48 @@ interface OnRampProps {
47
49
  customSubTitle?: string;
48
50
  showHeader?: boolean;
49
51
  }
52
+
53
+ function useWidgetUrl(
54
+ checkout: Checkout | undefined,
55
+ provider: WrappedBrowserProvider | undefined,
56
+ tokenAddress: string | undefined,
57
+ tokenAmount: string | undefined,
58
+ passport: Passport | undefined,
59
+ showMenu: boolean | undefined,
60
+ customSubTitle: string | undefined,
61
+ ) {
62
+ const [widgetUrl, setWidgetUrl] = useState<string | undefined>(undefined);
63
+
64
+ useEffect(() => {
65
+ if (!checkout || !provider) return;
66
+
67
+ const params = {
68
+ exchangeType: ExchangeType.ONRAMP,
69
+ browserProvider: provider,
70
+ tokenAddress,
71
+ tokenAmount,
72
+ passport,
73
+ showMenu,
74
+ customSubTitle,
75
+ };
76
+
77
+ checkout.createFiatRampUrl(params).then(setWidgetUrl);
78
+ }, [checkout, provider, tokenAddress, tokenAmount, passport, showMenu, customSubTitle]);
79
+
80
+ return widgetUrl;
81
+ }
82
+
83
+ function useWalletAddress(provider: WrappedBrowserProvider | undefined) {
84
+ const [userWalletAddress, setUserWalletAddress] = useState<string | undefined>(undefined);
85
+
86
+ useEffect(() => {
87
+ if (!provider) return;
88
+ provider.getSigner().then((signer) => signer.getAddress()).then(setUserWalletAddress);
89
+ }, [provider]);
90
+
91
+ return userWalletAddress;
92
+ }
93
+
50
94
  export function OnRampMain({
51
95
  passport,
52
96
  showIframe,
@@ -66,7 +110,8 @@ export function OnRampMain({
66
110
 
67
111
  const { t } = useTranslation();
68
112
  const { viewState, viewDispatch } = useContext(ViewContext);
69
- const [widgetUrl, setWidgetUrl] = useState<string>('');
113
+ const widgetUrl = useWidgetUrl(checkout, provider, tokenAddress, tokenAmount, passport, showMenu, customSubTitle);
114
+ const userWalletAddress = useWalletAddress(provider);
70
115
 
71
116
  const eventTimer = useRef<number | undefined>();
72
117
 
@@ -233,46 +278,31 @@ export function OnRampMain({
233
278
  }, [viewDispatch, tokenAmount, tokenAddress, viewState.view.data?.amount, viewState.view.data?.tokenAddress]);
234
279
 
235
280
  useEffect(() => {
236
- if (!checkout || !provider) return;
237
-
238
- let userWalletAddress = '';
239
-
240
- (async () => {
241
- const params = {
242
- exchangeType: ExchangeType.ONRAMP,
243
- browserProvider: provider,
244
- tokenAddress,
245
- tokenAmount,
246
- passport,
247
- showMenu,
248
- customSubTitle,
249
- };
250
-
251
- setWidgetUrl(await checkout.createFiatRampUrl(params));
252
- userWalletAddress = await (await provider!.getSigner()).getAddress();
253
- })();
254
-
255
- const domIframe: HTMLIFrameElement = document.getElementById(
281
+ const domIframe = document.getElementById(
256
282
  transakIframeId,
257
- ) as HTMLIFrameElement;
283
+ ) as HTMLIFrameElement | null;
258
284
 
259
285
  if (!domIframe) return;
260
286
 
261
287
  const handleTransakEvents = (event: any) => {
262
- if (!domIframe) return;
263
-
264
288
  const host = url.parse(event.origin)?.host?.toLowerCase();
265
289
  if (
266
290
  event.source === domIframe.contentWindow
267
291
  && host
268
292
  && TRANSAK_ORIGIN.includes(host)
269
293
  ) {
270
- trackSegmentEvents(event.data, userWalletAddress);
294
+ trackSegmentEvents(event.data, userWalletAddress ?? '');
271
295
  transakEventHandler(event.data);
272
296
  }
273
297
  };
298
+
274
299
  window.addEventListener('message', handleTransakEvents);
275
- }, [checkout, provider, tokenAmount, tokenAddress, passport, trackSegmentEvents, transakEventHandler]);
300
+
301
+ // eslint-disable-next-line consistent-return
302
+ return () => {
303
+ window.removeEventListener('message', handleTransakEvents);
304
+ };
305
+ }, [trackSegmentEvents, transakEventHandler, userWalletAddress]);
276
306
 
277
307
  return (
278
308
  <Box sx={boxMainStyle(showIframe)}>