@swype-org/react-sdk 0.1.48 → 0.1.49
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.cjs +91 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +92 -31
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -669,13 +669,20 @@ function isInCrossOriginIframe() {
|
|
|
669
669
|
}
|
|
670
670
|
}
|
|
671
671
|
var delegationCounter = 0;
|
|
672
|
+
var DELEGATION_CREATE_TIMEOUT_MS = 6e4;
|
|
673
|
+
var DELEGATION_GET_TIMEOUT_MS = 3e4;
|
|
672
674
|
function delegatePasskeyCreate(options) {
|
|
673
675
|
return new Promise((resolve, reject) => {
|
|
674
676
|
const id = `pc-${++delegationCounter}-${Date.now()}`;
|
|
677
|
+
const timer = setTimeout(() => {
|
|
678
|
+
window.removeEventListener("message", handler);
|
|
679
|
+
reject(new Error("Passkey creation timed out. Please try again."));
|
|
680
|
+
}, DELEGATION_CREATE_TIMEOUT_MS);
|
|
675
681
|
const handler = (event) => {
|
|
676
682
|
const data = event.data;
|
|
677
683
|
if (!data || typeof data !== "object") return;
|
|
678
684
|
if (data.type !== "swype:passkey-create-response" || data.id !== id) return;
|
|
685
|
+
clearTimeout(timer);
|
|
679
686
|
window.removeEventListener("message", handler);
|
|
680
687
|
if (data.error) {
|
|
681
688
|
reject(new Error(data.error));
|
|
@@ -692,10 +699,15 @@ function delegatePasskeyCreate(options) {
|
|
|
692
699
|
function delegatePasskeyGet(options) {
|
|
693
700
|
return new Promise((resolve, reject) => {
|
|
694
701
|
const id = `pg-${++delegationCounter}-${Date.now()}`;
|
|
702
|
+
const timer = setTimeout(() => {
|
|
703
|
+
window.removeEventListener("message", handler);
|
|
704
|
+
reject(new Error("Passkey verification timed out. Please try again."));
|
|
705
|
+
}, DELEGATION_GET_TIMEOUT_MS);
|
|
695
706
|
const handler = (event) => {
|
|
696
707
|
const data = event.data;
|
|
697
708
|
if (!data || typeof data !== "object") return;
|
|
698
709
|
if (data.type !== "swype:passkey-get-response" || data.id !== id) return;
|
|
710
|
+
clearTimeout(timer);
|
|
699
711
|
window.removeEventListener("message", handler);
|
|
700
712
|
if (data.error) {
|
|
701
713
|
reject(new Error(data.error));
|
|
@@ -2647,7 +2659,6 @@ var hintStyle = (color) => ({
|
|
|
2647
2659
|
});
|
|
2648
2660
|
function CreatePasskeyScreen({
|
|
2649
2661
|
onCreatePasskey,
|
|
2650
|
-
onSkip,
|
|
2651
2662
|
onBack,
|
|
2652
2663
|
creating,
|
|
2653
2664
|
error
|
|
@@ -2658,7 +2669,6 @@ function CreatePasskeyScreen({
|
|
|
2658
2669
|
{
|
|
2659
2670
|
footer: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2660
2671
|
/* @__PURE__ */ jsxRuntime.jsx(PrimaryButton, { onClick: onCreatePasskey, disabled: creating, loading: creating, children: "Create passkey" }),
|
|
2661
|
-
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: onSkip, style: skipStyle(tokens.textMuted), disabled: creating, children: "Skip for now" }),
|
|
2662
2672
|
/* @__PURE__ */ jsxRuntime.jsx(PoweredByFooter, {})
|
|
2663
2673
|
] }),
|
|
2664
2674
|
children: [
|
|
@@ -2713,19 +2723,6 @@ var errorBannerStyle2 = (tokens) => ({
|
|
|
2713
2723
|
width: "100%",
|
|
2714
2724
|
textAlign: "left"
|
|
2715
2725
|
});
|
|
2716
|
-
var skipStyle = (color) => ({
|
|
2717
|
-
background: "transparent",
|
|
2718
|
-
border: "none",
|
|
2719
|
-
color,
|
|
2720
|
-
cursor: "pointer",
|
|
2721
|
-
fontFamily: "inherit",
|
|
2722
|
-
fontSize: "0.88rem",
|
|
2723
|
-
fontWeight: 500,
|
|
2724
|
-
display: "block",
|
|
2725
|
-
width: "100%",
|
|
2726
|
-
textAlign: "center",
|
|
2727
|
-
padding: "12px 0 0"
|
|
2728
|
-
});
|
|
2729
2726
|
var WALLET_EMOJIS = {
|
|
2730
2727
|
rabby: "\u{1F430}",
|
|
2731
2728
|
ora: "\u2666\uFE0F",
|
|
@@ -3944,6 +3941,74 @@ var hintStyle3 = (color) => ({
|
|
|
3944
3941
|
color,
|
|
3945
3942
|
margin: "8px 0 0"
|
|
3946
3943
|
});
|
|
3944
|
+
var PaymentErrorBoundary = class extends react.Component {
|
|
3945
|
+
constructor(props) {
|
|
3946
|
+
super(props);
|
|
3947
|
+
this.state = { hasError: false };
|
|
3948
|
+
}
|
|
3949
|
+
static getDerivedStateFromError() {
|
|
3950
|
+
return { hasError: true };
|
|
3951
|
+
}
|
|
3952
|
+
componentDidCatch(error, info) {
|
|
3953
|
+
console.error("[SwypePayment] Uncaught error:", error, info.componentStack);
|
|
3954
|
+
}
|
|
3955
|
+
handleReset = () => {
|
|
3956
|
+
this.setState({ hasError: false });
|
|
3957
|
+
this.props.onReset();
|
|
3958
|
+
};
|
|
3959
|
+
render() {
|
|
3960
|
+
if (!this.state.hasError) {
|
|
3961
|
+
return this.props.children;
|
|
3962
|
+
}
|
|
3963
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: containerStyle8, children: [
|
|
3964
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: iconStyle4, children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "48", height: "48", viewBox: "0 0 24 24", fill: "none", children: [
|
|
3965
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "10", stroke: "#ef4444", strokeWidth: "1.5" }),
|
|
3966
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 8v5", stroke: "#ef4444", strokeWidth: "1.5", strokeLinecap: "round" }),
|
|
3967
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "16", r: "0.75", fill: "#ef4444" })
|
|
3968
|
+
] }) }),
|
|
3969
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { style: headingStyle9, children: "Something went wrong" }),
|
|
3970
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: messageStyle, children: "An unexpected error occurred. Please try again." }),
|
|
3971
|
+
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: this.handleReset, style: buttonStyle3, children: "Try again" })
|
|
3972
|
+
] });
|
|
3973
|
+
}
|
|
3974
|
+
};
|
|
3975
|
+
var containerStyle8 = {
|
|
3976
|
+
display: "flex",
|
|
3977
|
+
flexDirection: "column",
|
|
3978
|
+
alignItems: "center",
|
|
3979
|
+
justifyContent: "center",
|
|
3980
|
+
textAlign: "center",
|
|
3981
|
+
padding: "48px 24px",
|
|
3982
|
+
minHeight: "100%",
|
|
3983
|
+
maxWidth: 420,
|
|
3984
|
+
margin: "0 auto"
|
|
3985
|
+
};
|
|
3986
|
+
var iconStyle4 = {
|
|
3987
|
+
marginBottom: 20
|
|
3988
|
+
};
|
|
3989
|
+
var headingStyle9 = {
|
|
3990
|
+
fontSize: "1.25rem",
|
|
3991
|
+
fontWeight: 700,
|
|
3992
|
+
color: "#1a1a1a",
|
|
3993
|
+
margin: "0 0 8px"
|
|
3994
|
+
};
|
|
3995
|
+
var messageStyle = {
|
|
3996
|
+
fontSize: "0.9rem",
|
|
3997
|
+
color: "#666",
|
|
3998
|
+
margin: "0 0 28px",
|
|
3999
|
+
lineHeight: 1.5
|
|
4000
|
+
};
|
|
4001
|
+
var buttonStyle3 = {
|
|
4002
|
+
background: "#1a1a1a",
|
|
4003
|
+
color: "#fff",
|
|
4004
|
+
border: "none",
|
|
4005
|
+
borderRadius: 12,
|
|
4006
|
+
padding: "12px 32px",
|
|
4007
|
+
fontSize: "0.95rem",
|
|
4008
|
+
fontWeight: 600,
|
|
4009
|
+
fontFamily: "inherit",
|
|
4010
|
+
cursor: "pointer"
|
|
4011
|
+
};
|
|
3947
4012
|
function isInIframe() {
|
|
3948
4013
|
try {
|
|
3949
4014
|
return typeof window !== "undefined" && window !== window.top;
|
|
@@ -4021,7 +4086,14 @@ function buildSelectSourceChoices(options) {
|
|
|
4021
4086
|
}
|
|
4022
4087
|
return chainChoices;
|
|
4023
4088
|
}
|
|
4024
|
-
function SwypePayment({
|
|
4089
|
+
function SwypePayment(props) {
|
|
4090
|
+
const resetKey = react.useRef(0);
|
|
4091
|
+
const handleBoundaryReset = react.useCallback(() => {
|
|
4092
|
+
resetKey.current += 1;
|
|
4093
|
+
}, []);
|
|
4094
|
+
return /* @__PURE__ */ jsxRuntime.jsx(PaymentErrorBoundary, { onReset: handleBoundaryReset, children: /* @__PURE__ */ jsxRuntime.jsx(SwypePaymentInner, { ...props }) }, resetKey.current);
|
|
4095
|
+
}
|
|
4096
|
+
function SwypePaymentInner({
|
|
4025
4097
|
destination,
|
|
4026
4098
|
onComplete,
|
|
4027
4099
|
onError,
|
|
@@ -4212,7 +4284,7 @@ function SwypePayment({
|
|
|
4212
4284
|
}
|
|
4213
4285
|
setStep("create-passkey");
|
|
4214
4286
|
} catch {
|
|
4215
|
-
if (!cancelled) setStep("
|
|
4287
|
+
if (!cancelled) setStep("create-passkey");
|
|
4216
4288
|
}
|
|
4217
4289
|
};
|
|
4218
4290
|
checkPasskey();
|
|
@@ -4592,16 +4664,6 @@ function SwypePayment({
|
|
|
4592
4664
|
setRegisteringPasskey(false);
|
|
4593
4665
|
}
|
|
4594
4666
|
}, [getAccessToken, user, apiBaseUrl, accounts]);
|
|
4595
|
-
const handleSkipPasskey = react.useCallback(() => {
|
|
4596
|
-
const hasActiveWallet = accounts.some(
|
|
4597
|
-
(a) => a.wallets.some((w) => w.status === "ACTIVE")
|
|
4598
|
-
);
|
|
4599
|
-
if (accounts.length === 0 || !hasActiveWallet) {
|
|
4600
|
-
setStep("wallet-picker");
|
|
4601
|
-
} else {
|
|
4602
|
-
setStep("deposit");
|
|
4603
|
-
}
|
|
4604
|
-
}, [accounts]);
|
|
4605
4667
|
const handleSelectProvider = react.useCallback((providerId) => {
|
|
4606
4668
|
setSelectedProviderId(providerId);
|
|
4607
4669
|
setSelectedAccountId(null);
|
|
@@ -4717,8 +4779,7 @@ function SwypePayment({
|
|
|
4717
4779
|
CreatePasskeyScreen,
|
|
4718
4780
|
{
|
|
4719
4781
|
onCreatePasskey: handleRegisterPasskey,
|
|
4720
|
-
|
|
4721
|
-
onBack: () => setStep("login"),
|
|
4782
|
+
onBack: handleLogout,
|
|
4722
4783
|
creating: registeringPasskey,
|
|
4723
4784
|
error
|
|
4724
4785
|
}
|
|
@@ -4733,7 +4794,7 @@ function SwypePayment({
|
|
|
4733
4794
|
loading: creatingTransfer,
|
|
4734
4795
|
onSelectProvider: handleSelectProvider,
|
|
4735
4796
|
onContinueConnection: handleContinueConnection,
|
|
4736
|
-
onBack: () => setStep("create-passkey")
|
|
4797
|
+
onBack: () => setStep(activeCredentialId ? "deposit" : "create-passkey")
|
|
4737
4798
|
}
|
|
4738
4799
|
);
|
|
4739
4800
|
}
|