@unifold/connect-react 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.d.mts CHANGED
@@ -52,6 +52,8 @@ interface DepositConfig {
52
52
  depositConfirmationMode?: DepositConfirmationMode;
53
53
  onSuccess?: (data: DepositResult) => void;
54
54
  onError?: (error: DepositError) => void;
55
+ /** Called when the user dismisses the deposit dialog (X button, Escape key, or programmatic close) */
56
+ onClose?: () => void;
55
57
  }
56
58
  declare function UnifoldProvider({ children, publishableKey, config, }: React.PropsWithChildren<UnifoldConnectProviderConfig>): react_jsx_runtime.JSX.Element;
57
59
  declare function useUnifold(): {
package/dist/index.d.ts CHANGED
@@ -52,6 +52,8 @@ interface DepositConfig {
52
52
  depositConfirmationMode?: DepositConfirmationMode;
53
53
  onSuccess?: (data: DepositResult) => void;
54
54
  onError?: (error: DepositError) => void;
55
+ /** Called when the user dismisses the deposit dialog (X button, Escape key, or programmatic close) */
56
+ onClose?: () => void;
55
57
  }
56
58
  declare function UnifoldProvider({ children, publishableKey, config, }: React.PropsWithChildren<UnifoldConnectProviderConfig>): react_jsx_runtime.JSX.Element;
57
59
  declare function useUnifold(): {
package/dist/index.js CHANGED
@@ -6072,7 +6072,7 @@ var API_BASE_URL = (() => {
6072
6072
  return "https://api.unifold.io";
6073
6073
  }
6074
6074
  })();
6075
- var DEFAULT_PUBLISHABLE_KEY = "pk_test_123";
6075
+ var DEFAULT_PUBLISHABLE_KEY = "";
6076
6076
  var DEFAULT_CONFIG = {};
6077
6077
  function setApiConfig(config) {
6078
6078
  if (config.publishableKey !== void 0) {
@@ -6104,11 +6104,6 @@ function validatePublishableKey(key) {
6104
6104
  "Unifold SDK: No publishable key configured. Please provide a valid publishable key via setApiConfig() or pass it directly to the API function."
6105
6105
  );
6106
6106
  }
6107
- if (key === "pk_test_123") {
6108
- console.warn(
6109
- '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.'
6110
- );
6111
- }
6112
6107
  }
6113
6108
  function getIconUrl(iconPath) {
6114
6109
  const normalizedPath = iconPath.startsWith("/") ? iconPath : `/${iconPath}`;
@@ -21865,6 +21860,11 @@ function UnifoldProvider2({
21865
21860
  null
21866
21861
  );
21867
21862
  const [resolvedTheme, setResolvedTheme] = import_react24.default.useState("dark");
21863
+ (0, import_react24.useEffect)(() => {
21864
+ if (publishableKey) {
21865
+ setApiConfig({ publishableKey });
21866
+ }
21867
+ }, [publishableKey]);
21868
21868
  import_react24.default.useEffect(() => {
21869
21869
  const appearance = config?.appearance || "dark";
21870
21870
  if (appearance === "auto") {
@@ -21881,12 +21881,16 @@ function UnifoldProvider2({
21881
21881
  }
21882
21882
  }, [config?.appearance]);
21883
21883
  const depositPromiseRef = import_react24.default.useRef(null);
21884
+ const depositConfigRef = import_react24.default.useRef(null);
21885
+ depositConfigRef.current = depositConfig;
21884
21886
  const closeTimeoutRef = import_react24.default.useRef(null);
21887
+ const closeGuardRef = import_react24.default.useRef(false);
21885
21888
  const beginDeposit = (0, import_react24.useCallback)((config2) => {
21886
21889
  if (closeTimeoutRef.current) {
21887
21890
  clearTimeout(closeTimeoutRef.current);
21888
21891
  closeTimeoutRef.current = null;
21889
21892
  }
21893
+ closeGuardRef.current = false;
21890
21894
  if (depositPromiseRef.current) {
21891
21895
  console.warn("[UnifoldProvider] A deposit is already in progress. Cancelling previous deposit.");
21892
21896
  depositPromiseRef.current.reject({
@@ -21898,17 +21902,27 @@ function UnifoldProvider2({
21898
21902
  const promise = new Promise((resolve, reject) => {
21899
21903
  depositPromiseRef.current = { resolve, reject };
21900
21904
  });
21905
+ promise.catch(() => {
21906
+ });
21901
21907
  setDepositConfig(config2);
21902
21908
  setIsOpen(true);
21903
21909
  return promise;
21904
21910
  }, []);
21905
21911
  const closeDeposit = (0, import_react24.useCallback)(() => {
21906
- if (depositPromiseRef.current) {
21907
- depositPromiseRef.current.reject({
21912
+ if (closeGuardRef.current) {
21913
+ return;
21914
+ }
21915
+ closeGuardRef.current = true;
21916
+ const promiseToReject = depositPromiseRef.current;
21917
+ depositPromiseRef.current = null;
21918
+ if (depositConfigRef.current?.onClose) {
21919
+ depositConfigRef.current.onClose();
21920
+ }
21921
+ if (promiseToReject) {
21922
+ promiseToReject.reject({
21908
21923
  message: "Deposit cancelled by user",
21909
21924
  code: "DEPOSIT_CANCELLED"
21910
21925
  });
21911
- depositPromiseRef.current = null;
21912
21926
  }
21913
21927
  setIsOpen(false);
21914
21928
  closeTimeoutRef.current = setTimeout(() => {
package/dist/index.mjs CHANGED
@@ -1147,7 +1147,8 @@ ${new this._window.XMLSerializer().serializeToString(e3)}`;
1147
1147
  import React38, {
1148
1148
  useState as useState29,
1149
1149
  useCallback as useCallback12,
1150
- useMemo as useMemo15
1150
+ useMemo as useMemo15,
1151
+ useEffect as useEffect29
1151
1152
  } from "react";
1152
1153
 
1153
1154
  // ../react-provider/dist/index.mjs
@@ -6046,7 +6047,7 @@ var API_BASE_URL = (() => {
6046
6047
  return "https://api.unifold.io";
6047
6048
  }
6048
6049
  })();
6049
- var DEFAULT_PUBLISHABLE_KEY = "pk_test_123";
6050
+ var DEFAULT_PUBLISHABLE_KEY = "";
6050
6051
  var DEFAULT_CONFIG = {};
6051
6052
  function setApiConfig(config) {
6052
6053
  if (config.publishableKey !== void 0) {
@@ -6078,11 +6079,6 @@ function validatePublishableKey(key) {
6078
6079
  "Unifold SDK: No publishable key configured. Please provide a valid publishable key via setApiConfig() or pass it directly to the API function."
6079
6080
  );
6080
6081
  }
6081
- if (key === "pk_test_123") {
6082
- console.warn(
6083
- '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.'
6084
- );
6085
- }
6086
6082
  }
6087
6083
  function getIconUrl(iconPath) {
6088
6084
  const normalizedPath = iconPath.startsWith("/") ? iconPath : `/${iconPath}`;
@@ -21839,6 +21835,11 @@ function UnifoldProvider2({
21839
21835
  null
21840
21836
  );
21841
21837
  const [resolvedTheme, setResolvedTheme] = React38.useState("dark");
21838
+ useEffect29(() => {
21839
+ if (publishableKey) {
21840
+ setApiConfig({ publishableKey });
21841
+ }
21842
+ }, [publishableKey]);
21842
21843
  React38.useEffect(() => {
21843
21844
  const appearance = config?.appearance || "dark";
21844
21845
  if (appearance === "auto") {
@@ -21855,12 +21856,16 @@ function UnifoldProvider2({
21855
21856
  }
21856
21857
  }, [config?.appearance]);
21857
21858
  const depositPromiseRef = React38.useRef(null);
21859
+ const depositConfigRef = React38.useRef(null);
21860
+ depositConfigRef.current = depositConfig;
21858
21861
  const closeTimeoutRef = React38.useRef(null);
21862
+ const closeGuardRef = React38.useRef(false);
21859
21863
  const beginDeposit = useCallback12((config2) => {
21860
21864
  if (closeTimeoutRef.current) {
21861
21865
  clearTimeout(closeTimeoutRef.current);
21862
21866
  closeTimeoutRef.current = null;
21863
21867
  }
21868
+ closeGuardRef.current = false;
21864
21869
  if (depositPromiseRef.current) {
21865
21870
  console.warn("[UnifoldProvider] A deposit is already in progress. Cancelling previous deposit.");
21866
21871
  depositPromiseRef.current.reject({
@@ -21872,17 +21877,27 @@ function UnifoldProvider2({
21872
21877
  const promise = new Promise((resolve, reject) => {
21873
21878
  depositPromiseRef.current = { resolve, reject };
21874
21879
  });
21880
+ promise.catch(() => {
21881
+ });
21875
21882
  setDepositConfig(config2);
21876
21883
  setIsOpen(true);
21877
21884
  return promise;
21878
21885
  }, []);
21879
21886
  const closeDeposit = useCallback12(() => {
21880
- if (depositPromiseRef.current) {
21881
- depositPromiseRef.current.reject({
21887
+ if (closeGuardRef.current) {
21888
+ return;
21889
+ }
21890
+ closeGuardRef.current = true;
21891
+ const promiseToReject = depositPromiseRef.current;
21892
+ depositPromiseRef.current = null;
21893
+ if (depositConfigRef.current?.onClose) {
21894
+ depositConfigRef.current.onClose();
21895
+ }
21896
+ if (promiseToReject) {
21897
+ promiseToReject.reject({
21882
21898
  message: "Deposit cancelled by user",
21883
21899
  code: "DEPOSIT_CANCELLED"
21884
21900
  });
21885
- depositPromiseRef.current = null;
21886
21901
  }
21887
21902
  setIsOpen(false);
21888
21903
  closeTimeoutRef.current = setTimeout(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unifold/connect-react",
3
- "version": "0.1.33",
3
+ "version": "0.1.34",
4
4
  "description": "Unifold Connect React - Complete React SDK with UI components for crypto deposits",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -31,9 +31,9 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@tanstack/react-query": "^5.90.11",
34
- "@unifold/core": "0.1.33",
35
- "@unifold/ui-react": "0.1.33",
36
- "@unifold/react-provider": "0.1.33"
34
+ "@unifold/core": "0.1.34",
35
+ "@unifold/ui-react": "0.1.34",
36
+ "@unifold/react-provider": "0.1.34"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/react": "^19.0.0",