@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/constants.cjs +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/index.cjs +188 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +188 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/constants.cjs
CHANGED
|
@@ -29,7 +29,7 @@ __export(constants_exports, {
|
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(constants_exports);
|
|
31
31
|
var SDK_NAME = "@trustware/sdk";
|
|
32
|
-
var SDK_VERSION = "
|
|
32
|
+
var SDK_VERSION = "1.0.14-staging.11";
|
|
33
33
|
var API_ROOT = "https://api.trustware.io";
|
|
34
34
|
var API_PREFIX = "/api";
|
|
35
35
|
var ASSETS_BASE_URL = "https://app.trustware.io";
|
package/dist/constants.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -74,7 +74,7 @@ var init_constants = __esm({
|
|
|
74
74
|
"src/constants.ts"() {
|
|
75
75
|
"use strict";
|
|
76
76
|
SDK_NAME = "@trustware/sdk";
|
|
77
|
-
SDK_VERSION = "
|
|
77
|
+
SDK_VERSION = "1.0.14-staging.11";
|
|
78
78
|
API_ROOT = "https://api.trustware.io";
|
|
79
79
|
API_PREFIX = "/api";
|
|
80
80
|
ASSETS_BASE_URL = "https://app.trustware.io";
|
|
@@ -172,7 +172,10 @@ function resolveConfig(input) {
|
|
|
172
172
|
theme,
|
|
173
173
|
messages,
|
|
174
174
|
retry,
|
|
175
|
-
walletConnect
|
|
175
|
+
walletConnect,
|
|
176
|
+
onError: input.onError,
|
|
177
|
+
onSuccess: input.onSuccess,
|
|
178
|
+
onEvent: input.onEvent
|
|
176
179
|
};
|
|
177
180
|
}
|
|
178
181
|
var init_merge = __esm({
|
|
@@ -1976,6 +1979,25 @@ function useTokens(chainId) {
|
|
|
1976
1979
|
};
|
|
1977
1980
|
}
|
|
1978
1981
|
|
|
1982
|
+
// src/errors/TrustwareError.ts
|
|
1983
|
+
var TrustwareError = class extends Error {
|
|
1984
|
+
constructor(params) {
|
|
1985
|
+
super(params.message);
|
|
1986
|
+
this.name = "TrustwareError";
|
|
1987
|
+
this.code = params.code;
|
|
1988
|
+
this.userMessage = params.userMessage;
|
|
1989
|
+
this.cause = params.cause;
|
|
1990
|
+
}
|
|
1991
|
+
toJSON() {
|
|
1992
|
+
return {
|
|
1993
|
+
name: this.name,
|
|
1994
|
+
code: this.code,
|
|
1995
|
+
message: this.message,
|
|
1996
|
+
userMessage: this.userMessage
|
|
1997
|
+
};
|
|
1998
|
+
}
|
|
1999
|
+
};
|
|
2000
|
+
|
|
1979
2001
|
// src/core/index.ts
|
|
1980
2002
|
var _lastValidatedKey = null;
|
|
1981
2003
|
var Trustware = {
|
|
@@ -1989,7 +2011,16 @@ var Trustware = {
|
|
|
1989
2011
|
_lastValidatedKey = key;
|
|
1990
2012
|
} catch (err) {
|
|
1991
2013
|
const reason = err instanceof Error && err.message ? `: ${err.message}` : "";
|
|
1992
|
-
|
|
2014
|
+
const error = new TrustwareError({
|
|
2015
|
+
code: "INVALID_API_KEY" /* INVALID_API_KEY */,
|
|
2016
|
+
message: `Trustware.init: API key validation failed${reason}`,
|
|
2017
|
+
userMessage: "API key validation failed. Please verify your Trustware API key.",
|
|
2018
|
+
cause: err
|
|
2019
|
+
});
|
|
2020
|
+
const config = TrustwareConfigStore.get();
|
|
2021
|
+
config.onError?.(error);
|
|
2022
|
+
config.onEvent?.({ type: "error", error });
|
|
2023
|
+
throw error;
|
|
1993
2024
|
}
|
|
1994
2025
|
}
|
|
1995
2026
|
return Trustware;
|
|
@@ -2244,6 +2275,7 @@ var zIndex = {
|
|
|
2244
2275
|
30: "30",
|
|
2245
2276
|
40: "40",
|
|
2246
2277
|
50: "50",
|
|
2278
|
+
60: "60",
|
|
2247
2279
|
auto: "auto"
|
|
2248
2280
|
};
|
|
2249
2281
|
|
|
@@ -3058,22 +3090,42 @@ function TrustwareProvider({
|
|
|
3058
3090
|
[config]
|
|
3059
3091
|
);
|
|
3060
3092
|
useWireDetectionIntoManager();
|
|
3093
|
+
const initialize = (0, import_react9.useCallback)(
|
|
3094
|
+
async (setStatusFn = setStatus, setErrorsFn = setErrors) => {
|
|
3095
|
+
setStatusFn("initializing");
|
|
3096
|
+
setErrorsFn(void 0);
|
|
3097
|
+
await Trustware.init(config);
|
|
3098
|
+
if (wallet) {
|
|
3099
|
+
Trustware.useWallet(wallet);
|
|
3100
|
+
setStatusFn("ready");
|
|
3101
|
+
return;
|
|
3102
|
+
}
|
|
3103
|
+
if (autoDetect) {
|
|
3104
|
+
await Trustware.autoDetect(400);
|
|
3105
|
+
}
|
|
3106
|
+
setStatusFn("ready");
|
|
3107
|
+
},
|
|
3108
|
+
[config, wallet, autoDetect]
|
|
3109
|
+
);
|
|
3110
|
+
const revalidate = (0, import_react9.useCallback)(async () => {
|
|
3111
|
+
try {
|
|
3112
|
+
await initialize();
|
|
3113
|
+
} catch (e) {
|
|
3114
|
+
setStatus("error");
|
|
3115
|
+
setErrors(e instanceof Error ? e.message : String(e));
|
|
3116
|
+
}
|
|
3117
|
+
}, [initialize]);
|
|
3061
3118
|
(0, import_react9.useEffect)(() => {
|
|
3062
3119
|
let cancelled = false;
|
|
3120
|
+
const setStatusSafe = (s) => {
|
|
3121
|
+
if (!cancelled) setStatus(s);
|
|
3122
|
+
};
|
|
3123
|
+
const setErrorsSafe = (e) => {
|
|
3124
|
+
if (!cancelled) setErrors(e);
|
|
3125
|
+
};
|
|
3063
3126
|
(async () => {
|
|
3064
3127
|
try {
|
|
3065
|
-
|
|
3066
|
-
setErrors(void 0);
|
|
3067
|
-
await Trustware.init(config);
|
|
3068
|
-
if (wallet) {
|
|
3069
|
-
Trustware.useWallet(wallet);
|
|
3070
|
-
if (!cancelled) setStatus("ready");
|
|
3071
|
-
return;
|
|
3072
|
-
}
|
|
3073
|
-
if (autoDetect) {
|
|
3074
|
-
await Trustware.autoDetect(400);
|
|
3075
|
-
}
|
|
3076
|
-
if (!cancelled) setStatus("ready");
|
|
3128
|
+
await initialize(setStatusSafe, setErrorsSafe);
|
|
3077
3129
|
} catch (e) {
|
|
3078
3130
|
if (!cancelled) {
|
|
3079
3131
|
setStatus("error");
|
|
@@ -3084,7 +3136,7 @@ function TrustwareProvider({
|
|
|
3084
3136
|
return () => {
|
|
3085
3137
|
cancelled = true;
|
|
3086
3138
|
};
|
|
3087
|
-
}, [
|
|
3139
|
+
}, [initialize]);
|
|
3088
3140
|
const value = (0, import_react9.useMemo)(
|
|
3089
3141
|
() => ({
|
|
3090
3142
|
status,
|
|
@@ -3092,9 +3144,10 @@ function TrustwareProvider({
|
|
|
3092
3144
|
core: Trustware,
|
|
3093
3145
|
emitError,
|
|
3094
3146
|
emitSuccess,
|
|
3095
|
-
emitEvent
|
|
3147
|
+
emitEvent,
|
|
3148
|
+
revalidate
|
|
3096
3149
|
}),
|
|
3097
|
-
[status, errors, emitError, emitSuccess, emitEvent]
|
|
3150
|
+
[status, errors, emitError, emitSuccess, emitEvent, revalidate]
|
|
3098
3151
|
);
|
|
3099
3152
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Ctx.Provider, { value, children });
|
|
3100
3153
|
}
|
|
@@ -8742,27 +8795,6 @@ function SelectToken({ style }) {
|
|
|
8742
8795
|
// src/widget-v2/pages/CryptoPay.tsx
|
|
8743
8796
|
var import_react22 = require("react");
|
|
8744
8797
|
var import_viem = require("viem");
|
|
8745
|
-
|
|
8746
|
-
// src/errors/TrustwareError.ts
|
|
8747
|
-
var TrustwareError = class extends Error {
|
|
8748
|
-
constructor(params) {
|
|
8749
|
-
super(params.message);
|
|
8750
|
-
this.name = "TrustwareError";
|
|
8751
|
-
this.code = params.code;
|
|
8752
|
-
this.userMessage = params.userMessage;
|
|
8753
|
-
this.cause = params.cause;
|
|
8754
|
-
}
|
|
8755
|
-
toJSON() {
|
|
8756
|
-
return {
|
|
8757
|
-
name: this.name,
|
|
8758
|
-
code: this.code,
|
|
8759
|
-
message: this.message,
|
|
8760
|
-
userMessage: this.userMessage
|
|
8761
|
-
};
|
|
8762
|
-
}
|
|
8763
|
-
};
|
|
8764
|
-
|
|
8765
|
-
// src/widget-v2/pages/CryptoPay.tsx
|
|
8766
8798
|
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
8767
8799
|
function normalizeTokenAddressForCompare(chain, addr) {
|
|
8768
8800
|
const chainType = (chain.type ?? chain.chainType ?? "").toLowerCase();
|
|
@@ -11591,6 +11623,99 @@ function ConfirmCloseDialog({
|
|
|
11591
11623
|
}
|
|
11592
11624
|
) });
|
|
11593
11625
|
}
|
|
11626
|
+
function InitErrorOverlay({
|
|
11627
|
+
open,
|
|
11628
|
+
isDark,
|
|
11629
|
+
isRefreshing,
|
|
11630
|
+
onRefresh
|
|
11631
|
+
}) {
|
|
11632
|
+
if (!open) return null;
|
|
11633
|
+
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
11634
|
+
"div",
|
|
11635
|
+
{
|
|
11636
|
+
role: "dialog",
|
|
11637
|
+
"aria-modal": "true",
|
|
11638
|
+
"aria-labelledby": "init-error-title",
|
|
11639
|
+
"aria-describedby": "init-error-description",
|
|
11640
|
+
style: {
|
|
11641
|
+
position: "absolute",
|
|
11642
|
+
inset: 0,
|
|
11643
|
+
backgroundColor: isDark ? "rgba(0, 0, 0, 0.55)" : "rgba(0, 0, 0, 0.2)",
|
|
11644
|
+
zIndex: zIndex[40],
|
|
11645
|
+
display: "flex",
|
|
11646
|
+
alignItems: "center",
|
|
11647
|
+
justifyContent: "center",
|
|
11648
|
+
padding: spacing[6],
|
|
11649
|
+
borderRadius: "20px"
|
|
11650
|
+
},
|
|
11651
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
|
|
11652
|
+
"div",
|
|
11653
|
+
{
|
|
11654
|
+
style: {
|
|
11655
|
+
width: "100%",
|
|
11656
|
+
maxWidth: "420px",
|
|
11657
|
+
borderRadius: borderRadius.xl,
|
|
11658
|
+
padding: spacing[6],
|
|
11659
|
+
backgroundColor: colors.card,
|
|
11660
|
+
color: colors.cardForeground,
|
|
11661
|
+
boxShadow: "0 25px 50px -12px rgb(0 0 0 / 0.35)",
|
|
11662
|
+
textAlign: "left",
|
|
11663
|
+
border: `1px solid ${colors.border}`
|
|
11664
|
+
},
|
|
11665
|
+
children: [
|
|
11666
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
11667
|
+
"h2",
|
|
11668
|
+
{
|
|
11669
|
+
id: "init-error-title",
|
|
11670
|
+
style: {
|
|
11671
|
+
fontSize: fontSize.lg,
|
|
11672
|
+
fontWeight: fontWeight.semibold,
|
|
11673
|
+
color: colors.cardForeground
|
|
11674
|
+
},
|
|
11675
|
+
children: "API key validation failed"
|
|
11676
|
+
}
|
|
11677
|
+
),
|
|
11678
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
11679
|
+
"p",
|
|
11680
|
+
{
|
|
11681
|
+
id: "init-error-description",
|
|
11682
|
+
style: {
|
|
11683
|
+
marginTop: spacing[2],
|
|
11684
|
+
fontSize: fontSize.sm,
|
|
11685
|
+
color: colors.mutedForeground
|
|
11686
|
+
},
|
|
11687
|
+
children: "We could not validate your Trustware API key. Please refresh to retry."
|
|
11688
|
+
}
|
|
11689
|
+
),
|
|
11690
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
11691
|
+
"button",
|
|
11692
|
+
{
|
|
11693
|
+
onClick: onRefresh,
|
|
11694
|
+
disabled: isRefreshing,
|
|
11695
|
+
"aria-label": "Refresh validation",
|
|
11696
|
+
style: {
|
|
11697
|
+
marginTop: spacing[4],
|
|
11698
|
+
width: "100%",
|
|
11699
|
+
borderRadius: "0.5rem",
|
|
11700
|
+
backgroundColor: colors.primary,
|
|
11701
|
+
padding: `${spacing[2.5]} ${spacing[4]}`,
|
|
11702
|
+
fontSize: fontSize.sm,
|
|
11703
|
+
fontWeight: fontWeight.medium,
|
|
11704
|
+
color: colors.primaryForeground,
|
|
11705
|
+
border: 0,
|
|
11706
|
+
cursor: isRefreshing ? "not-allowed" : "pointer",
|
|
11707
|
+
opacity: isRefreshing ? 0.7 : 1,
|
|
11708
|
+
transition: "background-color 0.2s"
|
|
11709
|
+
},
|
|
11710
|
+
children: isRefreshing ? "Refreshing..." : "Refresh"
|
|
11711
|
+
}
|
|
11712
|
+
)
|
|
11713
|
+
]
|
|
11714
|
+
}
|
|
11715
|
+
)
|
|
11716
|
+
}
|
|
11717
|
+
);
|
|
11718
|
+
}
|
|
11594
11719
|
function WidgetInner({
|
|
11595
11720
|
style,
|
|
11596
11721
|
onClose,
|
|
@@ -11599,6 +11724,7 @@ function WidgetInner({
|
|
|
11599
11724
|
showThemeToggle
|
|
11600
11725
|
}) {
|
|
11601
11726
|
const { transactionStatus, resetState, resolvedTheme } = useDeposit();
|
|
11727
|
+
const { status, revalidate } = useTrustware();
|
|
11602
11728
|
const [showConfirmDialog, setShowConfirmDialog] = (0, import_react26.useState)(false);
|
|
11603
11729
|
const handleCloseRequest = (0, import_react26.useCallback)(() => {
|
|
11604
11730
|
if (ACTIVE_TRANSACTION_STATUSES.includes(transactionStatus)) {
|
|
@@ -11622,14 +11748,30 @@ function WidgetInner({
|
|
|
11622
11748
|
setShowConfirmDialog(false);
|
|
11623
11749
|
}, []);
|
|
11624
11750
|
const effectiveTheme = resolvedTheme;
|
|
11751
|
+
const isRefreshing = status === "initializing";
|
|
11752
|
+
const initBlocked = status === "error";
|
|
11753
|
+
const handleRefresh = (0, import_react26.useCallback)(() => {
|
|
11754
|
+
revalidate?.();
|
|
11755
|
+
}, [revalidate]);
|
|
11625
11756
|
return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
|
|
11626
|
-
/* @__PURE__ */ (0, import_jsx_runtime20.
|
|
11627
|
-
|
|
11628
|
-
|
|
11629
|
-
|
|
11630
|
-
|
|
11631
|
-
|
|
11632
|
-
|
|
11757
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(WidgetContainer, { theme: effectiveTheme, style, children: [
|
|
11758
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
11759
|
+
WidgetContent,
|
|
11760
|
+
{
|
|
11761
|
+
onStateChange,
|
|
11762
|
+
showThemeToggle
|
|
11763
|
+
}
|
|
11764
|
+
),
|
|
11765
|
+
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
11766
|
+
InitErrorOverlay,
|
|
11767
|
+
{
|
|
11768
|
+
open: initBlocked,
|
|
11769
|
+
isDark: resolvedTheme === "dark",
|
|
11770
|
+
isRefreshing,
|
|
11771
|
+
onRefresh: handleRefresh
|
|
11772
|
+
}
|
|
11773
|
+
)
|
|
11774
|
+
] }),
|
|
11633
11775
|
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
11634
11776
|
ConfirmCloseDialog,
|
|
11635
11777
|
{
|