@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.cjs +56 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +56 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
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
|
}
|
|
@@ -5588,6 +5616,7 @@ function StepRenderer({
|
|
|
5588
5616
|
otpCode,
|
|
5589
5617
|
selectSourceChainName,
|
|
5590
5618
|
selectSourceTokenSymbol,
|
|
5619
|
+
savingOneTapLimit,
|
|
5591
5620
|
merchantName,
|
|
5592
5621
|
onBack,
|
|
5593
5622
|
onDismiss,
|
|
@@ -5711,7 +5740,7 @@ function StepRenderer({
|
|
|
5711
5740
|
onSetupOneTap: handlers.onSetupOneTap,
|
|
5712
5741
|
onBack: () => handlers.onNavigate("deposit"),
|
|
5713
5742
|
onLogout: handlers.onLogout,
|
|
5714
|
-
loading:
|
|
5743
|
+
loading: savingOneTapLimit,
|
|
5715
5744
|
error: state.error
|
|
5716
5745
|
}
|
|
5717
5746
|
);
|
|
@@ -5988,6 +6017,7 @@ function SwypePaymentInner({
|
|
|
5988
6017
|
const [otpCode, setOtpCode] = react.useState("");
|
|
5989
6018
|
const [selectSourceChainName, setSelectSourceChainName] = react.useState("");
|
|
5990
6019
|
const [selectSourceTokenSymbol, setSelectSourceTokenSymbol] = react.useState("");
|
|
6020
|
+
const [savingOneTapLimit, setSavingOneTapLimit] = react.useState(false);
|
|
5991
6021
|
const authExecutor = useAuthorizationExecutor();
|
|
5992
6022
|
const polling = useTransferPolling();
|
|
5993
6023
|
pollingRef.current = polling;
|
|
@@ -6571,7 +6601,7 @@ function SwypePaymentInner({
|
|
|
6571
6601
|
} else {
|
|
6572
6602
|
await authExecutor.executeSessionById(session.id);
|
|
6573
6603
|
await reloadAccounts();
|
|
6574
|
-
dispatch({ type: "NAVIGATE", step: "
|
|
6604
|
+
dispatch({ type: "NAVIGATE", step: "deposit" });
|
|
6575
6605
|
}
|
|
6576
6606
|
} catch (err) {
|
|
6577
6607
|
captureException(err);
|
|
@@ -6616,19 +6646,26 @@ function SwypePaymentInner({
|
|
|
6616
6646
|
[state.accounts, depositAmount]
|
|
6617
6647
|
);
|
|
6618
6648
|
const handleSetupOneTap = react.useCallback(async (limit) => {
|
|
6649
|
+
setSavingOneTapLimit(true);
|
|
6619
6650
|
try {
|
|
6620
6651
|
const token = await getAccessToken();
|
|
6621
6652
|
if (!token) throw new Error("Not authenticated");
|
|
6622
6653
|
await updateUserConfig(apiBaseUrl, token, { defaultAllowance: limit });
|
|
6623
|
-
|
|
6654
|
+
if (authExecutor.pendingOneTapSetup) {
|
|
6655
|
+
authExecutor.resolveOneTapSetup();
|
|
6656
|
+
} else {
|
|
6657
|
+
dispatch({ type: "NAVIGATE", step: "deposit" });
|
|
6658
|
+
}
|
|
6624
6659
|
} catch (err) {
|
|
6625
6660
|
captureException(err);
|
|
6626
6661
|
dispatch({
|
|
6627
6662
|
type: "SET_ERROR",
|
|
6628
6663
|
error: err instanceof Error ? err.message : "Failed to save One-Tap limit"
|
|
6629
6664
|
});
|
|
6665
|
+
} finally {
|
|
6666
|
+
setSavingOneTapLimit(false);
|
|
6630
6667
|
}
|
|
6631
|
-
}, [getAccessToken, apiBaseUrl]);
|
|
6668
|
+
}, [getAccessToken, apiBaseUrl, authExecutor]);
|
|
6632
6669
|
const handleNewPayment = react.useCallback(() => {
|
|
6633
6670
|
clearMobileFlowState();
|
|
6634
6671
|
processingStartedAtRef.current = null;
|
|
@@ -7158,6 +7195,17 @@ function SwypePaymentInner({
|
|
|
7158
7195
|
});
|
|
7159
7196
|
}
|
|
7160
7197
|
}, [pendingSelectSourceAction, authExecutor]);
|
|
7198
|
+
const pendingOneTapSetupAction = authExecutor.pendingOneTapSetup;
|
|
7199
|
+
const preOneTapSetupStepRef = react.useRef(null);
|
|
7200
|
+
react.useEffect(() => {
|
|
7201
|
+
if (pendingOneTapSetupAction && state.step === "setup-status") {
|
|
7202
|
+
preOneTapSetupStepRef.current = state.step;
|
|
7203
|
+
dispatch({ type: "NAVIGATE", step: "setup" });
|
|
7204
|
+
} else if (!pendingOneTapSetupAction && state.step === "setup" && preOneTapSetupStepRef.current) {
|
|
7205
|
+
dispatch({ type: "NAVIGATE", step: preOneTapSetupStepRef.current });
|
|
7206
|
+
preOneTapSetupStepRef.current = null;
|
|
7207
|
+
}
|
|
7208
|
+
}, [pendingOneTapSetupAction, state.step]);
|
|
7161
7209
|
const handlers = react.useMemo(() => ({
|
|
7162
7210
|
onSendLoginCode: handleSendLoginCode,
|
|
7163
7211
|
onVerifyLoginCode: handleVerifyLoginCode,
|
|
@@ -7241,6 +7289,7 @@ function SwypePaymentInner({
|
|
|
7241
7289
|
otpCode,
|
|
7242
7290
|
selectSourceChainName,
|
|
7243
7291
|
selectSourceTokenSymbol,
|
|
7292
|
+
savingOneTapLimit,
|
|
7244
7293
|
merchantName,
|
|
7245
7294
|
onBack,
|
|
7246
7295
|
onDismiss,
|