@imtbl/checkout-widgets 2.10.3 → 2.10.4-alpha.0
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-7xP3ash_.js} +24 -24
- package/dist/browser/{BridgeWidget-BGv6pl-L.js → BridgeWidget-xF3mC-MN.js} +32 -32
- package/dist/browser/{CommerceWidget-BmxPzB_7.js → CommerceWidget-Dx44BFWy.js} +182 -182
- package/dist/browser/{FeesBreakdown-CTf-10x4.js → FeesBreakdown-Dy1ctSpO.js} +2 -2
- package/dist/browser/{OnRampWidget-DHnrE80i.js → OnRampWidget-hWptERhu.js} +40 -26
- package/dist/browser/{SaleWidget-BXzTLbHG.js → SaleWidget-SueR-4Ck.js} +45 -45
- package/dist/browser/{SpendingCapHero-DgeQK3YA.js → SpendingCapHero-kPkYD5HR.js} +1 -1
- package/dist/browser/{SwapWidget-Bh2dRzCk.js → SwapWidget-B9Lgj2-6.js} +12 -12
- package/dist/browser/{TokenImage-D9BGjc4I.js → TokenImage-C44Kn3Pq.js} +1 -1
- package/dist/browser/{TopUpView-DQ6NHIsB.js → TopUpView-DZ6urV-T.js} +4 -4
- package/dist/browser/{WalletApproveHero-C8PSw4WQ.js → WalletApproveHero-B3gMB-AI.js} +2 -2
- package/dist/browser/{WalletWidget-ADG2A7wv.js → WalletWidget-Cq1IwRPp.js} +11 -11
- package/dist/browser/{auto-track-WjZIebqK.js → auto-track-1sIh5Cg-.js} +1 -1
- package/dist/browser/{index-BjDgJAyF.js → index-BAjyTG-F.js} +1 -1
- package/dist/browser/{index-BegaQ_Gy.js → index-BS6qjzzl.js} +1 -1
- package/dist/browser/{index-CTeRLgch.js → index-BpeF_Hv4.js} +1 -1
- package/dist/browser/{index-DOBGPXKx.js → index-CJrC7v34.js} +1 -1
- package/dist/browser/{index-D0vMQXbJ.js → index-C_2UQ8ka.js} +2 -2
- package/dist/browser/{index-DMgRiK35.js → index-Cc4A5E_A.js} +1 -1
- package/dist/browser/{index-CsK_1Pd3.js → index-DA9Xu4LZ.js} +1 -1
- package/dist/browser/{index-C8Pybl6W.js → index-DFAGr0d5.js} +348 -338
- package/dist/browser/index.js +1 -1
- package/dist/browser/{index.umd-TcVSRaL8.js → index.umd-BDwQTcot.js} +1 -1
- package/dist/browser/{useInterval-CI7WTOt5.js → useInterval-apxTIl_n.js} +1 -1
- package/dist/types/components/Transak/useTransakIframe.d.ts +5 -0
- package/package.json +7 -7
- package/src/components/Transak/useTransakIframe.ts +39 -12
- package/src/widgets/on-ramp/views/OnRampMain.tsx +56 -26
package/dist/browser/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { er as WidgetsFactory } from './index-
|
|
1
|
+
export { er as WidgetsFactory } from './index-DFAGr0d5.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as reactExports, dW as useBrowserLayoutEffect } from './index-DFAGr0d5.js';
|
|
2
2
|
|
|
3
3
|
// Inspired by https://usehooks-ts.com/react-hook/use-interval
|
|
4
4
|
function useInterval(callback, delay) {
|
|
@@ -35,6 +35,11 @@ export declare const TRANSAK_API_KEY: {
|
|
|
35
35
|
sandbox: string;
|
|
36
36
|
production: string;
|
|
37
37
|
};
|
|
38
|
+
export declare const IMMUTABLE_API_BASE_URL: {
|
|
39
|
+
development: string;
|
|
40
|
+
sandbox: string;
|
|
41
|
+
production: string;
|
|
42
|
+
};
|
|
38
43
|
export declare const useTransakIframe: (props: UseTransakIframeProps) => {
|
|
39
44
|
iframeSrc: string;
|
|
40
45
|
};
|
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.0",
|
|
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.0",
|
|
22
|
+
"@imtbl/checkout-sdk": "2.10.4-alpha.0",
|
|
23
|
+
"@imtbl/config": "2.10.4-alpha.0",
|
|
24
|
+
"@imtbl/cryptofiat": "2.10.4-alpha.0",
|
|
25
|
+
"@imtbl/dex-sdk": "2.10.4-alpha.0",
|
|
26
|
+
"@imtbl/passport": "2.10.4-alpha.0",
|
|
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
|
|
|
@@ -50,6 +51,12 @@ export const TRANSAK_API_KEY = {
|
|
|
50
51
|
[Environment.PRODUCTION]: 'ad1bca70-d917-4628-bb0f-5609537498bc',
|
|
51
52
|
};
|
|
52
53
|
|
|
54
|
+
export const IMMUTABLE_API_BASE_URL = {
|
|
55
|
+
development: 'https://api.dev.immutable.com',
|
|
56
|
+
[Environment.SANDBOX]: 'https://api.sandbox.immutable.com',
|
|
57
|
+
[Environment.PRODUCTION]: 'https://api.immutable.com',
|
|
58
|
+
};
|
|
59
|
+
|
|
53
60
|
export const useTransakIframe = (props: UseTransakIframeProps) => {
|
|
54
61
|
const {
|
|
55
62
|
contractId, environment, transakParams, onError,
|
|
@@ -64,7 +71,10 @@ export const useTransakIframe = (props: UseTransakIframeProps) => {
|
|
|
64
71
|
estimatedGasLimit,
|
|
65
72
|
cryptoCurrencyCode,
|
|
66
73
|
excludeFiatCurrencies,
|
|
67
|
-
|
|
74
|
+
exchangeScreenTitle,
|
|
75
|
+
email,
|
|
76
|
+
walletAddress,
|
|
77
|
+
partnerOrderId,
|
|
68
78
|
} = transakParams;
|
|
69
79
|
|
|
70
80
|
// FIXME: defaulting to first nft in the list
|
|
@@ -104,21 +114,38 @@ export const useTransakIframe = (props: UseTransakIframeProps) => {
|
|
|
104
114
|
|
|
105
115
|
const { id: nftTransactionId } = await response.json();
|
|
106
116
|
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
const requestBody: Record<string, unknown> = {
|
|
118
|
+
api_key: TRANSAK_API_KEY[environment],
|
|
119
|
+
nft_transaction_id: nftTransactionId,
|
|
120
|
+
theme_color: '0D0D0D',
|
|
121
|
+
exchange_screen_title: exchangeScreenTitle,
|
|
122
|
+
wallet_address: walletAddress,
|
|
123
|
+
partner_order_id: partnerOrderId,
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
if (email) {
|
|
127
|
+
requestBody.email = email;
|
|
128
|
+
}
|
|
116
129
|
|
|
117
130
|
if (excludeFiatCurrencies) {
|
|
118
|
-
|
|
131
|
+
requestBody.exclude_fiat_currencies = excludeFiatCurrencies.join(',');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const widgetUrlResponse = await fetch(`${IMMUTABLE_API_BASE_URL[environment]}/checkout/v1/widget-url`, {
|
|
135
|
+
method: 'POST',
|
|
136
|
+
headers: {
|
|
137
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
138
|
+
'Content-Type': 'application/json',
|
|
139
|
+
},
|
|
140
|
+
body: JSON.stringify(requestBody),
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
if (!widgetUrlResponse.ok) {
|
|
144
|
+
throw new Error('Failed to get widget URL');
|
|
119
145
|
}
|
|
120
146
|
|
|
121
|
-
|
|
147
|
+
const { url } = await widgetUrlResponse.json();
|
|
148
|
+
return url;
|
|
122
149
|
} catch {
|
|
123
150
|
onError?.();
|
|
124
151
|
}
|
|
@@ -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)}>
|