@swype-org/react-sdk 0.1.123 → 0.1.125

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
  }
@@ -5585,6 +5613,7 @@ function StepRenderer({
5585
5613
  otpCode,
5586
5614
  selectSourceChainName,
5587
5615
  selectSourceTokenSymbol,
5616
+ savingOneTapLimit,
5588
5617
  merchantName,
5589
5618
  onBack,
5590
5619
  onDismiss,
@@ -5708,7 +5737,7 @@ function StepRenderer({
5708
5737
  onSetupOneTap: handlers.onSetupOneTap,
5709
5738
  onBack: () => handlers.onNavigate("deposit"),
5710
5739
  onLogout: handlers.onLogout,
5711
- loading: state.creatingTransfer,
5740
+ loading: savingOneTapLimit,
5712
5741
  error: state.error
5713
5742
  }
5714
5743
  );
@@ -5985,6 +6014,7 @@ function SwypePaymentInner({
5985
6014
  const [otpCode, setOtpCode] = useState("");
5986
6015
  const [selectSourceChainName, setSelectSourceChainName] = useState("");
5987
6016
  const [selectSourceTokenSymbol, setSelectSourceTokenSymbol] = useState("");
6017
+ const [savingOneTapLimit, setSavingOneTapLimit] = useState(false);
5988
6018
  const authExecutor = useAuthorizationExecutor();
5989
6019
  const polling = useTransferPolling();
5990
6020
  pollingRef.current = polling;
@@ -6568,7 +6598,7 @@ function SwypePaymentInner({
6568
6598
  } else {
6569
6599
  await authExecutor.executeSessionById(session.id);
6570
6600
  await reloadAccounts();
6571
- dispatch({ type: "NAVIGATE", step: "setup" });
6601
+ dispatch({ type: "NAVIGATE", step: "deposit" });
6572
6602
  }
6573
6603
  } catch (err) {
6574
6604
  captureException(err);
@@ -6613,19 +6643,26 @@ function SwypePaymentInner({
6613
6643
  [state.accounts, depositAmount]
6614
6644
  );
6615
6645
  const handleSetupOneTap = useCallback(async (limit) => {
6646
+ setSavingOneTapLimit(true);
6616
6647
  try {
6617
6648
  const token = await getAccessToken();
6618
6649
  if (!token) throw new Error("Not authenticated");
6619
6650
  await updateUserConfig(apiBaseUrl, token, { defaultAllowance: limit });
6620
- dispatch({ type: "NAVIGATE", step: "deposit" });
6651
+ if (authExecutor.pendingOneTapSetup) {
6652
+ authExecutor.resolveOneTapSetup();
6653
+ } else {
6654
+ dispatch({ type: "NAVIGATE", step: "deposit" });
6655
+ }
6621
6656
  } catch (err) {
6622
6657
  captureException(err);
6623
6658
  dispatch({
6624
6659
  type: "SET_ERROR",
6625
6660
  error: err instanceof Error ? err.message : "Failed to save One-Tap limit"
6626
6661
  });
6662
+ } finally {
6663
+ setSavingOneTapLimit(false);
6627
6664
  }
6628
- }, [getAccessToken, apiBaseUrl]);
6665
+ }, [getAccessToken, apiBaseUrl, authExecutor]);
6629
6666
  const handleNewPayment = useCallback(() => {
6630
6667
  clearMobileFlowState();
6631
6668
  processingStartedAtRef.current = null;
@@ -7155,6 +7192,17 @@ function SwypePaymentInner({
7155
7192
  });
7156
7193
  }
7157
7194
  }, [pendingSelectSourceAction, authExecutor]);
7195
+ const pendingOneTapSetupAction = authExecutor.pendingOneTapSetup;
7196
+ const preOneTapSetupStepRef = useRef(null);
7197
+ useEffect(() => {
7198
+ if (pendingOneTapSetupAction && state.step === "setup-status") {
7199
+ preOneTapSetupStepRef.current = state.step;
7200
+ dispatch({ type: "NAVIGATE", step: "setup" });
7201
+ } else if (!pendingOneTapSetupAction && state.step === "setup" && preOneTapSetupStepRef.current) {
7202
+ dispatch({ type: "NAVIGATE", step: preOneTapSetupStepRef.current });
7203
+ preOneTapSetupStepRef.current = null;
7204
+ }
7205
+ }, [pendingOneTapSetupAction, state.step]);
7158
7206
  const handlers = useMemo(() => ({
7159
7207
  onSendLoginCode: handleSendLoginCode,
7160
7208
  onVerifyLoginCode: handleVerifyLoginCode,
@@ -7238,6 +7286,7 @@ function SwypePaymentInner({
7238
7286
  otpCode,
7239
7287
  selectSourceChainName,
7240
7288
  selectSourceTokenSymbol,
7289
+ savingOneTapLimit,
7241
7290
  merchantName,
7242
7291
  onBack,
7243
7292
  onDismiss,