@imtbl/sdk 0.22.2 → 0.23.0-alpha

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.
@@ -25393,7 +25393,7 @@ declare function CheckoutWidgets(config?: CheckoutWidgetsConfig): void;
25393
25393
  /**
25394
25394
  * Updates the configuration for the checkout widgets by setting the global variable
25395
25395
  * `window.ImtblCheckoutWidgetConfig` to the JSON string representation of the given
25396
- * `config` object.
25396
+ * `config` object and update all the Checkout web components configuration.
25397
25397
  * @param {CheckoutWidgetsConfig} config - The new configuration object for the checkout widgets.
25398
25398
  * @returns None
25399
25399
  */
@@ -4,11 +4,54 @@ import { useEffect } from 'react';
4
4
  function $parcel$export(e, n, v, s) {
5
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
6
  }
7
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.22.2";
7
+ var $045213b18e9f1f94$exports = {};
8
+
9
+ $parcel$export($045213b18e9f1f94$exports, "WidgetTheme", () => $045213b18e9f1f94$export$c88931fdc51854eb);
10
+ $parcel$export($045213b18e9f1f94$exports, "CheckoutWidgetTagNames", () => $045213b18e9f1f94$export$75be0f6af9650f2c);
11
+ /**
12
+ * Enum representing the themes for the Checkout widgets.
13
+ */ var $045213b18e9f1f94$export$c88931fdc51854eb;
14
+ (function(WidgetTheme) {
15
+ WidgetTheme["LIGHT"] = "light";
16
+ WidgetTheme["DARK"] = "dark";
17
+ })($045213b18e9f1f94$export$c88931fdc51854eb || ($045213b18e9f1f94$export$c88931fdc51854eb = {}));
18
+ var $045213b18e9f1f94$export$75be0f6af9650f2c;
19
+ (function(CheckoutWidgetTagNames) {
20
+ CheckoutWidgetTagNames["CONNECT"] = "imtbl-connect";
21
+ CheckoutWidgetTagNames["WALLET"] = "imtbl-wallet";
22
+ CheckoutWidgetTagNames["SWAP"] = "imtbl-swap";
23
+ CheckoutWidgetTagNames["BRIDGE"] = "imtbl-bridge";
24
+ CheckoutWidgetTagNames["ONRAMP"] = "imtbl-onramp";
25
+ })($045213b18e9f1f94$export$75be0f6af9650f2c || ($045213b18e9f1f94$export$75be0f6af9650f2c = {}));
26
+
27
+
28
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.23.0-alpha";
8
29
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
9
30
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
10
31
 
11
32
 
33
+ function $430e3eda76fa4d5f$var$getWidgetConfig(element) {
34
+ const config = element.getAttribute("widgetconfig");
35
+ if (!config) return null;
36
+ try {
37
+ return JSON.parse(config);
38
+ } catch (err) {
39
+ // eslint-disable-next-line no-console
40
+ console.warn(`Unable to decode widgetconfig for ${element}: `, err);
41
+ }
42
+ return null;
43
+ }
44
+ function $430e3eda76fa4d5f$var$setWidgetConfig(element, config) {
45
+ element.setAttribute("widgetconfig", JSON.stringify(config));
46
+ }
47
+ function $430e3eda76fa4d5f$var$saveConfig(config) {
48
+ if (window === undefined) {
49
+ // eslint-disable-next-line no-console
50
+ console.error("missing window object: please run Checkout client side");
51
+ return;
52
+ }
53
+ window.ImtblCheckoutWidgetConfig = JSON.stringify(config);
54
+ }
12
55
  function $430e3eda76fa4d5f$export$46b1ae20f762ad4c(version) {
13
56
  const defaultPackageVersion = ($d663162fd5a0853f$export$1169f5475725171b)();
14
57
  if (version === undefined || version.major === undefined) return defaultPackageVersion;
@@ -30,6 +73,29 @@ function $430e3eda76fa4d5f$export$46b1ae20f762ad4c(version) {
30
73
  if (Number.isInteger(version.build) && version.build >= 0) validatedVersion += `.${version.build.toString()}`;
31
74
  return validatedVersion;
32
75
  }
76
+ function $430e3eda76fa4d5f$var$loadScript(config) {
77
+ if (document === undefined) {
78
+ // eslint-disable-next-line no-console
79
+ console.error("missing document object: please run Checkout client side");
80
+ return;
81
+ }
82
+ const validVersion = $430e3eda76fa4d5f$export$46b1ae20f762ad4c(config?.version);
83
+ // Prevent the script to be loaded more than once
84
+ // by checking the presence of the script and its version.
85
+ const initScript = document.querySelector('[data-product="checkout"]');
86
+ if (initScript) {
87
+ // eslint-disable-next-line no-console
88
+ console.warn("checkout script has already been loaded, it can only be loaded once.");
89
+ return;
90
+ }
91
+ const tag = document.createElement("script");
92
+ let cdnUrl = `https://cdn.jsdelivr.net/npm/@imtbl/sdk@${validVersion}/dist/browser/checkout.js`;
93
+ if (($d663162fd5a0853f$export$83bf90b30cdfd29f)()) cdnUrl = "http://localhost:3000/lib/js/imtbl-checkout.js";
94
+ tag.setAttribute("data-product", "checkout");
95
+ tag.setAttribute("data-version", validVersion);
96
+ tag.setAttribute("src", cdnUrl);
97
+ document.head.appendChild(tag);
98
+ }
33
99
  function $430e3eda76fa4d5f$export$af210a0808087845(config) {
34
100
  if (window === undefined) {
35
101
  // eslint-disable-next-line no-console
@@ -41,21 +107,45 @@ function $430e3eda76fa4d5f$export$af210a0808087845(config) {
41
107
  console.error("missing document object: please run Checkout client side");
42
108
  return;
43
109
  }
44
- const checkoutWidgetJS = document.createElement("script");
45
- const validVersion = $430e3eda76fa4d5f$export$46b1ae20f762ad4c(config?.version);
46
- let cdnUrl = `https://cdn.jsdelivr.net/npm/@imtbl/sdk@${validVersion}/dist/browser/checkout.js`;
47
- if (($d663162fd5a0853f$export$83bf90b30cdfd29f)()) cdnUrl = "http://localhost:3000/lib/js/imtbl-checkout.js";
48
- checkoutWidgetJS.setAttribute("src", cdnUrl);
49
- document.head.appendChild(checkoutWidgetJS);
50
- window.ImtblCheckoutWidgetConfig = JSON.stringify(config);
110
+ $430e3eda76fa4d5f$var$loadScript(config || {});
111
+ $430e3eda76fa4d5f$var$saveConfig(config || {});
51
112
  }
52
113
  function $430e3eda76fa4d5f$export$bf1548ba7e61c17f(config) {
53
114
  if (window === undefined) {
115
+ // eslint-disable-next-line no-console
116
+ console.error("missing window object: please run Checkout client side");
117
+ return;
118
+ }
119
+ if (document === undefined) {
54
120
  // eslint-disable-next-line no-console
55
121
  console.error("missing document object: please run Checkout client side");
56
122
  return;
57
123
  }
58
- window.ImtblCheckoutWidgetConfig = JSON.stringify(config);
124
+ let globalConfig = {};
125
+ try {
126
+ globalConfig = JSON.parse(window.ImtblCheckoutWidgetConfig);
127
+ } catch (err) {
128
+ // eslint-disable-next-line no-console
129
+ console.warn("Unable to decode window.ImtblCheckoutWidgetConfig: ", err);
130
+ }
131
+ Object.values(($045213b18e9f1f94$export$75be0f6af9650f2c)).forEach((elem)=>{
132
+ const widgets = document.getElementsByTagName(elem);
133
+ if (!widgets) return;
134
+ // Loop through all the widgets to ensure that the script
135
+ // get the correct local configs for the DOM elements and
136
+ // simply update the global configurations.
137
+ for (const e of widgets){
138
+ const widgetConf = $430e3eda76fa4d5f$var$getWidgetConfig(e) || {};
139
+ $430e3eda76fa4d5f$var$setWidgetConfig(e, {
140
+ ...widgetConf,
141
+ ...config
142
+ });
143
+ }
144
+ });
145
+ $430e3eda76fa4d5f$var$saveConfig({
146
+ ...globalConfig,
147
+ ...config
148
+ });
59
149
  }
60
150
 
61
151
 
@@ -162,27 +252,6 @@ $parcel$export($d882ddc5600b1284$exports, "OnRampEventType", () => $d882ddc5600b
162
252
  OnRampEventType["SUCCESS"] = "success";
163
253
  OnRampEventType["FAILURE"] = "failure";
164
254
  })($d882ddc5600b1284$export$66ec39c0924078d8 || ($d882ddc5600b1284$export$66ec39c0924078d8 = {}));
165
- /* eslint-disable @typescript-eslint/naming-convention */
166
-
167
- var $045213b18e9f1f94$exports = {};
168
-
169
- $parcel$export($045213b18e9f1f94$exports, "WidgetTheme", () => $045213b18e9f1f94$export$c88931fdc51854eb);
170
- $parcel$export($045213b18e9f1f94$exports, "CheckoutWidgetTagNames", () => $045213b18e9f1f94$export$75be0f6af9650f2c);
171
- /**
172
- * Enum representing the themes for the Checkout widgets.
173
- */ var $045213b18e9f1f94$export$c88931fdc51854eb;
174
- (function(WidgetTheme) {
175
- WidgetTheme["LIGHT"] = "light";
176
- WidgetTheme["DARK"] = "dark";
177
- })($045213b18e9f1f94$export$c88931fdc51854eb || ($045213b18e9f1f94$export$c88931fdc51854eb = {}));
178
- var $045213b18e9f1f94$export$75be0f6af9650f2c;
179
- (function(CheckoutWidgetTagNames) {
180
- CheckoutWidgetTagNames["CONNECT"] = "imtbl-connect";
181
- CheckoutWidgetTagNames["WALLET"] = "imtbl-wallet";
182
- CheckoutWidgetTagNames["SWAP"] = "imtbl-swap";
183
- CheckoutWidgetTagNames["BRIDGE"] = "imtbl-bridge";
184
- CheckoutWidgetTagNames["ONRAMP"] = "imtbl-onramp";
185
- })($045213b18e9f1f94$export$75be0f6af9650f2c || ($045213b18e9f1f94$export$75be0f6af9650f2c = {}));
186
255
 
187
256
 
188
257
  var $1f969328e5988c99$exports = {};
@@ -16,7 +16,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
16
16
  chainID,
17
17
  coreContractAddress,
18
18
  registrationContractAddress,
19
- sdkVersion: 'ts-immutable-sdk-0.22.2',
19
+ sdkVersion: 'ts-immutable-sdk-0.23.0-alpha',
20
20
  });
21
21
  /**
22
22
  * Sets `sdkVersion` at the time of build