@swype-org/react-sdk 0.1.47 → 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 +128 -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 +128 -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(() => {
|
|
@@ -4355,12 +4457,15 @@ function SwypePayment({
|
|
|
4355
4457
|
return;
|
|
4356
4458
|
}
|
|
4357
4459
|
const isSetupRedirect = mobileSetupFlowRef.current;
|
|
4358
|
-
if (
|
|
4460
|
+
if (isSetupRedirect) {
|
|
4461
|
+
setStep("open-wallet");
|
|
4462
|
+
} else {
|
|
4359
4463
|
setStep("processing");
|
|
4360
4464
|
}
|
|
4361
4465
|
processingStartedAtRef.current = Date.now();
|
|
4362
4466
|
setError(null);
|
|
4363
4467
|
setCreatingTransfer(true);
|
|
4468
|
+
setDeeplinkUri(null);
|
|
4364
4469
|
setMobileFlow(false);
|
|
4365
4470
|
try {
|
|
4366
4471
|
if (transfer?.status === "AUTHORIZED") {
|
|
@@ -4384,7 +4489,7 @@ function SwypePayment({
|
|
|
4384
4489
|
const isActiveWallet = effectiveSourceType === "walletId" && accounts.some(
|
|
4385
4490
|
(a) => a.wallets.some((w) => w.id === effectiveSourceId && w.status === "ACTIVE")
|
|
4386
4491
|
);
|
|
4387
|
-
if (!isActiveWallet) {
|
|
4492
|
+
if (!isActiveWallet && !isSetupRedirect) {
|
|
4388
4493
|
let found = false;
|
|
4389
4494
|
for (const acct of accounts) {
|
|
4390
4495
|
for (const wallet of acct.wallets) {
|
|
@@ -4414,11 +4519,14 @@ function SwypePayment({
|
|
|
4414
4519
|
userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
|
|
4415
4520
|
});
|
|
4416
4521
|
if (!shouldUseConnector) {
|
|
4522
|
+
const uri = t.authorizationSessions[0].uri;
|
|
4417
4523
|
setMobileFlow(true);
|
|
4418
4524
|
pollingTransferIdRef.current = t.id;
|
|
4419
4525
|
polling.startPolling(t.id);
|
|
4420
|
-
|
|
4421
|
-
|
|
4526
|
+
setDeeplinkUri(uri);
|
|
4527
|
+
setStep("open-wallet");
|
|
4528
|
+
if (!isInIframe()) {
|
|
4529
|
+
window.location.href = uri;
|
|
4422
4530
|
}
|
|
4423
4531
|
return;
|
|
4424
4532
|
} else {
|
|
@@ -4432,7 +4540,7 @@ function SwypePayment({
|
|
|
4432
4540
|
const msg = err instanceof Error ? err.message : "Transfer failed";
|
|
4433
4541
|
setError(msg);
|
|
4434
4542
|
onError?.(msg);
|
|
4435
|
-
setStep("deposit");
|
|
4543
|
+
setStep(isSetupRedirect ? "wallet-picker" : "deposit");
|
|
4436
4544
|
} finally {
|
|
4437
4545
|
setCreatingTransfer(false);
|
|
4438
4546
|
}
|
|
@@ -4523,6 +4631,7 @@ function SwypePayment({
|
|
|
4523
4631
|
setError(null);
|
|
4524
4632
|
setAmount(depositAmount != null ? depositAmount.toString() : "");
|
|
4525
4633
|
setMobileFlow(false);
|
|
4634
|
+
setDeeplinkUri(null);
|
|
4526
4635
|
processingStartedAtRef.current = null;
|
|
4527
4636
|
pollingTransferIdRef.current = null;
|
|
4528
4637
|
mobileSigningTransferIdRef.current = null;
|
|
@@ -4554,6 +4663,7 @@ function SwypePayment({
|
|
|
4554
4663
|
setConnectingNewAccount(false);
|
|
4555
4664
|
setAmount(depositAmount != null ? depositAmount.toString() : "");
|
|
4556
4665
|
setMobileFlow(false);
|
|
4666
|
+
setDeeplinkUri(null);
|
|
4557
4667
|
resetHeadlessLogin();
|
|
4558
4668
|
}, [logout, polling, depositAmount, resetHeadlessLogin]);
|
|
4559
4669
|
if (!ready) {
|
|
@@ -4617,12 +4727,25 @@ function SwypePayment({
|
|
|
4617
4727
|
{
|
|
4618
4728
|
providers,
|
|
4619
4729
|
pendingConnections,
|
|
4730
|
+
loading: creatingTransfer,
|
|
4620
4731
|
onSelectProvider: handleSelectProvider,
|
|
4621
4732
|
onContinueConnection: handleContinueConnection,
|
|
4622
4733
|
onBack: () => setStep("create-passkey")
|
|
4623
4734
|
}
|
|
4624
4735
|
);
|
|
4625
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
|
+
}
|
|
4626
4749
|
if (step === "deposit") {
|
|
4627
4750
|
if (loadingData) {
|
|
4628
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..." }) }) });
|