@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 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(() => {
@@ -4357,10 +4459,16 @@ function SwypePayment({
4357
4459
  setStep("create-passkey");
4358
4460
  return;
4359
4461
  }
4360
- setStep("processing");
4462
+ const isSetupRedirect = mobileSetupFlowRef.current;
4463
+ if (isSetupRedirect) {
4464
+ setStep("open-wallet");
4465
+ } else {
4466
+ setStep("processing");
4467
+ }
4361
4468
  processingStartedAtRef.current = Date.now();
4362
4469
  setError(null);
4363
4470
  setCreatingTransfer(true);
4471
+ setDeeplinkUri(null);
4364
4472
  setMobileFlow(false);
4365
4473
  try {
4366
4474
  if (transfer?.status === "AUTHORIZED") {
@@ -4384,7 +4492,7 @@ function SwypePayment({
4384
4492
  const isActiveWallet = effectiveSourceType === "walletId" && accounts.some(
4385
4493
  (a) => a.wallets.some((w) => w.id === effectiveSourceId && w.status === "ACTIVE")
4386
4494
  );
4387
- if (!isActiveWallet) {
4495
+ if (!isActiveWallet && !isSetupRedirect) {
4388
4496
  let found = false;
4389
4497
  for (const acct of accounts) {
4390
4498
  for (const wallet of acct.wallets) {
@@ -4414,11 +4522,14 @@ function SwypePayment({
4414
4522
  userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
4415
4523
  });
4416
4524
  if (!shouldUseConnector) {
4525
+ const uri = t.authorizationSessions[0].uri;
4417
4526
  setMobileFlow(true);
4418
4527
  pollingTransferIdRef.current = t.id;
4419
4528
  polling.startPolling(t.id);
4420
- if (!isActiveWallet) {
4421
- window.location.href = t.authorizationSessions[0].uri;
4529
+ setDeeplinkUri(uri);
4530
+ setStep("open-wallet");
4531
+ if (!isInIframe()) {
4532
+ window.location.href = uri;
4422
4533
  }
4423
4534
  return;
4424
4535
  } else {
@@ -4432,7 +4543,7 @@ function SwypePayment({
4432
4543
  const msg = err instanceof Error ? err.message : "Transfer failed";
4433
4544
  setError(msg);
4434
4545
  onError?.(msg);
4435
- setStep("deposit");
4546
+ setStep(isSetupRedirect ? "wallet-picker" : "deposit");
4436
4547
  } finally {
4437
4548
  setCreatingTransfer(false);
4438
4549
  }
@@ -4523,6 +4634,7 @@ function SwypePayment({
4523
4634
  setError(null);
4524
4635
  setAmount(depositAmount != null ? depositAmount.toString() : "");
4525
4636
  setMobileFlow(false);
4637
+ setDeeplinkUri(null);
4526
4638
  processingStartedAtRef.current = null;
4527
4639
  pollingTransferIdRef.current = null;
4528
4640
  mobileSigningTransferIdRef.current = null;
@@ -4554,6 +4666,7 @@ function SwypePayment({
4554
4666
  setConnectingNewAccount(false);
4555
4667
  setAmount(depositAmount != null ? depositAmount.toString() : "");
4556
4668
  setMobileFlow(false);
4669
+ setDeeplinkUri(null);
4557
4670
  resetHeadlessLogin();
4558
4671
  }, [logout, polling, depositAmount, resetHeadlessLogin]);
4559
4672
  if (!ready) {
@@ -4617,12 +4730,25 @@ function SwypePayment({
4617
4730
  {
4618
4731
  providers,
4619
4732
  pendingConnections,
4733
+ loading: creatingTransfer,
4620
4734
  onSelectProvider: handleSelectProvider,
4621
4735
  onContinueConnection: handleContinueConnection,
4622
4736
  onBack: () => setStep("create-passkey")
4623
4737
  }
4624
4738
  );
4625
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
+ }
4626
4752
  if (step === "deposit") {
4627
4753
  if (loadingData) {
4628
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..." }) }) });