@swype-org/react-sdk 0.1.46 → 0.1.48
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 +131 -5
- 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 +131 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -198,7 +198,7 @@ interface UserConfig {
|
|
|
198
198
|
/** Theme mode */
|
|
199
199
|
type ThemeMode = 'light' | 'dark';
|
|
200
200
|
/** Steps in the payment flow */
|
|
201
|
-
type PaymentStep = 'login' | 'otp-verify' | 'create-passkey' | 'wallet-picker' | 'deposit' | 'low-balance' | 'processing' | 'select-source' | 'success';
|
|
201
|
+
type PaymentStep = 'login' | 'otp-verify' | 'create-passkey' | 'wallet-picker' | 'open-wallet' | 'deposit' | 'low-balance' | 'processing' | 'select-source' | 'success';
|
|
202
202
|
/** User-selected advanced settings for chain/asset override */
|
|
203
203
|
interface AdvancedSettings {
|
|
204
204
|
/** Override asset (e.g. 'USDC', 'USDT'). Null = let backend decide. */
|
package/dist/index.d.ts
CHANGED
|
@@ -198,7 +198,7 @@ interface UserConfig {
|
|
|
198
198
|
/** Theme mode */
|
|
199
199
|
type ThemeMode = 'light' | 'dark';
|
|
200
200
|
/** Steps in the payment flow */
|
|
201
|
-
type PaymentStep = 'login' | 'otp-verify' | 'create-passkey' | 'wallet-picker' | 'deposit' | 'low-balance' | 'processing' | 'select-source' | 'success';
|
|
201
|
+
type PaymentStep = 'login' | 'otp-verify' | 'create-passkey' | 'wallet-picker' | 'open-wallet' | 'deposit' | 'low-balance' | 'processing' | 'select-source' | 'success';
|
|
202
202
|
/** User-selected advanced settings for chain/asset override */
|
|
203
203
|
interface AdvancedSettings {
|
|
204
204
|
/** Override asset (e.g. 'USDC', 'USDT'). Null = let backend decide. */
|
package/dist/index.js
CHANGED
|
@@ -2735,6 +2735,7 @@ function truncateAddress(address) {
|
|
|
2735
2735
|
function WalletPickerScreen({
|
|
2736
2736
|
providers,
|
|
2737
2737
|
pendingConnections,
|
|
2738
|
+
loading,
|
|
2738
2739
|
onSelectProvider,
|
|
2739
2740
|
onContinueConnection,
|
|
2740
2741
|
onBack
|
|
@@ -2748,6 +2749,12 @@ function WalletPickerScreen({
|
|
|
2748
2749
|
{ id: "ora", name: "Ora" },
|
|
2749
2750
|
{ id: "phantom", name: "Phantom" }
|
|
2750
2751
|
];
|
|
2752
|
+
if (loading) {
|
|
2753
|
+
return /* @__PURE__ */ jsxs(ScreenLayout, { children: [
|
|
2754
|
+
/* @__PURE__ */ jsx(ScreenHeader, { title: "Set up Swype", onBack }),
|
|
2755
|
+
/* @__PURE__ */ jsx("div", { style: { textAlign: "center", padding: "48px 0", flex: 1, display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ jsx(Spinner, { label: "Connecting..." }) })
|
|
2756
|
+
] });
|
|
2757
|
+
}
|
|
2751
2758
|
return /* @__PURE__ */ jsxs(
|
|
2752
2759
|
ScreenLayout,
|
|
2753
2760
|
{
|
|
@@ -3848,6 +3855,99 @@ var waitHintStyle = (color) => ({
|
|
|
3848
3855
|
color,
|
|
3849
3856
|
margin: 0
|
|
3850
3857
|
});
|
|
3858
|
+
function OpenWalletScreen({
|
|
3859
|
+
walletName,
|
|
3860
|
+
deeplinkUri,
|
|
3861
|
+
loading,
|
|
3862
|
+
onLogout
|
|
3863
|
+
}) {
|
|
3864
|
+
const { tokens } = useSwypeConfig();
|
|
3865
|
+
const displayName = walletName ?? "your wallet";
|
|
3866
|
+
const logoSrc = walletName ? KNOWN_LOGOS[walletName.toLowerCase()] : void 0;
|
|
3867
|
+
const handleOpen = useCallback(() => {
|
|
3868
|
+
const opened = window.open(deeplinkUri, "_blank");
|
|
3869
|
+
if (!opened) {
|
|
3870
|
+
window.location.href = deeplinkUri;
|
|
3871
|
+
}
|
|
3872
|
+
}, [deeplinkUri]);
|
|
3873
|
+
return /* @__PURE__ */ jsxs(
|
|
3874
|
+
ScreenLayout,
|
|
3875
|
+
{
|
|
3876
|
+
footer: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3877
|
+
!loading && /* @__PURE__ */ jsxs(PrimaryButton, { onClick: handleOpen, children: [
|
|
3878
|
+
"Open ",
|
|
3879
|
+
displayName
|
|
3880
|
+
] }),
|
|
3881
|
+
/* @__PURE__ */ jsx("p", { style: hintStyle3(tokens.textMuted), children: loading ? "Preparing authorization..." : "Tap the button to authorize in your wallet app" })
|
|
3882
|
+
] }),
|
|
3883
|
+
children: [
|
|
3884
|
+
/* @__PURE__ */ jsx(ScreenHeader, { right: /* @__PURE__ */ jsx(SettingsMenu, { onLogout }) }),
|
|
3885
|
+
/* @__PURE__ */ jsxs("div", { style: contentStyle6, children: [
|
|
3886
|
+
logoSrc ? /* @__PURE__ */ jsx("img", { src: logoSrc, alt: displayName, style: logoStyle }) : /* @__PURE__ */ jsx(Spinner, { size: 48 }),
|
|
3887
|
+
/* @__PURE__ */ jsx("h2", { style: headingStyle8(tokens.text), children: loading ? "Connecting..." : `Open ${displayName}` }),
|
|
3888
|
+
/* @__PURE__ */ jsx("p", { style: subtitleStyle8(tokens.textSecondary), children: loading ? "Creating transfer and preparing your wallet link..." : `Continue in ${displayName} to authorize this connection.` }),
|
|
3889
|
+
!loading && /* @__PURE__ */ jsxs("div", { style: waitingBadgeStyle(tokens), children: [
|
|
3890
|
+
/* @__PURE__ */ jsx(Spinner, { size: 14 }),
|
|
3891
|
+
/* @__PURE__ */ jsx("span", { children: "Waiting for authorization..." })
|
|
3892
|
+
] })
|
|
3893
|
+
] })
|
|
3894
|
+
]
|
|
3895
|
+
}
|
|
3896
|
+
);
|
|
3897
|
+
}
|
|
3898
|
+
var contentStyle6 = {
|
|
3899
|
+
flex: 1,
|
|
3900
|
+
display: "flex",
|
|
3901
|
+
flexDirection: "column",
|
|
3902
|
+
alignItems: "center",
|
|
3903
|
+
justifyContent: "center",
|
|
3904
|
+
textAlign: "center",
|
|
3905
|
+
padding: "0 24px"
|
|
3906
|
+
};
|
|
3907
|
+
var logoStyle = {
|
|
3908
|
+
width: 56,
|
|
3909
|
+
height: 56,
|
|
3910
|
+
borderRadius: 14,
|
|
3911
|
+
objectFit: "contain"
|
|
3912
|
+
};
|
|
3913
|
+
var headingStyle8 = (color) => ({
|
|
3914
|
+
fontSize: "1.45rem",
|
|
3915
|
+
fontWeight: 700,
|
|
3916
|
+
letterSpacing: "-0.02em",
|
|
3917
|
+
color,
|
|
3918
|
+
margin: "20px 0 8px"
|
|
3919
|
+
});
|
|
3920
|
+
var subtitleStyle8 = (color) => ({
|
|
3921
|
+
fontSize: "0.9rem",
|
|
3922
|
+
color,
|
|
3923
|
+
margin: "0 0 24px",
|
|
3924
|
+
lineHeight: 1.5,
|
|
3925
|
+
maxWidth: 280
|
|
3926
|
+
});
|
|
3927
|
+
var waitingBadgeStyle = (tokens) => ({
|
|
3928
|
+
display: "inline-flex",
|
|
3929
|
+
alignItems: "center",
|
|
3930
|
+
gap: 8,
|
|
3931
|
+
padding: "8px 16px",
|
|
3932
|
+
borderRadius: 20,
|
|
3933
|
+
background: tokens.bgInput,
|
|
3934
|
+
border: `1px solid ${tokens.border}`,
|
|
3935
|
+
color: tokens.textMuted,
|
|
3936
|
+
fontSize: "0.82rem"
|
|
3937
|
+
});
|
|
3938
|
+
var hintStyle3 = (color) => ({
|
|
3939
|
+
textAlign: "center",
|
|
3940
|
+
fontSize: "0.82rem",
|
|
3941
|
+
color,
|
|
3942
|
+
margin: "8px 0 0"
|
|
3943
|
+
});
|
|
3944
|
+
function isInIframe() {
|
|
3945
|
+
try {
|
|
3946
|
+
return typeof window !== "undefined" && window !== window.top;
|
|
3947
|
+
} catch {
|
|
3948
|
+
return true;
|
|
3949
|
+
}
|
|
3950
|
+
}
|
|
3851
3951
|
var ACTIVE_CREDENTIAL_STORAGE_KEY = "swype_active_credential_id";
|
|
3852
3952
|
var MIN_SEND_AMOUNT_USD = 0.25;
|
|
3853
3953
|
function computeSmartDefaults(accts, transferAmount) {
|
|
@@ -3968,6 +4068,7 @@ function SwypePayment({
|
|
|
3968
4068
|
const [otpCode, setOtpCode] = useState("");
|
|
3969
4069
|
const [oneTapLimit, setOneTapLimit] = useState(100);
|
|
3970
4070
|
const [mobileFlow, setMobileFlow] = useState(false);
|
|
4071
|
+
const [deeplinkUri, setDeeplinkUri] = useState(null);
|
|
3971
4072
|
const pollingTransferIdRef = useRef(null);
|
|
3972
4073
|
const mobileSigningTransferIdRef = useRef(null);
|
|
3973
4074
|
const mobileSetupFlowRef = useRef(false);
|
|
@@ -4215,6 +4316,7 @@ function SwypePayment({
|
|
|
4215
4316
|
if (mobileSetupFlowRef.current) {
|
|
4216
4317
|
mobileSetupFlowRef.current = false;
|
|
4217
4318
|
setMobileFlow(false);
|
|
4319
|
+
setDeeplinkUri(null);
|
|
4218
4320
|
polling.stopPolling();
|
|
4219
4321
|
setTransfer(polledTransfer);
|
|
4220
4322
|
reloadAccounts().catch(() => {
|
|
@@ -4354,10 +4456,16 @@ function SwypePayment({
|
|
|
4354
4456
|
setStep("create-passkey");
|
|
4355
4457
|
return;
|
|
4356
4458
|
}
|
|
4357
|
-
|
|
4459
|
+
const isSetupRedirect = mobileSetupFlowRef.current;
|
|
4460
|
+
if (isSetupRedirect) {
|
|
4461
|
+
setStep("open-wallet");
|
|
4462
|
+
} else {
|
|
4463
|
+
setStep("processing");
|
|
4464
|
+
}
|
|
4358
4465
|
processingStartedAtRef.current = Date.now();
|
|
4359
4466
|
setError(null);
|
|
4360
4467
|
setCreatingTransfer(true);
|
|
4468
|
+
setDeeplinkUri(null);
|
|
4361
4469
|
setMobileFlow(false);
|
|
4362
4470
|
try {
|
|
4363
4471
|
if (transfer?.status === "AUTHORIZED") {
|
|
@@ -4381,7 +4489,7 @@ function SwypePayment({
|
|
|
4381
4489
|
const isActiveWallet = effectiveSourceType === "walletId" && accounts.some(
|
|
4382
4490
|
(a) => a.wallets.some((w) => w.id === effectiveSourceId && w.status === "ACTIVE")
|
|
4383
4491
|
);
|
|
4384
|
-
if (!isActiveWallet) {
|
|
4492
|
+
if (!isActiveWallet && !isSetupRedirect) {
|
|
4385
4493
|
let found = false;
|
|
4386
4494
|
for (const acct of accounts) {
|
|
4387
4495
|
for (const wallet of acct.wallets) {
|
|
@@ -4411,11 +4519,14 @@ function SwypePayment({
|
|
|
4411
4519
|
userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
|
|
4412
4520
|
});
|
|
4413
4521
|
if (!shouldUseConnector) {
|
|
4522
|
+
const uri = t.authorizationSessions[0].uri;
|
|
4414
4523
|
setMobileFlow(true);
|
|
4415
4524
|
pollingTransferIdRef.current = t.id;
|
|
4416
4525
|
polling.startPolling(t.id);
|
|
4417
|
-
|
|
4418
|
-
|
|
4526
|
+
setDeeplinkUri(uri);
|
|
4527
|
+
setStep("open-wallet");
|
|
4528
|
+
if (!isInIframe()) {
|
|
4529
|
+
window.location.href = uri;
|
|
4419
4530
|
}
|
|
4420
4531
|
return;
|
|
4421
4532
|
} else {
|
|
@@ -4429,7 +4540,7 @@ function SwypePayment({
|
|
|
4429
4540
|
const msg = err instanceof Error ? err.message : "Transfer failed";
|
|
4430
4541
|
setError(msg);
|
|
4431
4542
|
onError?.(msg);
|
|
4432
|
-
setStep("deposit");
|
|
4543
|
+
setStep(isSetupRedirect ? "wallet-picker" : "deposit");
|
|
4433
4544
|
} finally {
|
|
4434
4545
|
setCreatingTransfer(false);
|
|
4435
4546
|
}
|
|
@@ -4520,6 +4631,7 @@ function SwypePayment({
|
|
|
4520
4631
|
setError(null);
|
|
4521
4632
|
setAmount(depositAmount != null ? depositAmount.toString() : "");
|
|
4522
4633
|
setMobileFlow(false);
|
|
4634
|
+
setDeeplinkUri(null);
|
|
4523
4635
|
processingStartedAtRef.current = null;
|
|
4524
4636
|
pollingTransferIdRef.current = null;
|
|
4525
4637
|
mobileSigningTransferIdRef.current = null;
|
|
@@ -4551,6 +4663,7 @@ function SwypePayment({
|
|
|
4551
4663
|
setConnectingNewAccount(false);
|
|
4552
4664
|
setAmount(depositAmount != null ? depositAmount.toString() : "");
|
|
4553
4665
|
setMobileFlow(false);
|
|
4666
|
+
setDeeplinkUri(null);
|
|
4554
4667
|
resetHeadlessLogin();
|
|
4555
4668
|
}, [logout, polling, depositAmount, resetHeadlessLogin]);
|
|
4556
4669
|
if (!ready) {
|
|
@@ -4614,12 +4727,25 @@ function SwypePayment({
|
|
|
4614
4727
|
{
|
|
4615
4728
|
providers,
|
|
4616
4729
|
pendingConnections,
|
|
4730
|
+
loading: creatingTransfer,
|
|
4617
4731
|
onSelectProvider: handleSelectProvider,
|
|
4618
4732
|
onContinueConnection: handleContinueConnection,
|
|
4619
4733
|
onBack: () => setStep("create-passkey")
|
|
4620
4734
|
}
|
|
4621
4735
|
);
|
|
4622
4736
|
}
|
|
4737
|
+
if (step === "open-wallet") {
|
|
4738
|
+
const providerName = providers.find((p) => p.id === selectedProviderId)?.name ?? null;
|
|
4739
|
+
return /* @__PURE__ */ jsx(
|
|
4740
|
+
OpenWalletScreen,
|
|
4741
|
+
{
|
|
4742
|
+
walletName: providerName,
|
|
4743
|
+
deeplinkUri: deeplinkUri ?? "",
|
|
4744
|
+
loading: creatingTransfer || !deeplinkUri,
|
|
4745
|
+
onLogout: handleLogout
|
|
4746
|
+
}
|
|
4747
|
+
);
|
|
4748
|
+
}
|
|
4623
4749
|
if (step === "deposit") {
|
|
4624
4750
|
if (loadingData) {
|
|
4625
4751
|
return /* @__PURE__ */ jsx(ScreenLayout, { children: /* @__PURE__ */ jsx("div", { style: { textAlign: "center", padding: "48px 0", flex: 1, display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ jsx(Spinner, { label: "Loading..." }) }) });
|