@swype-org/react-sdk 0.1.260 → 0.1.262
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 +134 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +134 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2442,13 +2442,37 @@ function applyAction(state, action) {
|
|
|
2442
2442
|
selectedProviderId: action.providerId ?? state.selectedProviderId,
|
|
2443
2443
|
error: action.error ?? null
|
|
2444
2444
|
};
|
|
2445
|
-
case "MOBILE_RESUME_SUCCESS":
|
|
2445
|
+
case "MOBILE_RESUME_SUCCESS": {
|
|
2446
|
+
const guestResume = action.guestCheckoutResume;
|
|
2446
2447
|
return {
|
|
2447
2448
|
...state,
|
|
2448
2449
|
transfer: action.transfer,
|
|
2449
2450
|
error: null,
|
|
2450
2451
|
mobileFlow: false,
|
|
2451
|
-
deeplinkUri: null
|
|
2452
|
+
deeplinkUri: null,
|
|
2453
|
+
...guestResume ? {
|
|
2454
|
+
isGuestFlow: true,
|
|
2455
|
+
guestSessionToken: guestResume.guestSessionToken,
|
|
2456
|
+
guestTransferId: action.transfer.id
|
|
2457
|
+
} : {}
|
|
2458
|
+
};
|
|
2459
|
+
}
|
|
2460
|
+
case "GUEST_PREAUTH_RESUME_WITH_TRANSFER":
|
|
2461
|
+
return {
|
|
2462
|
+
...state,
|
|
2463
|
+
transfer: action.transfer,
|
|
2464
|
+
error: null,
|
|
2465
|
+
mobileFlow: false,
|
|
2466
|
+
deeplinkUri: null,
|
|
2467
|
+
isGuestFlow: true,
|
|
2468
|
+
guestSessionToken: action.guestSessionToken,
|
|
2469
|
+
guestTransferId: action.transfer.id,
|
|
2470
|
+
guestPreauthAccountId: action.guestPreauthAccountId,
|
|
2471
|
+
guestPreauthSessionId: action.guestPreauthSessionId ?? state.guestPreauthSessionId,
|
|
2472
|
+
selectedProviderId: action.selectedProviderId,
|
|
2473
|
+
selectedAccountId: action.guestPreauthAccountId,
|
|
2474
|
+
selectedWalletId: null,
|
|
2475
|
+
selectedTokenSymbol: null
|
|
2452
2476
|
};
|
|
2453
2477
|
case "MOBILE_RESUME_FAILED":
|
|
2454
2478
|
return {
|
|
@@ -8242,6 +8266,38 @@ function usePasskeyCheckEffect(deps) {
|
|
|
8242
8266
|
if (cancelled) return;
|
|
8243
8267
|
if (existingTransfer.status === "COMPLETED") {
|
|
8244
8268
|
clearMobileFlowState();
|
|
8269
|
+
if (persisted.isGuestPreauth && persisted.guestSessionToken) {
|
|
8270
|
+
let guestLookup = null;
|
|
8271
|
+
try {
|
|
8272
|
+
guestLookup = await fetchGuestAccount(
|
|
8273
|
+
apiBaseUrl,
|
|
8274
|
+
persisted.guestSessionToken
|
|
8275
|
+
);
|
|
8276
|
+
} catch {
|
|
8277
|
+
dispatch({ type: "MOBILE_RESUME_SUCCESS", transfer: existingTransfer });
|
|
8278
|
+
onCompleteRef.current?.(existingTransfer);
|
|
8279
|
+
return;
|
|
8280
|
+
}
|
|
8281
|
+
if (guestLookup == null) {
|
|
8282
|
+
dispatch({
|
|
8283
|
+
type: "MOBILE_RESUME_SUCCESS",
|
|
8284
|
+
transfer: existingTransfer,
|
|
8285
|
+
guestCheckoutResume: { guestSessionToken: persisted.guestSessionToken }
|
|
8286
|
+
});
|
|
8287
|
+
onCompleteRef.current?.(existingTransfer);
|
|
8288
|
+
return;
|
|
8289
|
+
}
|
|
8290
|
+
dispatch({
|
|
8291
|
+
type: "GUEST_PREAUTH_RESUME_WITH_TRANSFER",
|
|
8292
|
+
transfer: existingTransfer,
|
|
8293
|
+
guestSessionToken: persisted.guestSessionToken,
|
|
8294
|
+
guestPreauthAccountId: guestLookup.accountId,
|
|
8295
|
+
guestPreauthSessionId: persisted.sessionId ?? null,
|
|
8296
|
+
selectedProviderId: persisted.providerId
|
|
8297
|
+
});
|
|
8298
|
+
onCompleteRef.current?.(existingTransfer);
|
|
8299
|
+
return;
|
|
8300
|
+
}
|
|
8245
8301
|
dispatch({ type: "MOBILE_RESUME_SUCCESS", transfer: existingTransfer });
|
|
8246
8302
|
onCompleteRef.current?.(existingTransfer);
|
|
8247
8303
|
return;
|
|
@@ -8597,9 +8653,11 @@ function useMobilePollingEffect(deps) {
|
|
|
8597
8653
|
reloadAccounts,
|
|
8598
8654
|
apiBaseUrl
|
|
8599
8655
|
} = deps;
|
|
8600
|
-
const { getAccessToken } = reactAuth.usePrivy();
|
|
8656
|
+
const { getAccessToken, authenticated: privyAuthenticated } = reactAuth.usePrivy();
|
|
8601
8657
|
const getAccessTokenRef = react.useRef(getAccessToken);
|
|
8602
8658
|
getAccessTokenRef.current = getAccessToken;
|
|
8659
|
+
const privyAuthenticatedRef = react.useRef(privyAuthenticated);
|
|
8660
|
+
privyAuthenticatedRef.current = privyAuthenticated;
|
|
8603
8661
|
const handleAuthorizedMobileReturnRef = react.useRef(deps.handleAuthorizedMobileReturn);
|
|
8604
8662
|
handleAuthorizedMobileReturnRef.current = deps.handleAuthorizedMobileReturn;
|
|
8605
8663
|
react.useEffect(() => {
|
|
@@ -8607,16 +8665,25 @@ function useMobilePollingEffect(deps) {
|
|
|
8607
8665
|
handlingMobileReturnRef.current = false;
|
|
8608
8666
|
return;
|
|
8609
8667
|
}
|
|
8668
|
+
if (state.isGuestFlow && state.guestPreauthSessionId != null && mobileSetupFlowRef.current) {
|
|
8669
|
+
return;
|
|
8670
|
+
}
|
|
8610
8671
|
if (handlingMobileReturnRef.current) return;
|
|
8611
8672
|
const polledTransfer = polling.transfer;
|
|
8612
8673
|
if (!polledTransfer || polledTransfer.status !== "AUTHORIZED") return;
|
|
8613
8674
|
void handleAuthorizedMobileReturnRef.current(polledTransfer, mobileSetupFlowRef.current);
|
|
8614
|
-
}, [
|
|
8675
|
+
}, [
|
|
8676
|
+
state.mobileFlow,
|
|
8677
|
+
state.isGuestFlow,
|
|
8678
|
+
state.guestPreauthSessionId,
|
|
8679
|
+
polling.transfer,
|
|
8680
|
+
handlingMobileReturnRef,
|
|
8681
|
+
mobileSetupFlowRef
|
|
8682
|
+
]);
|
|
8615
8683
|
react.useEffect(() => {
|
|
8616
8684
|
if (!state.mobileFlow || !mobileSetupFlowRef.current) return;
|
|
8617
8685
|
if (!setupAccountIdRef.current) return;
|
|
8618
8686
|
if (!state.guestPreauthSessionId || !state.isGuestFlow) return;
|
|
8619
|
-
if (state.activeCredentialId) return;
|
|
8620
8687
|
const sessionId = state.guestPreauthSessionId;
|
|
8621
8688
|
let cancelled = false;
|
|
8622
8689
|
let completedGuestPreauth = false;
|
|
@@ -8632,6 +8699,34 @@ function useMobilePollingEffect(deps) {
|
|
|
8632
8699
|
await reloadAccounts();
|
|
8633
8700
|
} catch {
|
|
8634
8701
|
}
|
|
8702
|
+
const guestToken = state.guestSessionToken;
|
|
8703
|
+
const preauthAccountId = state.guestPreauthAccountId;
|
|
8704
|
+
const preauthSessionId = state.guestPreauthSessionId;
|
|
8705
|
+
if (!guestToken) {
|
|
8706
|
+
dispatch({ type: "MOBILE_SETUP_COMPLETE" });
|
|
8707
|
+
return;
|
|
8708
|
+
}
|
|
8709
|
+
let guestLookup = null;
|
|
8710
|
+
try {
|
|
8711
|
+
guestLookup = await fetchGuestAccount(apiBaseUrl, guestToken);
|
|
8712
|
+
} catch {
|
|
8713
|
+
dispatch({ type: "MOBILE_SETUP_COMPLETE" });
|
|
8714
|
+
return;
|
|
8715
|
+
}
|
|
8716
|
+
if (guestLookup == null) {
|
|
8717
|
+
dispatch({ type: "MOBILE_SETUP_COMPLETE" });
|
|
8718
|
+
return;
|
|
8719
|
+
}
|
|
8720
|
+
if (guestLookup.accountId !== preauthAccountId) {
|
|
8721
|
+
dispatch({
|
|
8722
|
+
type: "GUEST_PREAUTH_DETECTED",
|
|
8723
|
+
accountId: guestLookup.accountId,
|
|
8724
|
+
sessionId: preauthSessionId ?? void 0
|
|
8725
|
+
});
|
|
8726
|
+
}
|
|
8727
|
+
if (!privyAuthenticatedRef.current) {
|
|
8728
|
+
dispatch({ type: "REQUEST_LOGIN" });
|
|
8729
|
+
}
|
|
8635
8730
|
dispatch({ type: "MOBILE_SETUP_COMPLETE" });
|
|
8636
8731
|
};
|
|
8637
8732
|
const pollGuestPreauthSession = async () => {
|
|
@@ -8663,9 +8758,10 @@ function useMobilePollingEffect(deps) {
|
|
|
8663
8758
|
};
|
|
8664
8759
|
}, [
|
|
8665
8760
|
state.mobileFlow,
|
|
8666
|
-
state.activeCredentialId,
|
|
8667
8761
|
state.guestPreauthSessionId,
|
|
8668
8762
|
state.isGuestFlow,
|
|
8763
|
+
state.guestSessionToken,
|
|
8764
|
+
state.guestPreauthAccountId,
|
|
8669
8765
|
apiBaseUrl,
|
|
8670
8766
|
reloadAccounts,
|
|
8671
8767
|
dispatch,
|
|
@@ -8674,6 +8770,7 @@ function useMobilePollingEffect(deps) {
|
|
|
8674
8770
|
]);
|
|
8675
8771
|
react.useEffect(() => {
|
|
8676
8772
|
if (!state.mobileFlow || !mobileSetupFlowRef.current) return;
|
|
8773
|
+
if (state.isGuestFlow && state.guestPreauthSessionId != null) return;
|
|
8677
8774
|
if (!state.activeCredentialId || !setupAccountIdRef.current) return;
|
|
8678
8775
|
const accountId = setupAccountIdRef.current;
|
|
8679
8776
|
const credentialId = state.activeCredentialId;
|
|
@@ -8762,6 +8859,8 @@ function useMobilePollingEffect(deps) {
|
|
|
8762
8859
|
};
|
|
8763
8860
|
}, [
|
|
8764
8861
|
state.mobileFlow,
|
|
8862
|
+
state.isGuestFlow,
|
|
8863
|
+
state.guestPreauthSessionId,
|
|
8765
8864
|
state.activeCredentialId,
|
|
8766
8865
|
apiBaseUrl,
|
|
8767
8866
|
reloadAccounts,
|
|
@@ -8833,11 +8932,38 @@ function useGuestPreauthMobileRestoreEffect(deps) {
|
|
|
8833
8932
|
]);
|
|
8834
8933
|
if (cancelled) return;
|
|
8835
8934
|
const mobileOpen = session.status !== "AUTHORIZED";
|
|
8935
|
+
let guestLookup = null;
|
|
8936
|
+
if (!mobileOpen) {
|
|
8937
|
+
try {
|
|
8938
|
+
guestLookup = await fetchGuestAccount(
|
|
8939
|
+
apiBaseUrl,
|
|
8940
|
+
persisted.guestSessionToken
|
|
8941
|
+
);
|
|
8942
|
+
} catch {
|
|
8943
|
+
dispatch({
|
|
8944
|
+
type: "MOBILE_RESUME_SUCCESS",
|
|
8945
|
+
transfer,
|
|
8946
|
+
guestCheckoutResume: { guestSessionToken: persisted.guestSessionToken }
|
|
8947
|
+
});
|
|
8948
|
+
clearMobileFlowState();
|
|
8949
|
+
return;
|
|
8950
|
+
}
|
|
8951
|
+
if (guestLookup == null) {
|
|
8952
|
+
dispatch({
|
|
8953
|
+
type: "MOBILE_RESUME_SUCCESS",
|
|
8954
|
+
transfer,
|
|
8955
|
+
guestCheckoutResume: { guestSessionToken: persisted.guestSessionToken }
|
|
8956
|
+
});
|
|
8957
|
+
clearMobileFlowState();
|
|
8958
|
+
return;
|
|
8959
|
+
}
|
|
8960
|
+
}
|
|
8961
|
+
const guestPreauthAccountId = !mobileOpen && guestLookup != null ? guestLookup.accountId : persisted.accountId;
|
|
8836
8962
|
dispatch({
|
|
8837
8963
|
type: "RESTORE_GUEST_PREAUTH_MOBILE",
|
|
8838
8964
|
transfer,
|
|
8839
8965
|
guestSessionToken: persisted.guestSessionToken,
|
|
8840
|
-
guestPreauthAccountId
|
|
8966
|
+
guestPreauthAccountId,
|
|
8841
8967
|
guestPreauthSessionId: persisted.sessionId,
|
|
8842
8968
|
selectedProviderId: persisted.providerId,
|
|
8843
8969
|
deeplinkUri: persisted.deeplinkUri,
|
|
@@ -8845,7 +8971,7 @@ function useGuestPreauthMobileRestoreEffect(deps) {
|
|
|
8845
8971
|
});
|
|
8846
8972
|
if (mobileOpen) {
|
|
8847
8973
|
mobileSetupFlowRef.current = true;
|
|
8848
|
-
setupAccountIdRef.current = persisted.accountId;
|
|
8974
|
+
setupAccountIdRef.current = persisted.accountId ?? null;
|
|
8849
8975
|
} else {
|
|
8850
8976
|
clearMobileFlowState();
|
|
8851
8977
|
}
|