@trustware/sdk-staging 0.0.0 → 1.0.14-staging.11

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.cts CHANGED
@@ -4,6 +4,7 @@ export { API_PREFIX, API_ROOT, ASSETS_BASE_URL, SDK_NAME, SDK_VERSION, WALLETCON
4
4
 
5
5
  declare enum TrustwareErrorCode {
6
6
  INVALID_CONFIG = "INVALID_CONFIG",
7
+ INVALID_API_KEY = "INVALID_API_KEY",
7
8
  WALLET_NOT_CONNECTED = "WALLET_NOT_CONNECTED",
8
9
  BRIDGE_FAILED = "BRIDGE_FAILED",
9
10
  NETWORK_ERROR = "NETWORK_ERROR",
@@ -272,6 +273,9 @@ type ResolvedTrustwareConfig = {
272
273
  messages: TrustwareWidgetMessages;
273
274
  retry: ResolvedRetryConfig;
274
275
  walletConnect?: ResolvedWalletConnectConfig;
276
+ onError?: (error: TrustwareError) => void;
277
+ onSuccess?: (transaction: Transaction) => void;
278
+ onEvent?: (event: TrustwareEvent) => void;
275
279
  };
276
280
  declare const DEFAULT_SLIPPAGE = 1;
277
281
  declare const DEFAULT_AUTO_DETECT_PROVIDER = false;
@@ -692,6 +696,7 @@ type Ctx = {
692
696
  emitError?: (error: TrustwareError) => void;
693
697
  emitSuccess?: (transaction: Transaction) => void;
694
698
  emitEvent?: (event: TrustwareEvent) => void;
699
+ revalidate?: () => Promise<void>;
695
700
  };
696
701
  declare const Ctx: React.Context<Ctx>;
697
702
  declare function TrustwareProvider({ config, wallet, autoDetect, children, }: {
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export { API_PREFIX, API_ROOT, ASSETS_BASE_URL, SDK_NAME, SDK_VERSION, WALLETCON
4
4
 
5
5
  declare enum TrustwareErrorCode {
6
6
  INVALID_CONFIG = "INVALID_CONFIG",
7
+ INVALID_API_KEY = "INVALID_API_KEY",
7
8
  WALLET_NOT_CONNECTED = "WALLET_NOT_CONNECTED",
8
9
  BRIDGE_FAILED = "BRIDGE_FAILED",
9
10
  NETWORK_ERROR = "NETWORK_ERROR",
@@ -272,6 +273,9 @@ type ResolvedTrustwareConfig = {
272
273
  messages: TrustwareWidgetMessages;
273
274
  retry: ResolvedRetryConfig;
274
275
  walletConnect?: ResolvedWalletConnectConfig;
276
+ onError?: (error: TrustwareError) => void;
277
+ onSuccess?: (transaction: Transaction) => void;
278
+ onEvent?: (event: TrustwareEvent) => void;
275
279
  };
276
280
  declare const DEFAULT_SLIPPAGE = 1;
277
281
  declare const DEFAULT_AUTO_DETECT_PROVIDER = false;
@@ -692,6 +696,7 @@ type Ctx = {
692
696
  emitError?: (error: TrustwareError) => void;
693
697
  emitSuccess?: (transaction: Transaction) => void;
694
698
  emitEvent?: (event: TrustwareEvent) => void;
699
+ revalidate?: () => Promise<void>;
695
700
  };
696
701
  declare const Ctx: React.Context<Ctx>;
697
702
  declare function TrustwareProvider({ config, wallet, autoDetect, children, }: {
package/dist/index.mjs CHANGED
@@ -52,7 +52,7 @@ var init_constants = __esm({
52
52
  "src/constants.ts"() {
53
53
  "use strict";
54
54
  SDK_NAME = "@trustware/sdk";
55
- SDK_VERSION = "0.0.0";
55
+ SDK_VERSION = "1.0.14-staging.11";
56
56
  API_ROOT = "https://api.trustware.io";
57
57
  API_PREFIX = "/api";
58
58
  ASSETS_BASE_URL = "https://app.trustware.io";
@@ -150,7 +150,10 @@ function resolveConfig(input) {
150
150
  theme,
151
151
  messages,
152
152
  retry,
153
- walletConnect
153
+ walletConnect,
154
+ onError: input.onError,
155
+ onSuccess: input.onSuccess,
156
+ onEvent: input.onEvent
154
157
  };
155
158
  }
156
159
  var init_merge = __esm({
@@ -1925,6 +1928,25 @@ function useTokens(chainId) {
1925
1928
  };
1926
1929
  }
1927
1930
 
1931
+ // src/errors/TrustwareError.ts
1932
+ var TrustwareError = class extends Error {
1933
+ constructor(params) {
1934
+ super(params.message);
1935
+ this.name = "TrustwareError";
1936
+ this.code = params.code;
1937
+ this.userMessage = params.userMessage;
1938
+ this.cause = params.cause;
1939
+ }
1940
+ toJSON() {
1941
+ return {
1942
+ name: this.name,
1943
+ code: this.code,
1944
+ message: this.message,
1945
+ userMessage: this.userMessage
1946
+ };
1947
+ }
1948
+ };
1949
+
1928
1950
  // src/core/index.ts
1929
1951
  var _lastValidatedKey = null;
1930
1952
  var Trustware = {
@@ -1938,7 +1960,16 @@ var Trustware = {
1938
1960
  _lastValidatedKey = key;
1939
1961
  } catch (err) {
1940
1962
  const reason = err instanceof Error && err.message ? `: ${err.message}` : "";
1941
- throw new Error(`Trustware.init: API key validation failed${reason}`);
1963
+ const error = new TrustwareError({
1964
+ code: "INVALID_API_KEY" /* INVALID_API_KEY */,
1965
+ message: `Trustware.init: API key validation failed${reason}`,
1966
+ userMessage: "API key validation failed. Please verify your Trustware API key.",
1967
+ cause: err
1968
+ });
1969
+ const config = TrustwareConfigStore.get();
1970
+ config.onError?.(error);
1971
+ config.onEvent?.({ type: "error", error });
1972
+ throw error;
1942
1973
  }
1943
1974
  }
1944
1975
  return Trustware;
@@ -2200,6 +2231,7 @@ var zIndex = {
2200
2231
  30: "30",
2201
2232
  40: "40",
2202
2233
  50: "50",
2234
+ 60: "60",
2203
2235
  auto: "auto"
2204
2236
  };
2205
2237
 
@@ -3029,22 +3061,42 @@ function TrustwareProvider({
3029
3061
  [config]
3030
3062
  );
3031
3063
  useWireDetectionIntoManager();
3064
+ const initialize = useCallback2(
3065
+ async (setStatusFn = setStatus, setErrorsFn = setErrors) => {
3066
+ setStatusFn("initializing");
3067
+ setErrorsFn(void 0);
3068
+ await Trustware.init(config);
3069
+ if (wallet) {
3070
+ Trustware.useWallet(wallet);
3071
+ setStatusFn("ready");
3072
+ return;
3073
+ }
3074
+ if (autoDetect) {
3075
+ await Trustware.autoDetect(400);
3076
+ }
3077
+ setStatusFn("ready");
3078
+ },
3079
+ [config, wallet, autoDetect]
3080
+ );
3081
+ const revalidate = useCallback2(async () => {
3082
+ try {
3083
+ await initialize();
3084
+ } catch (e) {
3085
+ setStatus("error");
3086
+ setErrors(e instanceof Error ? e.message : String(e));
3087
+ }
3088
+ }, [initialize]);
3032
3089
  useEffect7(() => {
3033
3090
  let cancelled = false;
3091
+ const setStatusSafe = (s) => {
3092
+ if (!cancelled) setStatus(s);
3093
+ };
3094
+ const setErrorsSafe = (e) => {
3095
+ if (!cancelled) setErrors(e);
3096
+ };
3034
3097
  (async () => {
3035
3098
  try {
3036
- setStatus("initializing");
3037
- setErrors(void 0);
3038
- await Trustware.init(config);
3039
- if (wallet) {
3040
- Trustware.useWallet(wallet);
3041
- if (!cancelled) setStatus("ready");
3042
- return;
3043
- }
3044
- if (autoDetect) {
3045
- await Trustware.autoDetect(400);
3046
- }
3047
- if (!cancelled) setStatus("ready");
3099
+ await initialize(setStatusSafe, setErrorsSafe);
3048
3100
  } catch (e) {
3049
3101
  if (!cancelled) {
3050
3102
  setStatus("error");
@@ -3055,7 +3107,7 @@ function TrustwareProvider({
3055
3107
  return () => {
3056
3108
  cancelled = true;
3057
3109
  };
3058
- }, [config, wallet, autoDetect]);
3110
+ }, [initialize]);
3059
3111
  const value = useMemo6(
3060
3112
  () => ({
3061
3113
  status,
@@ -3063,9 +3115,10 @@ function TrustwareProvider({
3063
3115
  core: Trustware,
3064
3116
  emitError,
3065
3117
  emitSuccess,
3066
- emitEvent
3118
+ emitEvent,
3119
+ revalidate
3067
3120
  }),
3068
- [status, errors, emitError, emitSuccess, emitEvent]
3121
+ [status, errors, emitError, emitSuccess, emitEvent, revalidate]
3069
3122
  );
3070
3123
  return /* @__PURE__ */ jsx(Ctx.Provider, { value, children });
3071
3124
  }
@@ -8725,27 +8778,6 @@ import {
8725
8778
  useCallback as useCallback10
8726
8779
  } from "react";
8727
8780
  import { createPublicClient, encodeFunctionData, erc20Abi, http } from "viem";
8728
-
8729
- // src/errors/TrustwareError.ts
8730
- var TrustwareError = class extends Error {
8731
- constructor(params) {
8732
- super(params.message);
8733
- this.name = "TrustwareError";
8734
- this.code = params.code;
8735
- this.userMessage = params.userMessage;
8736
- this.cause = params.cause;
8737
- }
8738
- toJSON() {
8739
- return {
8740
- name: this.name,
8741
- code: this.code,
8742
- message: this.message,
8743
- userMessage: this.userMessage
8744
- };
8745
- }
8746
- };
8747
-
8748
- // src/widget-v2/pages/CryptoPay.tsx
8749
8781
  import { Fragment as Fragment4, jsx as jsx16, jsxs as jsxs13 } from "react/jsx-runtime";
8750
8782
  function normalizeTokenAddressForCompare(chain, addr) {
8751
8783
  const chainType = (chain.type ?? chain.chainType ?? "").toLowerCase();
@@ -11574,6 +11606,99 @@ function ConfirmCloseDialog({
11574
11606
  }
11575
11607
  ) });
11576
11608
  }
11609
+ function InitErrorOverlay({
11610
+ open,
11611
+ isDark,
11612
+ isRefreshing,
11613
+ onRefresh
11614
+ }) {
11615
+ if (!open) return null;
11616
+ return /* @__PURE__ */ jsx20(
11617
+ "div",
11618
+ {
11619
+ role: "dialog",
11620
+ "aria-modal": "true",
11621
+ "aria-labelledby": "init-error-title",
11622
+ "aria-describedby": "init-error-description",
11623
+ style: {
11624
+ position: "absolute",
11625
+ inset: 0,
11626
+ backgroundColor: isDark ? "rgba(0, 0, 0, 0.55)" : "rgba(0, 0, 0, 0.2)",
11627
+ zIndex: zIndex[40],
11628
+ display: "flex",
11629
+ alignItems: "center",
11630
+ justifyContent: "center",
11631
+ padding: spacing[6],
11632
+ borderRadius: "20px"
11633
+ },
11634
+ children: /* @__PURE__ */ jsxs17(
11635
+ "div",
11636
+ {
11637
+ style: {
11638
+ width: "100%",
11639
+ maxWidth: "420px",
11640
+ borderRadius: borderRadius.xl,
11641
+ padding: spacing[6],
11642
+ backgroundColor: colors.card,
11643
+ color: colors.cardForeground,
11644
+ boxShadow: "0 25px 50px -12px rgb(0 0 0 / 0.35)",
11645
+ textAlign: "left",
11646
+ border: `1px solid ${colors.border}`
11647
+ },
11648
+ children: [
11649
+ /* @__PURE__ */ jsx20(
11650
+ "h2",
11651
+ {
11652
+ id: "init-error-title",
11653
+ style: {
11654
+ fontSize: fontSize.lg,
11655
+ fontWeight: fontWeight.semibold,
11656
+ color: colors.cardForeground
11657
+ },
11658
+ children: "API key validation failed"
11659
+ }
11660
+ ),
11661
+ /* @__PURE__ */ jsx20(
11662
+ "p",
11663
+ {
11664
+ id: "init-error-description",
11665
+ style: {
11666
+ marginTop: spacing[2],
11667
+ fontSize: fontSize.sm,
11668
+ color: colors.mutedForeground
11669
+ },
11670
+ children: "We could not validate your Trustware API key. Please refresh to retry."
11671
+ }
11672
+ ),
11673
+ /* @__PURE__ */ jsx20(
11674
+ "button",
11675
+ {
11676
+ onClick: onRefresh,
11677
+ disabled: isRefreshing,
11678
+ "aria-label": "Refresh validation",
11679
+ style: {
11680
+ marginTop: spacing[4],
11681
+ width: "100%",
11682
+ borderRadius: "0.5rem",
11683
+ backgroundColor: colors.primary,
11684
+ padding: `${spacing[2.5]} ${spacing[4]}`,
11685
+ fontSize: fontSize.sm,
11686
+ fontWeight: fontWeight.medium,
11687
+ color: colors.primaryForeground,
11688
+ border: 0,
11689
+ cursor: isRefreshing ? "not-allowed" : "pointer",
11690
+ opacity: isRefreshing ? 0.7 : 1,
11691
+ transition: "background-color 0.2s"
11692
+ },
11693
+ children: isRefreshing ? "Refreshing..." : "Refresh"
11694
+ }
11695
+ )
11696
+ ]
11697
+ }
11698
+ )
11699
+ }
11700
+ );
11701
+ }
11577
11702
  function WidgetInner({
11578
11703
  style,
11579
11704
  onClose,
@@ -11582,6 +11707,7 @@ function WidgetInner({
11582
11707
  showThemeToggle
11583
11708
  }) {
11584
11709
  const { transactionStatus, resetState, resolvedTheme } = useDeposit();
11710
+ const { status, revalidate } = useTrustware();
11585
11711
  const [showConfirmDialog, setShowConfirmDialog] = useState17(false);
11586
11712
  const handleCloseRequest = useCallback11(() => {
11587
11713
  if (ACTIVE_TRANSACTION_STATUSES.includes(transactionStatus)) {
@@ -11605,14 +11731,30 @@ function WidgetInner({
11605
11731
  setShowConfirmDialog(false);
11606
11732
  }, []);
11607
11733
  const effectiveTheme = resolvedTheme;
11734
+ const isRefreshing = status === "initializing";
11735
+ const initBlocked = status === "error";
11736
+ const handleRefresh = useCallback11(() => {
11737
+ revalidate?.();
11738
+ }, [revalidate]);
11608
11739
  return /* @__PURE__ */ jsxs17(Fragment5, { children: [
11609
- /* @__PURE__ */ jsx20(WidgetContainer, { theme: effectiveTheme, style, children: /* @__PURE__ */ jsx20(
11610
- WidgetContent,
11611
- {
11612
- onStateChange,
11613
- showThemeToggle
11614
- }
11615
- ) }),
11740
+ /* @__PURE__ */ jsxs17(WidgetContainer, { theme: effectiveTheme, style, children: [
11741
+ /* @__PURE__ */ jsx20(
11742
+ WidgetContent,
11743
+ {
11744
+ onStateChange,
11745
+ showThemeToggle
11746
+ }
11747
+ ),
11748
+ /* @__PURE__ */ jsx20(
11749
+ InitErrorOverlay,
11750
+ {
11751
+ open: initBlocked,
11752
+ isDark: resolvedTheme === "dark",
11753
+ isRefreshing,
11754
+ onRefresh: handleRefresh
11755
+ }
11756
+ )
11757
+ ] }),
11616
11758
  /* @__PURE__ */ jsx20(
11617
11759
  ConfirmCloseDialog,
11618
11760
  {