@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.cjs CHANGED
@@ -1436,6 +1436,22 @@ function useAuthorizationExecutor(options) {
1436
1436
  }),
1437
1437
  []
1438
1438
  );
1439
+ const [pendingOneTapSetup, setPendingOneTapSetup] = react.useState(null);
1440
+ const oneTapSetupResolverRef = react.useRef(null);
1441
+ const resolveOneTapSetup = react.useCallback(() => {
1442
+ if (oneTapSetupResolverRef.current) {
1443
+ oneTapSetupResolverRef.current();
1444
+ oneTapSetupResolverRef.current = null;
1445
+ setPendingOneTapSetup(null);
1446
+ }
1447
+ }, []);
1448
+ const waitForOneTapSetup = react.useCallback(
1449
+ (action) => new Promise((resolve) => {
1450
+ oneTapSetupResolverRef.current = resolve;
1451
+ setPendingOneTapSetup(action);
1452
+ }),
1453
+ []
1454
+ );
1439
1455
  const dispatchAction = react.useCallback(
1440
1456
  async (action) => {
1441
1457
  setCurrentAction(action);
@@ -1450,13 +1466,23 @@ function useAuthorizationExecutor(options) {
1450
1466
  return executeApprovePermit2(action, wagmiConfig2);
1451
1467
  case "DEPLOY_SMART_ACCOUNT":
1452
1468
  return actionSuccess(action, "Smart account deployment acknowledged.");
1453
- case "SIGN_PERMIT2":
1454
- return executeSignPermit2(action, wagmiConfig2, apiBaseUrl ?? "", sessionIdRef.current);
1469
+ case "SIGN_PERMIT2": {
1470
+ let resolvedAction = action;
1471
+ if (action.metadata?.awaitingLimit) {
1472
+ await waitForOneTapSetup(action);
1473
+ if (apiBaseUrl && sessionIdRef.current) {
1474
+ const session = await fetchAuthorizationSession(apiBaseUrl, sessionIdRef.current);
1475
+ const refreshed = session.actions.find((a) => a.id === action.id);
1476
+ if (refreshed) resolvedAction = refreshed;
1477
+ }
1478
+ }
1479
+ return executeSignPermit2(resolvedAction, wagmiConfig2, apiBaseUrl ?? "", sessionIdRef.current);
1480
+ }
1455
1481
  default:
1456
1482
  return actionError(action, `Unsupported action type: ${action.type}`);
1457
1483
  }
1458
1484
  },
1459
- [wagmiConfig2, connectors, connectAsync, switchChainAsync, apiBaseUrl, waitForSelection]
1485
+ [wagmiConfig2, connectors, connectAsync, switchChainAsync, apiBaseUrl, waitForSelection, waitForOneTapSetup]
1460
1486
  );
1461
1487
  const executeSessionById = react.useCallback(
1462
1488
  async (sessionId) => {
@@ -1527,6 +1553,8 @@ function useAuthorizationExecutor(options) {
1527
1553
  currentAction,
1528
1554
  pendingSelectSource,
1529
1555
  resolveSelectSource,
1556
+ pendingOneTapSetup,
1557
+ resolveOneTapSetup,
1530
1558
  executeSessionById
1531
1559
  };
1532
1560
  }
@@ -6571,7 +6599,7 @@ function SwypePaymentInner({
6571
6599
  } else {
6572
6600
  await authExecutor.executeSessionById(session.id);
6573
6601
  await reloadAccounts();
6574
- dispatch({ type: "NAVIGATE", step: "setup" });
6602
+ dispatch({ type: "NAVIGATE", step: "deposit" });
6575
6603
  }
6576
6604
  } catch (err) {
6577
6605
  captureException(err);
@@ -6620,7 +6648,11 @@ function SwypePaymentInner({
6620
6648
  const token = await getAccessToken();
6621
6649
  if (!token) throw new Error("Not authenticated");
6622
6650
  await updateUserConfig(apiBaseUrl, token, { defaultAllowance: limit });
6623
- dispatch({ type: "NAVIGATE", step: "deposit" });
6651
+ if (authExecutor.pendingOneTapSetup) {
6652
+ authExecutor.resolveOneTapSetup();
6653
+ } else {
6654
+ dispatch({ type: "NAVIGATE", step: "deposit" });
6655
+ }
6624
6656
  } catch (err) {
6625
6657
  captureException(err);
6626
6658
  dispatch({
@@ -6628,7 +6660,7 @@ function SwypePaymentInner({
6628
6660
  error: err instanceof Error ? err.message : "Failed to save One-Tap limit"
6629
6661
  });
6630
6662
  }
6631
- }, [getAccessToken, apiBaseUrl]);
6663
+ }, [getAccessToken, apiBaseUrl, authExecutor]);
6632
6664
  const handleNewPayment = react.useCallback(() => {
6633
6665
  clearMobileFlowState();
6634
6666
  processingStartedAtRef.current = null;
@@ -7158,6 +7190,17 @@ function SwypePaymentInner({
7158
7190
  });
7159
7191
  }
7160
7192
  }, [pendingSelectSourceAction, authExecutor]);
7193
+ const pendingOneTapSetupAction = authExecutor.pendingOneTapSetup;
7194
+ const preOneTapSetupStepRef = react.useRef(null);
7195
+ react.useEffect(() => {
7196
+ if (pendingOneTapSetupAction && state.step === "setup-status") {
7197
+ preOneTapSetupStepRef.current = state.step;
7198
+ dispatch({ type: "NAVIGATE", step: "setup" });
7199
+ } else if (!pendingOneTapSetupAction && state.step === "setup" && preOneTapSetupStepRef.current) {
7200
+ dispatch({ type: "NAVIGATE", step: preOneTapSetupStepRef.current });
7201
+ preOneTapSetupStepRef.current = null;
7202
+ }
7203
+ }, [pendingOneTapSetupAction, state.step]);
7161
7204
  const handlers = react.useMemo(() => ({
7162
7205
  onSendLoginCode: handleSendLoginCode,
7163
7206
  onVerifyLoginCode: handleVerifyLoginCode,