@swype-org/react-sdk 0.1.158 → 0.1.160

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
@@ -2110,6 +2110,18 @@ function maskAuthIdentifier(identifier) {
2110
2110
  const visibleSuffix = digits.slice(-4);
2111
2111
  return `***-***-${visibleSuffix}`;
2112
2112
  }
2113
+
2114
+ // src/walletFlow.ts
2115
+ var MOBILE_USER_AGENT_PATTERN = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
2116
+ function isMobileUserAgent(userAgent) {
2117
+ if (!userAgent) {
2118
+ return false;
2119
+ }
2120
+ return MOBILE_USER_AGENT_PATTERN.test(userAgent);
2121
+ }
2122
+ function shouldUseWalletConnector(options) {
2123
+ return options.useWalletConnector ?? !isMobileUserAgent(options.userAgent);
2124
+ }
2113
2125
  var ACCENT = "#28b67a";
2114
2126
  var BG_RING = "#d2e4ea";
2115
2127
  function SwypeLoadingScreen() {
@@ -3432,6 +3444,7 @@ function WalletPickerScreen({
3432
3444
  providers,
3433
3445
  pendingConnections,
3434
3446
  loading,
3447
+ useDeeplink,
3435
3448
  onPrepareProvider,
3436
3449
  onSelectProvider,
3437
3450
  onContinueConnection,
@@ -3485,7 +3498,7 @@ function WalletPickerScreen({
3485
3498
  {
3486
3499
  onClick: () => {
3487
3500
  const session = preparedSession?.providerId === selectedProvider.id ? preparedSession : void 0;
3488
- if (session) {
3501
+ if (session && useDeeplink) {
3489
3502
  const opened = window.open(session.uri, "_blank");
3490
3503
  if (!opened && window === window.parent) {
3491
3504
  window.location.href = session.uri;
@@ -4205,13 +4218,10 @@ function DepositScreen({
4205
4218
  remainingLimit.toFixed(2),
4206
4219
  ". Increase your limit to continue."
4207
4220
  ] })
4208
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4209
- /* @__PURE__ */ jsxRuntime.jsxs(PrimaryButton, { onClick: () => onDeposit(amount), disabled: !canDeposit, loading: processing, children: [
4210
- "Deposit $",
4211
- amount.toFixed(2)
4212
- ] }),
4213
- /* @__PURE__ */ jsxRuntime.jsx("p", { style: noApprovalStyle(tokens.textMuted), children: "No approval needed \xB7 within your One-Tap limit" })
4214
- ] }),
4221
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsxs(PrimaryButton, { onClick: () => onDeposit(amount), disabled: !canDeposit, loading: processing, children: [
4222
+ "Deposit $",
4223
+ amount.toFixed(2)
4224
+ ] }) }),
4215
4225
  /* @__PURE__ */ jsxRuntime.jsxs("p", { style: routeStyle(tokens.textMuted), children: [
4216
4226
  "From ",
4217
4227
  sourceName,
@@ -4269,22 +4279,13 @@ function DepositScreen({
4269
4279
  }
4270
4280
  )
4271
4281
  ] }),
4272
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: detailsStyle, children: [
4273
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: detailRowStyle(tokens.textMuted), children: [
4274
- "Remaining limit: ",
4275
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { style: { color: tokens.text }, children: [
4276
- "$",
4277
- remainingLimit.toFixed(2)
4278
- ] })
4279
- ] }),
4280
- estimatedFeeUsd != null && estimatedFeePct != null ? /* @__PURE__ */ jsxRuntime.jsxs("div", { style: detailRowStyle(tokens.textMuted), children: [
4281
- "Fee: ~$",
4282
- estimatedFeeUsd.toFixed(2),
4283
- " (",
4284
- estimatedFeePct.toFixed(1),
4285
- "%)"
4286
- ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { style: detailRowStyle(tokens.textMuted), children: "Fees calculated at time of transfer" })
4287
- ] }),
4282
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: detailsStyle, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: detailRowStyle(tokens.textMuted), children: [
4283
+ "Remaining limit: ",
4284
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { style: { color: tokens.text }, children: [
4285
+ "$",
4286
+ remainingLimit.toFixed(2)
4287
+ ] })
4288
+ ] }) }),
4288
4289
  error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: errorBannerStyle5(tokens), children: error })
4289
4290
  ]
4290
4291
  }
@@ -4366,12 +4367,6 @@ var errorBannerStyle5 = (tokens) => ({
4366
4367
  marginTop: 8,
4367
4368
  lineHeight: 1.5
4368
4369
  });
4369
- var noApprovalStyle = (color) => ({
4370
- textAlign: "center",
4371
- fontSize: "0.78rem",
4372
- color,
4373
- margin: "12px 0 2px"
4374
- });
4375
4370
  var limitExceededHintStyle = (color) => ({
4376
4371
  textAlign: "center",
4377
4372
  fontSize: "0.78rem",
@@ -5596,6 +5591,9 @@ function StepRenderer({
5596
5591
  providers: state.providers,
5597
5592
  pendingConnections,
5598
5593
  loading: state.creatingTransfer,
5594
+ useDeeplink: !shouldUseWalletConnector({
5595
+ userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
5596
+ }),
5599
5597
  onPrepareProvider: handlers.onPrepareProvider,
5600
5598
  onSelectProvider: handlers.onSelectProvider,
5601
5599
  onContinueConnection: handlers.onContinueConnection,
@@ -6472,16 +6470,10 @@ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransfe
6472
6470
  clearMobileFlowState();
6473
6471
  try {
6474
6472
  await reloadAccounts();
6475
- loadingDataRef.current = false;
6476
- dispatch({ type: "MOBILE_SETUP_COMPLETE", transfer: authorizedTransfer });
6477
- } catch (err) {
6478
- handlingMobileReturnRef.current = false;
6479
- dispatch({
6480
- type: "SET_ERROR",
6481
- error: err instanceof Error ? err.message : "Wallet authorized, but we could not refresh your account yet."
6482
- });
6483
- dispatch({ type: "NAVIGATE", step: "open-wallet" });
6473
+ } catch {
6484
6474
  }
6475
+ loadingDataRef.current = false;
6476
+ dispatch({ type: "MOBILE_SETUP_COMPLETE", transfer: authorizedTransfer });
6485
6477
  return;
6486
6478
  }
6487
6479
  mobileSetupFlowRef.current = false;
@@ -6506,20 +6498,6 @@ function useMobileFlowHandlers(dispatch, polling, reloadAccounts, pollingTransfe
6506
6498
  handleRetryMobileStatus
6507
6499
  };
6508
6500
  }
6509
-
6510
- // src/walletFlow.ts
6511
- var MOBILE_USER_AGENT_PATTERN = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
6512
- function isMobileUserAgent(userAgent) {
6513
- if (!userAgent) {
6514
- return false;
6515
- }
6516
- return MOBILE_USER_AGENT_PATTERN.test(userAgent);
6517
- }
6518
- function shouldUseWalletConnector(options) {
6519
- return options.useWalletConnector ?? !isMobileUserAgent(options.userAgent);
6520
- }
6521
-
6522
- // src/hooks/useProviderHandlers.ts
6523
6501
  function useProviderHandlers(deps) {
6524
6502
  const {
6525
6503
  dispatch,
@@ -6624,9 +6602,7 @@ function useProviderHandlers(deps) {
6624
6602
  providerId,
6625
6603
  isSetup: true
6626
6604
  });
6627
- if (!preparedSession) {
6628
- triggerDeeplink(sessionUri);
6629
- }
6605
+ triggerDeeplink(sessionUri);
6630
6606
  dispatch({ type: "MOBILE_DEEPLINK_READY", deeplinkUri: sessionUri });
6631
6607
  } else {
6632
6608
  await authExecutor.executeSessionById(sessionId);
@@ -6662,7 +6638,17 @@ function useProviderHandlers(deps) {
6662
6638
  const acct = accounts.find((a) => a.id === accountId);
6663
6639
  if (!acct) return;
6664
6640
  const matchedProvider = providers.find((p) => p.name === acct.name);
6665
- if (matchedProvider) {
6641
+ if (!matchedProvider) return;
6642
+ const pendingSession = acct.authorizationSessions?.find(
6643
+ (s) => s.status === "PENDING"
6644
+ );
6645
+ if (pendingSession) {
6646
+ handleSelectProvider(matchedProvider.id, {
6647
+ accountId: acct.id,
6648
+ sessionId: pendingSession.id,
6649
+ uri: pendingSession.uri
6650
+ });
6651
+ } else {
6666
6652
  handleSelectProvider(matchedProvider.id);
6667
6653
  }
6668
6654
  },
@@ -7099,8 +7085,25 @@ function usePaymentEffects(deps) {
7099
7085
  return;
7100
7086
  }
7101
7087
  if (resolved.step === "open-wallet" && persisted && persisted.accountId && !persisted.transferId) {
7102
- clearMobileFlowState();
7103
- dispatch({ type: "NAVIGATE", step: "deposit" });
7088
+ if (persisted.sessionId) {
7089
+ try {
7090
+ const session = await fetchAuthorizationSession(apiBaseUrl, persisted.sessionId);
7091
+ if (cancelled) return;
7092
+ if (session.status === "AUTHORIZED") {
7093
+ clearMobileFlowState();
7094
+ dispatch({ type: "NAVIGATE", step: "deposit" });
7095
+ return;
7096
+ }
7097
+ } catch {
7098
+ }
7099
+ }
7100
+ mobileSetupFlowRef.current = true;
7101
+ setupAccountIdRef.current = persisted.accountId;
7102
+ dispatch({
7103
+ type: "ENTER_MOBILE_FLOW",
7104
+ deeplinkUri: persisted.deeplinkUri,
7105
+ providerId: persisted.providerId
7106
+ });
7104
7107
  return;
7105
7108
  }
7106
7109
  if (resolved.step === "open-wallet" && persisted && persisted.transferId) {
@@ -7369,6 +7372,8 @@ function usePaymentEffects(deps) {
7369
7372
  const isReauth = !!reauthSessionIdRef.current;
7370
7373
  const sessionId = reauthSessionIdRef.current;
7371
7374
  const tokenSelection = reauthTokenRef.current;
7375
+ const persistedFlow = loadMobileFlowState();
7376
+ const setupSessionId = !isReauth ? persistedFlow?.sessionId : void 0;
7372
7377
  let cancelled = false;
7373
7378
  const POLL_INTERVAL_MS = 3e3;
7374
7379
  const pollReauthorization = async () => {
@@ -7395,6 +7400,17 @@ function usePaymentEffects(deps) {
7395
7400
  } catch {
7396
7401
  }
7397
7402
  };
7403
+ const completeSetup = async () => {
7404
+ cancelled = true;
7405
+ mobileSetupFlowRef.current = false;
7406
+ setupAccountIdRef.current = null;
7407
+ clearMobileFlowState();
7408
+ try {
7409
+ await reloadAccounts();
7410
+ } catch {
7411
+ }
7412
+ dispatch({ type: "MOBILE_SETUP_COMPLETE" });
7413
+ };
7398
7414
  const pollWalletActive = async () => {
7399
7415
  try {
7400
7416
  const token = await getAccessTokenRef.current();
@@ -7403,15 +7419,18 @@ function usePaymentEffects(deps) {
7403
7419
  if (cancelled) return;
7404
7420
  const hasActive = acct.wallets.some((w) => w.status === "ACTIVE");
7405
7421
  if (hasActive) {
7406
- cancelled = true;
7407
- mobileSetupFlowRef.current = false;
7408
- setupAccountIdRef.current = null;
7409
- clearMobileFlowState();
7422
+ await completeSetup();
7423
+ return;
7424
+ }
7425
+ if (setupSessionId) {
7410
7426
  try {
7411
- await reloadAccounts();
7427
+ const session = await fetchAuthorizationSession(apiBaseUrl, setupSessionId);
7428
+ if (cancelled) return;
7429
+ if (session.status === "AUTHORIZED") {
7430
+ await completeSetup();
7431
+ }
7412
7432
  } catch {
7413
7433
  }
7414
- dispatch({ type: "MOBILE_SETUP_COMPLETE" });
7415
7434
  }
7416
7435
  } catch {
7417
7436
  }