@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.d.cts
CHANGED
|
@@ -377,7 +377,7 @@ interface SwypePaymentProps {
|
|
|
377
377
|
/** Seconds to count down on the success screen before auto-dismissing. */
|
|
378
378
|
autoCloseSeconds?: number;
|
|
379
379
|
}
|
|
380
|
-
declare function SwypePayment(
|
|
380
|
+
declare function SwypePayment(props: SwypePaymentProps): react_jsx_runtime.JSX.Element;
|
|
381
381
|
|
|
382
382
|
type AccessTokenGetter = () => Promise<string | null | undefined>;
|
|
383
383
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -377,7 +377,7 @@ interface SwypePaymentProps {
|
|
|
377
377
|
/** Seconds to count down on the success screen before auto-dismissing. */
|
|
378
378
|
autoCloseSeconds?: number;
|
|
379
379
|
}
|
|
380
|
-
declare function SwypePayment(
|
|
380
|
+
declare function SwypePayment(props: SwypePaymentProps): react_jsx_runtime.JSX.Element;
|
|
381
381
|
|
|
382
382
|
type AccessTokenGetter = () => Promise<string | null | undefined>;
|
|
383
383
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, useRef, useState, useCallback, useMemo, useContext, useEffect } from 'react';
|
|
1
|
+
import { createContext, useRef, useState, useCallback, useMemo, useContext, useEffect, Component } from 'react';
|
|
2
2
|
import { PrivyProvider, usePrivy, useLoginWithEmail, useLoginWithSms, useLoginWithOAuth } from '@privy-io/react-auth';
|
|
3
3
|
import { createConfig, http, WagmiProvider, useConfig, useConnect, useSwitchChain } from 'wagmi';
|
|
4
4
|
import { mainnet, arbitrum, base } from 'wagmi/chains';
|
|
@@ -666,13 +666,20 @@ function isInCrossOriginIframe() {
|
|
|
666
666
|
}
|
|
667
667
|
}
|
|
668
668
|
var delegationCounter = 0;
|
|
669
|
+
var DELEGATION_CREATE_TIMEOUT_MS = 6e4;
|
|
670
|
+
var DELEGATION_GET_TIMEOUT_MS = 3e4;
|
|
669
671
|
function delegatePasskeyCreate(options) {
|
|
670
672
|
return new Promise((resolve, reject) => {
|
|
671
673
|
const id = `pc-${++delegationCounter}-${Date.now()}`;
|
|
674
|
+
const timer = setTimeout(() => {
|
|
675
|
+
window.removeEventListener("message", handler);
|
|
676
|
+
reject(new Error("Passkey creation timed out. Please try again."));
|
|
677
|
+
}, DELEGATION_CREATE_TIMEOUT_MS);
|
|
672
678
|
const handler = (event) => {
|
|
673
679
|
const data = event.data;
|
|
674
680
|
if (!data || typeof data !== "object") return;
|
|
675
681
|
if (data.type !== "swype:passkey-create-response" || data.id !== id) return;
|
|
682
|
+
clearTimeout(timer);
|
|
676
683
|
window.removeEventListener("message", handler);
|
|
677
684
|
if (data.error) {
|
|
678
685
|
reject(new Error(data.error));
|
|
@@ -689,10 +696,15 @@ function delegatePasskeyCreate(options) {
|
|
|
689
696
|
function delegatePasskeyGet(options) {
|
|
690
697
|
return new Promise((resolve, reject) => {
|
|
691
698
|
const id = `pg-${++delegationCounter}-${Date.now()}`;
|
|
699
|
+
const timer = setTimeout(() => {
|
|
700
|
+
window.removeEventListener("message", handler);
|
|
701
|
+
reject(new Error("Passkey verification timed out. Please try again."));
|
|
702
|
+
}, DELEGATION_GET_TIMEOUT_MS);
|
|
692
703
|
const handler = (event) => {
|
|
693
704
|
const data = event.data;
|
|
694
705
|
if (!data || typeof data !== "object") return;
|
|
695
706
|
if (data.type !== "swype:passkey-get-response" || data.id !== id) return;
|
|
707
|
+
clearTimeout(timer);
|
|
696
708
|
window.removeEventListener("message", handler);
|
|
697
709
|
if (data.error) {
|
|
698
710
|
reject(new Error(data.error));
|
|
@@ -2644,7 +2656,6 @@ var hintStyle = (color) => ({
|
|
|
2644
2656
|
});
|
|
2645
2657
|
function CreatePasskeyScreen({
|
|
2646
2658
|
onCreatePasskey,
|
|
2647
|
-
onSkip,
|
|
2648
2659
|
onBack,
|
|
2649
2660
|
creating,
|
|
2650
2661
|
error
|
|
@@ -2655,7 +2666,6 @@ function CreatePasskeyScreen({
|
|
|
2655
2666
|
{
|
|
2656
2667
|
footer: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2657
2668
|
/* @__PURE__ */ jsx(PrimaryButton, { onClick: onCreatePasskey, disabled: creating, loading: creating, children: "Create passkey" }),
|
|
2658
|
-
/* @__PURE__ */ jsx("button", { type: "button", onClick: onSkip, style: skipStyle(tokens.textMuted), disabled: creating, children: "Skip for now" }),
|
|
2659
2669
|
/* @__PURE__ */ jsx(PoweredByFooter, {})
|
|
2660
2670
|
] }),
|
|
2661
2671
|
children: [
|
|
@@ -2710,19 +2720,6 @@ var errorBannerStyle2 = (tokens) => ({
|
|
|
2710
2720
|
width: "100%",
|
|
2711
2721
|
textAlign: "left"
|
|
2712
2722
|
});
|
|
2713
|
-
var skipStyle = (color) => ({
|
|
2714
|
-
background: "transparent",
|
|
2715
|
-
border: "none",
|
|
2716
|
-
color,
|
|
2717
|
-
cursor: "pointer",
|
|
2718
|
-
fontFamily: "inherit",
|
|
2719
|
-
fontSize: "0.88rem",
|
|
2720
|
-
fontWeight: 500,
|
|
2721
|
-
display: "block",
|
|
2722
|
-
width: "100%",
|
|
2723
|
-
textAlign: "center",
|
|
2724
|
-
padding: "12px 0 0"
|
|
2725
|
-
});
|
|
2726
2723
|
var WALLET_EMOJIS = {
|
|
2727
2724
|
rabby: "\u{1F430}",
|
|
2728
2725
|
ora: "\u2666\uFE0F",
|
|
@@ -3941,6 +3938,74 @@ var hintStyle3 = (color) => ({
|
|
|
3941
3938
|
color,
|
|
3942
3939
|
margin: "8px 0 0"
|
|
3943
3940
|
});
|
|
3941
|
+
var PaymentErrorBoundary = class extends Component {
|
|
3942
|
+
constructor(props) {
|
|
3943
|
+
super(props);
|
|
3944
|
+
this.state = { hasError: false };
|
|
3945
|
+
}
|
|
3946
|
+
static getDerivedStateFromError() {
|
|
3947
|
+
return { hasError: true };
|
|
3948
|
+
}
|
|
3949
|
+
componentDidCatch(error, info) {
|
|
3950
|
+
console.error("[SwypePayment] Uncaught error:", error, info.componentStack);
|
|
3951
|
+
}
|
|
3952
|
+
handleReset = () => {
|
|
3953
|
+
this.setState({ hasError: false });
|
|
3954
|
+
this.props.onReset();
|
|
3955
|
+
};
|
|
3956
|
+
render() {
|
|
3957
|
+
if (!this.state.hasError) {
|
|
3958
|
+
return this.props.children;
|
|
3959
|
+
}
|
|
3960
|
+
return /* @__PURE__ */ jsxs("div", { style: containerStyle8, children: [
|
|
3961
|
+
/* @__PURE__ */ jsx("div", { style: iconStyle4, children: /* @__PURE__ */ jsxs("svg", { width: "48", height: "48", viewBox: "0 0 24 24", fill: "none", children: [
|
|
3962
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "10", stroke: "#ef4444", strokeWidth: "1.5" }),
|
|
3963
|
+
/* @__PURE__ */ jsx("path", { d: "M12 8v5", stroke: "#ef4444", strokeWidth: "1.5", strokeLinecap: "round" }),
|
|
3964
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "16", r: "0.75", fill: "#ef4444" })
|
|
3965
|
+
] }) }),
|
|
3966
|
+
/* @__PURE__ */ jsx("h2", { style: headingStyle9, children: "Something went wrong" }),
|
|
3967
|
+
/* @__PURE__ */ jsx("p", { style: messageStyle, children: "An unexpected error occurred. Please try again." }),
|
|
3968
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: this.handleReset, style: buttonStyle3, children: "Try again" })
|
|
3969
|
+
] });
|
|
3970
|
+
}
|
|
3971
|
+
};
|
|
3972
|
+
var containerStyle8 = {
|
|
3973
|
+
display: "flex",
|
|
3974
|
+
flexDirection: "column",
|
|
3975
|
+
alignItems: "center",
|
|
3976
|
+
justifyContent: "center",
|
|
3977
|
+
textAlign: "center",
|
|
3978
|
+
padding: "48px 24px",
|
|
3979
|
+
minHeight: "100%",
|
|
3980
|
+
maxWidth: 420,
|
|
3981
|
+
margin: "0 auto"
|
|
3982
|
+
};
|
|
3983
|
+
var iconStyle4 = {
|
|
3984
|
+
marginBottom: 20
|
|
3985
|
+
};
|
|
3986
|
+
var headingStyle9 = {
|
|
3987
|
+
fontSize: "1.25rem",
|
|
3988
|
+
fontWeight: 700,
|
|
3989
|
+
color: "#1a1a1a",
|
|
3990
|
+
margin: "0 0 8px"
|
|
3991
|
+
};
|
|
3992
|
+
var messageStyle = {
|
|
3993
|
+
fontSize: "0.9rem",
|
|
3994
|
+
color: "#666",
|
|
3995
|
+
margin: "0 0 28px",
|
|
3996
|
+
lineHeight: 1.5
|
|
3997
|
+
};
|
|
3998
|
+
var buttonStyle3 = {
|
|
3999
|
+
background: "#1a1a1a",
|
|
4000
|
+
color: "#fff",
|
|
4001
|
+
border: "none",
|
|
4002
|
+
borderRadius: 12,
|
|
4003
|
+
padding: "12px 32px",
|
|
4004
|
+
fontSize: "0.95rem",
|
|
4005
|
+
fontWeight: 600,
|
|
4006
|
+
fontFamily: "inherit",
|
|
4007
|
+
cursor: "pointer"
|
|
4008
|
+
};
|
|
3944
4009
|
function isInIframe() {
|
|
3945
4010
|
try {
|
|
3946
4011
|
return typeof window !== "undefined" && window !== window.top;
|
|
@@ -4018,7 +4083,14 @@ function buildSelectSourceChoices(options) {
|
|
|
4018
4083
|
}
|
|
4019
4084
|
return chainChoices;
|
|
4020
4085
|
}
|
|
4021
|
-
function SwypePayment({
|
|
4086
|
+
function SwypePayment(props) {
|
|
4087
|
+
const resetKey = useRef(0);
|
|
4088
|
+
const handleBoundaryReset = useCallback(() => {
|
|
4089
|
+
resetKey.current += 1;
|
|
4090
|
+
}, []);
|
|
4091
|
+
return /* @__PURE__ */ jsx(PaymentErrorBoundary, { onReset: handleBoundaryReset, children: /* @__PURE__ */ jsx(SwypePaymentInner, { ...props }) }, resetKey.current);
|
|
4092
|
+
}
|
|
4093
|
+
function SwypePaymentInner({
|
|
4022
4094
|
destination,
|
|
4023
4095
|
onComplete,
|
|
4024
4096
|
onError,
|
|
@@ -4209,7 +4281,7 @@ function SwypePayment({
|
|
|
4209
4281
|
}
|
|
4210
4282
|
setStep("create-passkey");
|
|
4211
4283
|
} catch {
|
|
4212
|
-
if (!cancelled) setStep("
|
|
4284
|
+
if (!cancelled) setStep("create-passkey");
|
|
4213
4285
|
}
|
|
4214
4286
|
};
|
|
4215
4287
|
checkPasskey();
|
|
@@ -4589,16 +4661,6 @@ function SwypePayment({
|
|
|
4589
4661
|
setRegisteringPasskey(false);
|
|
4590
4662
|
}
|
|
4591
4663
|
}, [getAccessToken, user, apiBaseUrl, accounts]);
|
|
4592
|
-
const handleSkipPasskey = useCallback(() => {
|
|
4593
|
-
const hasActiveWallet = accounts.some(
|
|
4594
|
-
(a) => a.wallets.some((w) => w.status === "ACTIVE")
|
|
4595
|
-
);
|
|
4596
|
-
if (accounts.length === 0 || !hasActiveWallet) {
|
|
4597
|
-
setStep("wallet-picker");
|
|
4598
|
-
} else {
|
|
4599
|
-
setStep("deposit");
|
|
4600
|
-
}
|
|
4601
|
-
}, [accounts]);
|
|
4602
4664
|
const handleSelectProvider = useCallback((providerId) => {
|
|
4603
4665
|
setSelectedProviderId(providerId);
|
|
4604
4666
|
setSelectedAccountId(null);
|
|
@@ -4714,8 +4776,7 @@ function SwypePayment({
|
|
|
4714
4776
|
CreatePasskeyScreen,
|
|
4715
4777
|
{
|
|
4716
4778
|
onCreatePasskey: handleRegisterPasskey,
|
|
4717
|
-
|
|
4718
|
-
onBack: () => setStep("login"),
|
|
4779
|
+
onBack: handleLogout,
|
|
4719
4780
|
creating: registeringPasskey,
|
|
4720
4781
|
error
|
|
4721
4782
|
}
|
|
@@ -4730,7 +4791,7 @@ function SwypePayment({
|
|
|
4730
4791
|
loading: creatingTransfer,
|
|
4731
4792
|
onSelectProvider: handleSelectProvider,
|
|
4732
4793
|
onContinueConnection: handleContinueConnection,
|
|
4733
|
-
onBack: () => setStep("create-passkey")
|
|
4794
|
+
onBack: () => setStep(activeCredentialId ? "deposit" : "create-passkey")
|
|
4734
4795
|
}
|
|
4735
4796
|
);
|
|
4736
4797
|
}
|