@swype-org/react-sdk 0.1.258 → 0.1.259

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.js CHANGED
@@ -2535,6 +2535,23 @@ function applyAction(state, action) {
2535
2535
  };
2536
2536
  case "GUEST_PREAUTH_SETUP_COMPLETE_DISMISSED":
2537
2537
  return { ...state, guestPreauthSetupCompletePending: false };
2538
+ case "RESTORE_GUEST_PREAUTH_MOBILE":
2539
+ return {
2540
+ ...state,
2541
+ transfer: action.transfer,
2542
+ isGuestFlow: true,
2543
+ guestSessionToken: action.guestSessionToken,
2544
+ guestTransferId: action.transfer.id,
2545
+ guestPreauthAccountId: action.guestPreauthAccountId,
2546
+ guestPreauthSessionId: action.guestPreauthSessionId,
2547
+ selectedProviderId: action.selectedProviderId,
2548
+ selectedAccountId: action.guestPreauthAccountId,
2549
+ selectedWalletId: null,
2550
+ selectedTokenSymbol: null,
2551
+ mobileFlow: action.mobileOpen,
2552
+ deeplinkUri: action.mobileOpen ? action.deeplinkUri : null,
2553
+ error: null
2554
+ };
2538
2555
  // ── User intent & error ──────────────────────────────────────
2539
2556
  case "SET_USER_INTENT":
2540
2557
  return { ...state, phase: action.intent };
@@ -4865,11 +4882,9 @@ function SuccessScreen({
4865
4882
  footer: /* @__PURE__ */ jsxs(Fragment, { children: [
4866
4883
  /* @__PURE__ */ jsx(PrimaryButton, { onClick: onDone, children: succeeded ? "Done" : "Try again" }),
4867
4884
  succeeded && onPreauthorize && /* @__PURE__ */ jsx(
4868
- "button",
4885
+ PrimaryButton,
4869
4886
  {
4870
- type: "button",
4871
4887
  onClick: onPreauthorize,
4872
- style: preauthorizeStyle(tokens.accent, tokens.border),
4873
4888
  children: "Preauthorize future transfers"
4874
4889
  }
4875
4890
  ),
@@ -4997,19 +5012,6 @@ var upsellLinkStyle = (color) => ({
4997
5012
  fontFamily: "inherit",
4998
5013
  padding: 0
4999
5014
  });
5000
- var preauthorizeStyle = (accentColor, borderColor) => ({
5001
- width: "100%",
5002
- padding: "14px 0",
5003
- marginTop: 8,
5004
- background: "transparent",
5005
- border: `1px solid ${borderColor}`,
5006
- borderRadius: 20,
5007
- color: accentColor,
5008
- fontWeight: 600,
5009
- fontSize: "0.92rem",
5010
- cursor: "pointer",
5011
- fontFamily: "inherit"
5012
- });
5013
5015
  var manageStyle = (color) => ({
5014
5016
  background: "transparent",
5015
5017
  border: "none",
@@ -7311,6 +7313,7 @@ function useProviderHandlers(deps) {
7311
7313
  merchantAuthorization,
7312
7314
  destination,
7313
7315
  guestSessionToken,
7316
+ guestTransferId,
7314
7317
  selectedProviderId
7315
7318
  } = deps;
7316
7319
  const wagmiConfig2 = useConfig();
@@ -7744,7 +7747,9 @@ function useProviderHandlers(deps) {
7744
7747
  deeplinkUri: created.sessionUri,
7745
7748
  providerId: selectedProviderId,
7746
7749
  isSetup: true,
7747
- guestSessionToken
7750
+ guestSessionToken,
7751
+ transferId: guestTransferId ?? void 0,
7752
+ isGuestPreauth: true
7748
7753
  });
7749
7754
  triggerDeeplink(created.sessionUri);
7750
7755
  dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: created.sessionUri });
@@ -7767,6 +7772,7 @@ function useProviderHandlers(deps) {
7767
7772
  }
7768
7773
  }, [
7769
7774
  guestSessionToken,
7775
+ guestTransferId,
7770
7776
  selectedProviderId,
7771
7777
  providers,
7772
7778
  apiBaseUrl,
@@ -8603,6 +8609,66 @@ function useMobilePollingEffect(deps) {
8603
8609
  if (!polledTransfer || polledTransfer.status !== "AUTHORIZED") return;
8604
8610
  void handleAuthorizedMobileReturnRef.current(polledTransfer, mobileSetupFlowRef.current);
8605
8611
  }, [state.mobileFlow, polling.transfer, handlingMobileReturnRef, mobileSetupFlowRef]);
8612
+ useEffect(() => {
8613
+ if (!state.mobileFlow || !mobileSetupFlowRef.current) return;
8614
+ if (!setupAccountIdRef.current) return;
8615
+ if (!state.guestPreauthSessionId || !state.isGuestFlow) return;
8616
+ if (state.activeCredentialId) return;
8617
+ const sessionId = state.guestPreauthSessionId;
8618
+ let cancelled = false;
8619
+ let completedGuestPreauth = false;
8620
+ const POLL_INTERVAL_MS = 3e3;
8621
+ const completeGuestPreauthSetup = async () => {
8622
+ if (completedGuestPreauth) return;
8623
+ completedGuestPreauth = true;
8624
+ cancelled = true;
8625
+ mobileSetupFlowRef.current = false;
8626
+ setupAccountIdRef.current = null;
8627
+ clearMobileFlowState();
8628
+ try {
8629
+ await reloadAccounts();
8630
+ } catch {
8631
+ }
8632
+ dispatch({ type: "MOBILE_SETUP_COMPLETE" });
8633
+ };
8634
+ const pollGuestPreauthSession = async () => {
8635
+ try {
8636
+ if (cancelled) return;
8637
+ const session = await fetchAuthorizationSession(apiBaseUrl, sessionId);
8638
+ if (cancelled) return;
8639
+ if (session.status === "AUTHORIZED") {
8640
+ await completeGuestPreauthSetup();
8641
+ }
8642
+ } catch {
8643
+ }
8644
+ };
8645
+ pollGuestPreauthSession();
8646
+ const intervalId = window.setInterval(pollGuestPreauthSession, POLL_INTERVAL_MS);
8647
+ const handleVisibility = () => {
8648
+ if (document.visibilityState === "visible" && !cancelled) void pollGuestPreauthSession();
8649
+ };
8650
+ const handlePageShow = (e) => {
8651
+ if (e.persisted && !cancelled) void pollGuestPreauthSession();
8652
+ };
8653
+ document.addEventListener("visibilitychange", handleVisibility);
8654
+ window.addEventListener("pageshow", handlePageShow);
8655
+ return () => {
8656
+ cancelled = true;
8657
+ window.clearInterval(intervalId);
8658
+ document.removeEventListener("visibilitychange", handleVisibility);
8659
+ window.removeEventListener("pageshow", handlePageShow);
8660
+ };
8661
+ }, [
8662
+ state.mobileFlow,
8663
+ state.activeCredentialId,
8664
+ state.guestPreauthSessionId,
8665
+ state.isGuestFlow,
8666
+ apiBaseUrl,
8667
+ reloadAccounts,
8668
+ dispatch,
8669
+ mobileSetupFlowRef,
8670
+ setupAccountIdRef
8671
+ ]);
8606
8672
  useEffect(() => {
8607
8673
  if (!state.mobileFlow || !mobileSetupFlowRef.current) return;
8608
8674
  if (!state.activeCredentialId || !setupAccountIdRef.current) return;
@@ -8733,6 +8799,63 @@ function useMobilePollingEffect(deps) {
8733
8799
  pollingTransferIdRef
8734
8800
  ]);
8735
8801
  }
8802
+ var guestPreauthRestoreAttemptedKeys = /* @__PURE__ */ new Set();
8803
+ function guestPreauthRestoreKey(sessionId, transferId) {
8804
+ return `${sessionId}:${transferId}`;
8805
+ }
8806
+ function useGuestPreauthMobileRestoreEffect(deps) {
8807
+ const {
8808
+ dispatch,
8809
+ apiBaseUrl,
8810
+ privyReady,
8811
+ authenticated,
8812
+ mobileSetupFlowRef,
8813
+ setupAccountIdRef
8814
+ } = deps;
8815
+ useEffect(() => {
8816
+ if (!privyReady || authenticated) return;
8817
+ const persisted = loadMobileFlowState();
8818
+ if (!persisted?.isGuestPreauth || !persisted.transferId || !persisted.guestSessionToken || !persisted.sessionId || !persisted.deeplinkUri || persisted.accountId == null) {
8819
+ return;
8820
+ }
8821
+ const key = guestPreauthRestoreKey(persisted.sessionId, persisted.transferId);
8822
+ if (guestPreauthRestoreAttemptedKeys.has(key)) return;
8823
+ guestPreauthRestoreAttemptedKeys.add(key);
8824
+ let cancelled = false;
8825
+ void (async () => {
8826
+ try {
8827
+ const [transfer, session] = await Promise.all([
8828
+ getGuestTransfer(apiBaseUrl, persisted.transferId, persisted.guestSessionToken),
8829
+ fetchAuthorizationSession(apiBaseUrl, persisted.sessionId)
8830
+ ]);
8831
+ if (cancelled) return;
8832
+ const mobileOpen = session.status !== "AUTHORIZED";
8833
+ dispatch({
8834
+ type: "RESTORE_GUEST_PREAUTH_MOBILE",
8835
+ transfer,
8836
+ guestSessionToken: persisted.guestSessionToken,
8837
+ guestPreauthAccountId: persisted.accountId,
8838
+ guestPreauthSessionId: persisted.sessionId,
8839
+ selectedProviderId: persisted.providerId,
8840
+ deeplinkUri: persisted.deeplinkUri,
8841
+ mobileOpen
8842
+ });
8843
+ if (mobileOpen) {
8844
+ mobileSetupFlowRef.current = true;
8845
+ setupAccountIdRef.current = persisted.accountId;
8846
+ } else {
8847
+ clearMobileFlowState();
8848
+ }
8849
+ } catch (err) {
8850
+ guestPreauthRestoreAttemptedKeys.delete(key);
8851
+ captureException(err);
8852
+ }
8853
+ })();
8854
+ return () => {
8855
+ cancelled = true;
8856
+ };
8857
+ }, [privyReady, authenticated, apiBaseUrl, dispatch, mobileSetupFlowRef, setupAccountIdRef]);
8858
+ }
8736
8859
  function useSelectSourceEffect(deps) {
8737
8860
  const {
8738
8861
  pendingSelectSourceAction,
@@ -9108,6 +9231,7 @@ function BlinkPaymentInner({
9108
9231
  merchantAuthorization,
9109
9232
  destination,
9110
9233
  guestSessionToken: state.guestSessionToken,
9234
+ guestTransferId: state.guestTransferId,
9111
9235
  selectedProviderId: state.selectedProviderId
9112
9236
  });
9113
9237
  const guestPostPayPreauth = useMemo(
@@ -9169,6 +9293,14 @@ function BlinkPaymentInner({
9169
9293
  }
9170
9294
  }, [depositAmount, dispatch]);
9171
9295
  usePrivySessionSyncEffect({ dispatch, ready, authenticated });
9296
+ useGuestPreauthMobileRestoreEffect({
9297
+ dispatch,
9298
+ apiBaseUrl,
9299
+ privyReady: state.privyReady,
9300
+ authenticated,
9301
+ mobileSetupFlowRef: mobileFlowRefs.mobileSetupFlowRef,
9302
+ setupAccountIdRef: mobileFlowRefs.setupAccountIdRef
9303
+ });
9172
9304
  useOtpEffects({
9173
9305
  state,
9174
9306
  dispatch,