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