@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.
- package/dist/browser/{AddTokensWidget-CyYchEqL.js → AddTokensWidget-DfSlhpE2.js} +24 -24
- package/dist/browser/{BridgeWidget-BGv6pl-L.js → BridgeWidget-Bsfpyy6Q.js} +32 -32
- package/dist/browser/{CommerceWidget-BmxPzB_7.js → CommerceWidget-XxW5BnE_.js} +182 -182
- package/dist/browser/{FeesBreakdown-CTf-10x4.js → FeesBreakdown-BOeME08j.js} +2 -2
- package/dist/browser/{OnRampWidget-DHnrE80i.js → OnRampWidget-rrRpGMDQ.js} +40 -26
- package/dist/browser/{SaleWidget-BXzTLbHG.js → SaleWidget-BrlvBL0k.js} +45 -45
- package/dist/browser/{SpendingCapHero-DgeQK3YA.js → SpendingCapHero-CqZM_goS.js} +1 -1
- package/dist/browser/{SwapWidget-Bh2dRzCk.js → SwapWidget-XujPvLEA.js} +12 -12
- package/dist/browser/{TokenImage-D9BGjc4I.js → TokenImage-C1ydXYvS.js} +1 -1
- package/dist/browser/{TopUpView-DQ6NHIsB.js → TopUpView-Dy08ST9w.js} +4 -4
- package/dist/browser/{WalletApproveHero-C8PSw4WQ.js → WalletApproveHero-DpusLgi-.js} +2 -2
- package/dist/browser/{WalletWidget-ADG2A7wv.js → WalletWidget-h9GOBkvG.js} +11 -11
- package/dist/browser/{auto-track-WjZIebqK.js → auto-track-BnaNIxVw.js} +1 -1
- package/dist/browser/{index-CsK_1Pd3.js → index-B2p6QzbD.js} +1 -1
- package/dist/browser/{index-BjDgJAyF.js → index-B8cGCT2t.js} +1 -1
- package/dist/browser/{index-C8Pybl6W.js → index-BPK6WOYV.js} +348 -338
- package/dist/browser/{index-DMgRiK35.js → index-CGuYsKf3.js} +1 -1
- package/dist/browser/{index-D0vMQXbJ.js → index-DPXcD0g5.js} +2 -2
- package/dist/browser/{index-CTeRLgch.js → index-DX1fX6Eo.js} +1 -1
- package/dist/browser/{index-BegaQ_Gy.js → index-Djwk1xmm.js} +1 -1
- package/dist/browser/{index-DOBGPXKx.js → index-Dora0f5e.js} +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/browser/{index.umd-TcVSRaL8.js → index.umd-DM76_p44.js} +1 -1
- package/dist/browser/{useInterval-CI7WTOt5.js → useInterval-DsmMsnMZ.js} +1 -1
- package/dist/types/components/Transak/useTransakIframe.d.ts +3 -6
- package/package.json +7 -7
- package/src/components/Transak/useTransakIframe.ts +39 -24
- package/src/widgets/on-ramp/views/OnRampMain.tsx +56 -26
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { e5 as __awaiter, e6 as __generator } from './index-
|
|
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-
|
|
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 { 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-
|
|
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
|
package/dist/browser/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { er as WidgetsFactory } from './index-
|
|
1
|
+
export { er as WidgetsFactory } from './index-BPK6WOYV.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
26
|
+
export declare const TRANSAK_API_KEY: {
|
|
31
27
|
sandbox: string;
|
|
32
28
|
production: string;
|
|
33
29
|
};
|
|
34
|
-
export declare const
|
|
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
|
+
"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.
|
|
22
|
-
"@imtbl/checkout-sdk": "2.10.
|
|
23
|
-
"@imtbl/config": "2.10.
|
|
24
|
-
"@imtbl/cryptofiat": "2.10.
|
|
25
|
-
"@imtbl/dex-sdk": "2.10.
|
|
26
|
-
"@imtbl/passport": "2.10.
|
|
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
|
-
|
|
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
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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)}>
|