@unifold/ui-web 0.1.33 → 0.1.34
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/index.js +44 -9
- package/dist/index.mjs +44 -9
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -43049,19 +43049,35 @@ var API_BASE_URL = (() => {
|
|
|
43049
43049
|
return "https://api.unifold.io";
|
|
43050
43050
|
}
|
|
43051
43051
|
})();
|
|
43052
|
-
var DEFAULT_PUBLISHABLE_KEY = "
|
|
43052
|
+
var DEFAULT_PUBLISHABLE_KEY = "";
|
|
43053
43053
|
var DEFAULT_CONFIG = {};
|
|
43054
|
+
function setApiConfig(config) {
|
|
43055
|
+
if (config.publishableKey !== void 0) {
|
|
43056
|
+
if (!config.publishableKey || config.publishableKey.trim() === "") {
|
|
43057
|
+
throw new Error(
|
|
43058
|
+
"Unifold SDK: publishableKey cannot be empty. Please provide a valid publishable key."
|
|
43059
|
+
);
|
|
43060
|
+
}
|
|
43061
|
+
if (!config.publishableKey.startsWith("pk_test_") && !config.publishableKey.startsWith("pk_live_")) {
|
|
43062
|
+
console.warn(
|
|
43063
|
+
'Unifold SDK: publishableKey should start with "pk_test_" or "pk_live_". Please ensure you are using a valid publishable key.'
|
|
43064
|
+
);
|
|
43065
|
+
}
|
|
43066
|
+
DEFAULT_PUBLISHABLE_KEY = config.publishableKey;
|
|
43067
|
+
}
|
|
43068
|
+
if (config.baseUrl) {
|
|
43069
|
+
API_BASE_URL = config.baseUrl;
|
|
43070
|
+
}
|
|
43071
|
+
if (config.defaultConfig) {
|
|
43072
|
+
DEFAULT_CONFIG = config.defaultConfig;
|
|
43073
|
+
}
|
|
43074
|
+
}
|
|
43054
43075
|
function validatePublishableKey(key) {
|
|
43055
43076
|
if (!key || key.trim() === "") {
|
|
43056
43077
|
throw new Error(
|
|
43057
43078
|
"Unifold SDK: No publishable key configured. Please provide a valid publishable key via setApiConfig() or pass it directly to the API function."
|
|
43058
43079
|
);
|
|
43059
43080
|
}
|
|
43060
|
-
if (key === "pk_test_123") {
|
|
43061
|
-
console.warn(
|
|
43062
|
-
'Unifold SDK: Using default test key "pk_test_123". This should only be used for local development. Please use a real publishable key in production.'
|
|
43063
|
-
);
|
|
43064
|
-
}
|
|
43065
43081
|
}
|
|
43066
43082
|
function getIconUrl(iconPath) {
|
|
43067
43083
|
const normalizedPath = iconPath.startsWith("/") ? iconPath : `/${iconPath}`;
|
|
@@ -58531,6 +58547,11 @@ function UnifoldProvider2({
|
|
|
58531
58547
|
null
|
|
58532
58548
|
);
|
|
58533
58549
|
const [resolvedTheme, setResolvedTheme] = import_react.default.useState("dark");
|
|
58550
|
+
(0, import_react.useEffect)(() => {
|
|
58551
|
+
if (publishableKey) {
|
|
58552
|
+
setApiConfig({ publishableKey });
|
|
58553
|
+
}
|
|
58554
|
+
}, [publishableKey]);
|
|
58534
58555
|
import_react.default.useEffect(() => {
|
|
58535
58556
|
const appearance = config?.appearance || "dark";
|
|
58536
58557
|
if (appearance === "auto") {
|
|
@@ -58547,12 +58568,16 @@ function UnifoldProvider2({
|
|
|
58547
58568
|
}
|
|
58548
58569
|
}, [config?.appearance]);
|
|
58549
58570
|
const depositPromiseRef = import_react.default.useRef(null);
|
|
58571
|
+
const depositConfigRef = import_react.default.useRef(null);
|
|
58572
|
+
depositConfigRef.current = depositConfig;
|
|
58550
58573
|
const closeTimeoutRef = import_react.default.useRef(null);
|
|
58574
|
+
const closeGuardRef = import_react.default.useRef(false);
|
|
58551
58575
|
const beginDeposit = (0, import_react.useCallback)((config2) => {
|
|
58552
58576
|
if (closeTimeoutRef.current) {
|
|
58553
58577
|
clearTimeout(closeTimeoutRef.current);
|
|
58554
58578
|
closeTimeoutRef.current = null;
|
|
58555
58579
|
}
|
|
58580
|
+
closeGuardRef.current = false;
|
|
58556
58581
|
if (depositPromiseRef.current) {
|
|
58557
58582
|
console.warn("[UnifoldProvider] A deposit is already in progress. Cancelling previous deposit.");
|
|
58558
58583
|
depositPromiseRef.current.reject({
|
|
@@ -58564,17 +58589,27 @@ function UnifoldProvider2({
|
|
|
58564
58589
|
const promise = new Promise((resolve, reject) => {
|
|
58565
58590
|
depositPromiseRef.current = { resolve, reject };
|
|
58566
58591
|
});
|
|
58592
|
+
promise.catch(() => {
|
|
58593
|
+
});
|
|
58567
58594
|
setDepositConfig(config2);
|
|
58568
58595
|
setIsOpen(true);
|
|
58569
58596
|
return promise;
|
|
58570
58597
|
}, []);
|
|
58571
58598
|
const closeDeposit = (0, import_react.useCallback)(() => {
|
|
58572
|
-
if (
|
|
58573
|
-
|
|
58599
|
+
if (closeGuardRef.current) {
|
|
58600
|
+
return;
|
|
58601
|
+
}
|
|
58602
|
+
closeGuardRef.current = true;
|
|
58603
|
+
const promiseToReject = depositPromiseRef.current;
|
|
58604
|
+
depositPromiseRef.current = null;
|
|
58605
|
+
if (depositConfigRef.current?.onClose) {
|
|
58606
|
+
depositConfigRef.current.onClose();
|
|
58607
|
+
}
|
|
58608
|
+
if (promiseToReject) {
|
|
58609
|
+
promiseToReject.reject({
|
|
58574
58610
|
message: "Deposit cancelled by user",
|
|
58575
58611
|
code: "DEPOSIT_CANCELLED"
|
|
58576
58612
|
});
|
|
58577
|
-
depositPromiseRef.current = null;
|
|
58578
58613
|
}
|
|
58579
58614
|
setIsOpen(false);
|
|
58580
58615
|
closeTimeoutRef.current = setTimeout(() => {
|
package/dist/index.mjs
CHANGED
|
@@ -43036,19 +43036,35 @@ var API_BASE_URL = (() => {
|
|
|
43036
43036
|
return "https://api.unifold.io";
|
|
43037
43037
|
}
|
|
43038
43038
|
})();
|
|
43039
|
-
var DEFAULT_PUBLISHABLE_KEY = "
|
|
43039
|
+
var DEFAULT_PUBLISHABLE_KEY = "";
|
|
43040
43040
|
var DEFAULT_CONFIG = {};
|
|
43041
|
+
function setApiConfig(config) {
|
|
43042
|
+
if (config.publishableKey !== void 0) {
|
|
43043
|
+
if (!config.publishableKey || config.publishableKey.trim() === "") {
|
|
43044
|
+
throw new Error(
|
|
43045
|
+
"Unifold SDK: publishableKey cannot be empty. Please provide a valid publishable key."
|
|
43046
|
+
);
|
|
43047
|
+
}
|
|
43048
|
+
if (!config.publishableKey.startsWith("pk_test_") && !config.publishableKey.startsWith("pk_live_")) {
|
|
43049
|
+
console.warn(
|
|
43050
|
+
'Unifold SDK: publishableKey should start with "pk_test_" or "pk_live_". Please ensure you are using a valid publishable key.'
|
|
43051
|
+
);
|
|
43052
|
+
}
|
|
43053
|
+
DEFAULT_PUBLISHABLE_KEY = config.publishableKey;
|
|
43054
|
+
}
|
|
43055
|
+
if (config.baseUrl) {
|
|
43056
|
+
API_BASE_URL = config.baseUrl;
|
|
43057
|
+
}
|
|
43058
|
+
if (config.defaultConfig) {
|
|
43059
|
+
DEFAULT_CONFIG = config.defaultConfig;
|
|
43060
|
+
}
|
|
43061
|
+
}
|
|
43041
43062
|
function validatePublishableKey(key) {
|
|
43042
43063
|
if (!key || key.trim() === "") {
|
|
43043
43064
|
throw new Error(
|
|
43044
43065
|
"Unifold SDK: No publishable key configured. Please provide a valid publishable key via setApiConfig() or pass it directly to the API function."
|
|
43045
43066
|
);
|
|
43046
43067
|
}
|
|
43047
|
-
if (key === "pk_test_123") {
|
|
43048
|
-
console.warn(
|
|
43049
|
-
'Unifold SDK: Using default test key "pk_test_123". This should only be used for local development. Please use a real publishable key in production.'
|
|
43050
|
-
);
|
|
43051
|
-
}
|
|
43052
43068
|
}
|
|
43053
43069
|
function getIconUrl(iconPath) {
|
|
43054
43070
|
const normalizedPath = iconPath.startsWith("/") ? iconPath : `/${iconPath}`;
|
|
@@ -58518,6 +58534,11 @@ function UnifoldProvider2({
|
|
|
58518
58534
|
null
|
|
58519
58535
|
);
|
|
58520
58536
|
const [resolvedTheme, setResolvedTheme] = import_react.default.useState("dark");
|
|
58537
|
+
(0, import_react.useEffect)(() => {
|
|
58538
|
+
if (publishableKey) {
|
|
58539
|
+
setApiConfig({ publishableKey });
|
|
58540
|
+
}
|
|
58541
|
+
}, [publishableKey]);
|
|
58521
58542
|
import_react.default.useEffect(() => {
|
|
58522
58543
|
const appearance = config?.appearance || "dark";
|
|
58523
58544
|
if (appearance === "auto") {
|
|
@@ -58534,12 +58555,16 @@ function UnifoldProvider2({
|
|
|
58534
58555
|
}
|
|
58535
58556
|
}, [config?.appearance]);
|
|
58536
58557
|
const depositPromiseRef = import_react.default.useRef(null);
|
|
58558
|
+
const depositConfigRef = import_react.default.useRef(null);
|
|
58559
|
+
depositConfigRef.current = depositConfig;
|
|
58537
58560
|
const closeTimeoutRef = import_react.default.useRef(null);
|
|
58561
|
+
const closeGuardRef = import_react.default.useRef(false);
|
|
58538
58562
|
const beginDeposit = (0, import_react.useCallback)((config2) => {
|
|
58539
58563
|
if (closeTimeoutRef.current) {
|
|
58540
58564
|
clearTimeout(closeTimeoutRef.current);
|
|
58541
58565
|
closeTimeoutRef.current = null;
|
|
58542
58566
|
}
|
|
58567
|
+
closeGuardRef.current = false;
|
|
58543
58568
|
if (depositPromiseRef.current) {
|
|
58544
58569
|
console.warn("[UnifoldProvider] A deposit is already in progress. Cancelling previous deposit.");
|
|
58545
58570
|
depositPromiseRef.current.reject({
|
|
@@ -58551,17 +58576,27 @@ function UnifoldProvider2({
|
|
|
58551
58576
|
const promise = new Promise((resolve, reject) => {
|
|
58552
58577
|
depositPromiseRef.current = { resolve, reject };
|
|
58553
58578
|
});
|
|
58579
|
+
promise.catch(() => {
|
|
58580
|
+
});
|
|
58554
58581
|
setDepositConfig(config2);
|
|
58555
58582
|
setIsOpen(true);
|
|
58556
58583
|
return promise;
|
|
58557
58584
|
}, []);
|
|
58558
58585
|
const closeDeposit = (0, import_react.useCallback)(() => {
|
|
58559
|
-
if (
|
|
58560
|
-
|
|
58586
|
+
if (closeGuardRef.current) {
|
|
58587
|
+
return;
|
|
58588
|
+
}
|
|
58589
|
+
closeGuardRef.current = true;
|
|
58590
|
+
const promiseToReject = depositPromiseRef.current;
|
|
58591
|
+
depositPromiseRef.current = null;
|
|
58592
|
+
if (depositConfigRef.current?.onClose) {
|
|
58593
|
+
depositConfigRef.current.onClose();
|
|
58594
|
+
}
|
|
58595
|
+
if (promiseToReject) {
|
|
58596
|
+
promiseToReject.reject({
|
|
58561
58597
|
message: "Deposit cancelled by user",
|
|
58562
58598
|
code: "DEPOSIT_CANCELLED"
|
|
58563
58599
|
});
|
|
58564
|
-
depositPromiseRef.current = null;
|
|
58565
58600
|
}
|
|
58566
58601
|
setIsOpen(false);
|
|
58567
58602
|
closeTimeoutRef.current = setTimeout(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unifold/ui-web",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.34",
|
|
4
4
|
"description": "Unifold UI Web - Framework-agnostic deposit widget",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"@types/react-dom": "^19.0.0",
|
|
28
28
|
"tsup": "^8.0.0",
|
|
29
29
|
"typescript": "^5.0.0",
|
|
30
|
-
"@unifold/
|
|
31
|
-
"@unifold/
|
|
32
|
-
"@unifold/react-provider": "0.1.
|
|
33
|
-
"@unifold/
|
|
30
|
+
"@unifold/connect-react": "0.1.34",
|
|
31
|
+
"@unifold/ui-react": "0.1.34",
|
|
32
|
+
"@unifold/react-provider": "0.1.34",
|
|
33
|
+
"@unifold/core": "0.1.34"
|
|
34
34
|
},
|
|
35
35
|
"keywords": [
|
|
36
36
|
"unifold",
|