@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 CHANGED
@@ -2738,6 +2738,7 @@ function truncateAddress(address) {
2738
2738
  function WalletPickerScreen({
2739
2739
  providers,
2740
2740
  pendingConnections,
2741
+ loading,
2741
2742
  onSelectProvider,
2742
2743
  onContinueConnection,
2743
2744
  onBack
@@ -2751,6 +2752,12 @@ function WalletPickerScreen({
2751
2752
  { id: "ora", name: "Ora" },
2752
2753
  { id: "phantom", name: "Phantom" }
2753
2754
  ];
2755
+ if (loading) {
2756
+ return /* @__PURE__ */ jsxRuntime.jsxs(ScreenLayout, { children: [
2757
+ /* @__PURE__ */ jsxRuntime.jsx(ScreenHeader, { title: "Set up Swype", onBack }),
2758
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center", padding: "48px 0", flex: 1, display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ jsxRuntime.jsx(Spinner, { label: "Connecting..." }) })
2759
+ ] });
2760
+ }
2754
2761
  return /* @__PURE__ */ jsxRuntime.jsxs(
2755
2762
  ScreenLayout,
2756
2763
  {
@@ -3851,6 +3858,99 @@ var waitHintStyle = (color) => ({
3851
3858
  color,
3852
3859
  margin: 0
3853
3860
  });
3861
+ function OpenWalletScreen({
3862
+ walletName,
3863
+ deeplinkUri,
3864
+ loading,
3865
+ onLogout
3866
+ }) {
3867
+ const { tokens } = useSwypeConfig();
3868
+ const displayName = walletName ?? "your wallet";
3869
+ const logoSrc = walletName ? KNOWN_LOGOS[walletName.toLowerCase()] : void 0;
3870
+ const handleOpen = react.useCallback(() => {
3871
+ const opened = window.open(deeplinkUri, "_blank");
3872
+ if (!opened) {
3873
+ window.location.href = deeplinkUri;
3874
+ }
3875
+ }, [deeplinkUri]);
3876
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3877
+ ScreenLayout,
3878
+ {
3879
+ footer: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3880
+ !loading && /* @__PURE__ */ jsxRuntime.jsxs(PrimaryButton, { onClick: handleOpen, children: [
3881
+ "Open ",
3882
+ displayName
3883
+ ] }),
3884
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: hintStyle3(tokens.textMuted), children: loading ? "Preparing authorization..." : "Tap the button to authorize in your wallet app" })
3885
+ ] }),
3886
+ children: [
3887
+ /* @__PURE__ */ jsxRuntime.jsx(ScreenHeader, { right: /* @__PURE__ */ jsxRuntime.jsx(SettingsMenu, { onLogout }) }),
3888
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: contentStyle6, children: [
3889
+ logoSrc ? /* @__PURE__ */ jsxRuntime.jsx("img", { src: logoSrc, alt: displayName, style: logoStyle }) : /* @__PURE__ */ jsxRuntime.jsx(Spinner, { size: 48 }),
3890
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: headingStyle8(tokens.text), children: loading ? "Connecting..." : `Open ${displayName}` }),
3891
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: subtitleStyle8(tokens.textSecondary), children: loading ? "Creating transfer and preparing your wallet link..." : `Continue in ${displayName} to authorize this connection.` }),
3892
+ !loading && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: waitingBadgeStyle(tokens), children: [
3893
+ /* @__PURE__ */ jsxRuntime.jsx(Spinner, { size: 14 }),
3894
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: "Waiting for authorization..." })
3895
+ ] })
3896
+ ] })
3897
+ ]
3898
+ }
3899
+ );
3900
+ }
3901
+ var contentStyle6 = {
3902
+ flex: 1,
3903
+ display: "flex",
3904
+ flexDirection: "column",
3905
+ alignItems: "center",
3906
+ justifyContent: "center",
3907
+ textAlign: "center",
3908
+ padding: "0 24px"
3909
+ };
3910
+ var logoStyle = {
3911
+ width: 56,
3912
+ height: 56,
3913
+ borderRadius: 14,
3914
+ objectFit: "contain"
3915
+ };
3916
+ var headingStyle8 = (color) => ({
3917
+ fontSize: "1.45rem",
3918
+ fontWeight: 700,
3919
+ letterSpacing: "-0.02em",
3920
+ color,
3921
+ margin: "20px 0 8px"
3922
+ });
3923
+ var subtitleStyle8 = (color) => ({
3924
+ fontSize: "0.9rem",
3925
+ color,
3926
+ margin: "0 0 24px",
3927
+ lineHeight: 1.5,
3928
+ maxWidth: 280
3929
+ });
3930
+ var waitingBadgeStyle = (tokens) => ({
3931
+ display: "inline-flex",
3932
+ alignItems: "center",
3933
+ gap: 8,
3934
+ padding: "8px 16px",
3935
+ borderRadius: 20,
3936
+ background: tokens.bgInput,
3937
+ border: `1px solid ${tokens.border}`,
3938
+ color: tokens.textMuted,
3939
+ fontSize: "0.82rem"
3940
+ });
3941
+ var hintStyle3 = (color) => ({
3942
+ textAlign: "center",
3943
+ fontSize: "0.82rem",
3944
+ color,
3945
+ margin: "8px 0 0"
3946
+ });
3947
+ function isInIframe() {
3948
+ try {
3949
+ return typeof window !== "undefined" && window !== window.top;
3950
+ } catch {
3951
+ return true;
3952
+ }
3953
+ }
3854
3954
  var ACTIVE_CREDENTIAL_STORAGE_KEY = "swype_active_credential_id";
3855
3955
  var MIN_SEND_AMOUNT_USD = 0.25;
3856
3956
  function computeSmartDefaults(accts, transferAmount) {
@@ -3971,6 +4071,7 @@ function SwypePayment({
3971
4071
  const [otpCode, setOtpCode] = react.useState("");
3972
4072
  const [oneTapLimit, setOneTapLimit] = react.useState(100);
3973
4073
  const [mobileFlow, setMobileFlow] = react.useState(false);
4074
+ const [deeplinkUri, setDeeplinkUri] = react.useState(null);
3974
4075
  const pollingTransferIdRef = react.useRef(null);
3975
4076
  const mobileSigningTransferIdRef = react.useRef(null);
3976
4077
  const mobileSetupFlowRef = react.useRef(false);
@@ -4218,6 +4319,7 @@ function SwypePayment({
4218
4319
  if (mobileSetupFlowRef.current) {
4219
4320
  mobileSetupFlowRef.current = false;
4220
4321
  setMobileFlow(false);
4322
+ setDeeplinkUri(null);
4221
4323
  polling.stopPolling();
4222
4324
  setTransfer(polledTransfer);
4223
4325
  reloadAccounts().catch(() => {
@@ -4358,12 +4460,15 @@ function SwypePayment({
4358
4460
  return;
4359
4461
  }
4360
4462
  const isSetupRedirect = mobileSetupFlowRef.current;
4361
- if (!isSetupRedirect) {
4463
+ if (isSetupRedirect) {
4464
+ setStep("open-wallet");
4465
+ } else {
4362
4466
  setStep("processing");
4363
4467
  }
4364
4468
  processingStartedAtRef.current = Date.now();
4365
4469
  setError(null);
4366
4470
  setCreatingTransfer(true);
4471
+ setDeeplinkUri(null);
4367
4472
  setMobileFlow(false);
4368
4473
  try {
4369
4474
  if (transfer?.status === "AUTHORIZED") {
@@ -4387,7 +4492,7 @@ function SwypePayment({
4387
4492
  const isActiveWallet = effectiveSourceType === "walletId" && accounts.some(
4388
4493
  (a) => a.wallets.some((w) => w.id === effectiveSourceId && w.status === "ACTIVE")
4389
4494
  );
4390
- if (!isActiveWallet) {
4495
+ if (!isActiveWallet && !isSetupRedirect) {
4391
4496
  let found = false;
4392
4497
  for (const acct of accounts) {
4393
4498
  for (const wallet of acct.wallets) {
@@ -4417,11 +4522,14 @@ function SwypePayment({
4417
4522
  userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
4418
4523
  });
4419
4524
  if (!shouldUseConnector) {
4525
+ const uri = t.authorizationSessions[0].uri;
4420
4526
  setMobileFlow(true);
4421
4527
  pollingTransferIdRef.current = t.id;
4422
4528
  polling.startPolling(t.id);
4423
- if (!isActiveWallet) {
4424
- window.location.href = t.authorizationSessions[0].uri;
4529
+ setDeeplinkUri(uri);
4530
+ setStep("open-wallet");
4531
+ if (!isInIframe()) {
4532
+ window.location.href = uri;
4425
4533
  }
4426
4534
  return;
4427
4535
  } else {
@@ -4435,7 +4543,7 @@ function SwypePayment({
4435
4543
  const msg = err instanceof Error ? err.message : "Transfer failed";
4436
4544
  setError(msg);
4437
4545
  onError?.(msg);
4438
- setStep("deposit");
4546
+ setStep(isSetupRedirect ? "wallet-picker" : "deposit");
4439
4547
  } finally {
4440
4548
  setCreatingTransfer(false);
4441
4549
  }
@@ -4526,6 +4634,7 @@ function SwypePayment({
4526
4634
  setError(null);
4527
4635
  setAmount(depositAmount != null ? depositAmount.toString() : "");
4528
4636
  setMobileFlow(false);
4637
+ setDeeplinkUri(null);
4529
4638
  processingStartedAtRef.current = null;
4530
4639
  pollingTransferIdRef.current = null;
4531
4640
  mobileSigningTransferIdRef.current = null;
@@ -4557,6 +4666,7 @@ function SwypePayment({
4557
4666
  setConnectingNewAccount(false);
4558
4667
  setAmount(depositAmount != null ? depositAmount.toString() : "");
4559
4668
  setMobileFlow(false);
4669
+ setDeeplinkUri(null);
4560
4670
  resetHeadlessLogin();
4561
4671
  }, [logout, polling, depositAmount, resetHeadlessLogin]);
4562
4672
  if (!ready) {
@@ -4620,12 +4730,25 @@ function SwypePayment({
4620
4730
  {
4621
4731
  providers,
4622
4732
  pendingConnections,
4733
+ loading: creatingTransfer,
4623
4734
  onSelectProvider: handleSelectProvider,
4624
4735
  onContinueConnection: handleContinueConnection,
4625
4736
  onBack: () => setStep("create-passkey")
4626
4737
  }
4627
4738
  );
4628
4739
  }
4740
+ if (step === "open-wallet") {
4741
+ const providerName = providers.find((p) => p.id === selectedProviderId)?.name ?? null;
4742
+ return /* @__PURE__ */ jsxRuntime.jsx(
4743
+ OpenWalletScreen,
4744
+ {
4745
+ walletName: providerName,
4746
+ deeplinkUri: deeplinkUri ?? "",
4747
+ loading: creatingTransfer || !deeplinkUri,
4748
+ onLogout: handleLogout
4749
+ }
4750
+ );
4751
+ }
4629
4752
  if (step === "deposit") {
4630
4753
  if (loadingData) {
4631
4754
  return /* @__PURE__ */ jsxRuntime.jsx(ScreenLayout, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center", padding: "48px 0", flex: 1, display: "flex", alignItems: "center", justifyContent: "center" }, children: /* @__PURE__ */ jsxRuntime.jsx(Spinner, { label: "Loading..." }) }) });