@swype-org/react-sdk 0.1.123 → 0.1.124

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.d.cts CHANGED
@@ -582,6 +582,10 @@ interface UseAuthorizationExecutorResult {
582
582
  pendingSelectSource: AuthorizationAction | null;
583
583
  /** Call this from the UI to provide the user's chain+token choice. */
584
584
  resolveSelectSource: (selection: SourceSelection) => void;
585
+ /** The SIGN_PERMIT2 action when paused for One-Tap limit setup, null otherwise. */
586
+ pendingOneTapSetup: AuthorizationAction | null;
587
+ /** Call this from the UI after the user has set their One-Tap limit. */
588
+ resolveOneTapSetup: () => void;
585
589
  /** Execute authorization by session id. */
586
590
  executeSessionById: (sessionId: string) => Promise<void>;
587
591
  }
package/dist/index.d.ts CHANGED
@@ -582,6 +582,10 @@ interface UseAuthorizationExecutorResult {
582
582
  pendingSelectSource: AuthorizationAction | null;
583
583
  /** Call this from the UI to provide the user's chain+token choice. */
584
584
  resolveSelectSource: (selection: SourceSelection) => void;
585
+ /** The SIGN_PERMIT2 action when paused for One-Tap limit setup, null otherwise. */
586
+ pendingOneTapSetup: AuthorizationAction | null;
587
+ /** Call this from the UI after the user has set their One-Tap limit. */
588
+ resolveOneTapSetup: () => void;
585
589
  /** Execute authorization by session id. */
586
590
  executeSessionById: (sessionId: string) => Promise<void>;
587
591
  }
package/dist/index.js CHANGED
@@ -1433,6 +1433,22 @@ function useAuthorizationExecutor(options) {
1433
1433
  }),
1434
1434
  []
1435
1435
  );
1436
+ const [pendingOneTapSetup, setPendingOneTapSetup] = useState(null);
1437
+ const oneTapSetupResolverRef = useRef(null);
1438
+ const resolveOneTapSetup = useCallback(() => {
1439
+ if (oneTapSetupResolverRef.current) {
1440
+ oneTapSetupResolverRef.current();
1441
+ oneTapSetupResolverRef.current = null;
1442
+ setPendingOneTapSetup(null);
1443
+ }
1444
+ }, []);
1445
+ const waitForOneTapSetup = useCallback(
1446
+ (action) => new Promise((resolve) => {
1447
+ oneTapSetupResolverRef.current = resolve;
1448
+ setPendingOneTapSetup(action);
1449
+ }),
1450
+ []
1451
+ );
1436
1452
  const dispatchAction = useCallback(
1437
1453
  async (action) => {
1438
1454
  setCurrentAction(action);
@@ -1447,13 +1463,23 @@ function useAuthorizationExecutor(options) {
1447
1463
  return executeApprovePermit2(action, wagmiConfig2);
1448
1464
  case "DEPLOY_SMART_ACCOUNT":
1449
1465
  return actionSuccess(action, "Smart account deployment acknowledged.");
1450
- case "SIGN_PERMIT2":
1451
- return executeSignPermit2(action, wagmiConfig2, apiBaseUrl ?? "", sessionIdRef.current);
1466
+ case "SIGN_PERMIT2": {
1467
+ let resolvedAction = action;
1468
+ if (action.metadata?.awaitingLimit) {
1469
+ await waitForOneTapSetup(action);
1470
+ if (apiBaseUrl && sessionIdRef.current) {
1471
+ const session = await fetchAuthorizationSession(apiBaseUrl, sessionIdRef.current);
1472
+ const refreshed = session.actions.find((a) => a.id === action.id);
1473
+ if (refreshed) resolvedAction = refreshed;
1474
+ }
1475
+ }
1476
+ return executeSignPermit2(resolvedAction, wagmiConfig2, apiBaseUrl ?? "", sessionIdRef.current);
1477
+ }
1452
1478
  default:
1453
1479
  return actionError(action, `Unsupported action type: ${action.type}`);
1454
1480
  }
1455
1481
  },
1456
- [wagmiConfig2, connectors, connectAsync, switchChainAsync, apiBaseUrl, waitForSelection]
1482
+ [wagmiConfig2, connectors, connectAsync, switchChainAsync, apiBaseUrl, waitForSelection, waitForOneTapSetup]
1457
1483
  );
1458
1484
  const executeSessionById = useCallback(
1459
1485
  async (sessionId) => {
@@ -1524,6 +1550,8 @@ function useAuthorizationExecutor(options) {
1524
1550
  currentAction,
1525
1551
  pendingSelectSource,
1526
1552
  resolveSelectSource,
1553
+ pendingOneTapSetup,
1554
+ resolveOneTapSetup,
1527
1555
  executeSessionById
1528
1556
  };
1529
1557
  }
@@ -6568,7 +6596,7 @@ function SwypePaymentInner({
6568
6596
  } else {
6569
6597
  await authExecutor.executeSessionById(session.id);
6570
6598
  await reloadAccounts();
6571
- dispatch({ type: "NAVIGATE", step: "setup" });
6599
+ dispatch({ type: "NAVIGATE", step: "deposit" });
6572
6600
  }
6573
6601
  } catch (err) {
6574
6602
  captureException(err);
@@ -6617,7 +6645,11 @@ function SwypePaymentInner({
6617
6645
  const token = await getAccessToken();
6618
6646
  if (!token) throw new Error("Not authenticated");
6619
6647
  await updateUserConfig(apiBaseUrl, token, { defaultAllowance: limit });
6620
- dispatch({ type: "NAVIGATE", step: "deposit" });
6648
+ if (authExecutor.pendingOneTapSetup) {
6649
+ authExecutor.resolveOneTapSetup();
6650
+ } else {
6651
+ dispatch({ type: "NAVIGATE", step: "deposit" });
6652
+ }
6621
6653
  } catch (err) {
6622
6654
  captureException(err);
6623
6655
  dispatch({
@@ -6625,7 +6657,7 @@ function SwypePaymentInner({
6625
6657
  error: err instanceof Error ? err.message : "Failed to save One-Tap limit"
6626
6658
  });
6627
6659
  }
6628
- }, [getAccessToken, apiBaseUrl]);
6660
+ }, [getAccessToken, apiBaseUrl, authExecutor]);
6629
6661
  const handleNewPayment = useCallback(() => {
6630
6662
  clearMobileFlowState();
6631
6663
  processingStartedAtRef.current = null;
@@ -7155,6 +7187,17 @@ function SwypePaymentInner({
7155
7187
  });
7156
7188
  }
7157
7189
  }, [pendingSelectSourceAction, authExecutor]);
7190
+ const pendingOneTapSetupAction = authExecutor.pendingOneTapSetup;
7191
+ const preOneTapSetupStepRef = useRef(null);
7192
+ useEffect(() => {
7193
+ if (pendingOneTapSetupAction && state.step === "setup-status") {
7194
+ preOneTapSetupStepRef.current = state.step;
7195
+ dispatch({ type: "NAVIGATE", step: "setup" });
7196
+ } else if (!pendingOneTapSetupAction && state.step === "setup" && preOneTapSetupStepRef.current) {
7197
+ dispatch({ type: "NAVIGATE", step: preOneTapSetupStepRef.current });
7198
+ preOneTapSetupStepRef.current = null;
7199
+ }
7200
+ }, [pendingOneTapSetupAction, state.step]);
7158
7201
  const handlers = useMemo(() => ({
7159
7202
  onSendLoginCode: handleSendLoginCode,
7160
7203
  onVerifyLoginCode: handleVerifyLoginCode,