@swype-org/react-sdk 0.1.63 → 0.1.64
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 +80 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +80 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4449,6 +4449,24 @@ function buildSelectSourceChoices(options) {
|
|
|
4449
4449
|
}
|
|
4450
4450
|
return chainChoices;
|
|
4451
4451
|
}
|
|
4452
|
+
function resolvePostAuthStep(state) {
|
|
4453
|
+
if (!state.hasPasskey) {
|
|
4454
|
+
return { step: "create-passkey", clearPersistedFlow: false };
|
|
4455
|
+
}
|
|
4456
|
+
const hasActiveWallet = state.accounts.some(
|
|
4457
|
+
(a) => a.wallets.some((w) => w.status === "ACTIVE")
|
|
4458
|
+
);
|
|
4459
|
+
if (state.persistedMobileFlow) {
|
|
4460
|
+
if (hasActiveWallet && !state.mobileSetupInProgress) {
|
|
4461
|
+
return { step: "deposit", clearPersistedFlow: true };
|
|
4462
|
+
}
|
|
4463
|
+
return { step: "open-wallet", clearPersistedFlow: false };
|
|
4464
|
+
}
|
|
4465
|
+
if ((state.accounts.length === 0 || !hasActiveWallet) && !state.connectingNewAccount) {
|
|
4466
|
+
return { step: "wallet-picker", clearPersistedFlow: false };
|
|
4467
|
+
}
|
|
4468
|
+
return { step: "deposit", clearPersistedFlow: false };
|
|
4469
|
+
}
|
|
4452
4470
|
function SwypePayment(props) {
|
|
4453
4471
|
const resetKey = useRef(0);
|
|
4454
4472
|
const handleBoundaryReset = useCallback(() => {
|
|
@@ -4623,19 +4641,47 @@ function SwypePaymentInner({
|
|
|
4623
4641
|
let cancelled = false;
|
|
4624
4642
|
setError(null);
|
|
4625
4643
|
resetHeadlessLogin();
|
|
4626
|
-
const restoreOrDeposit = () => {
|
|
4644
|
+
const restoreOrDeposit = async (credId, token) => {
|
|
4627
4645
|
const persisted = loadMobileFlowState();
|
|
4628
|
-
|
|
4646
|
+
let accts = [];
|
|
4647
|
+
try {
|
|
4648
|
+
accts = await fetchAccounts(apiBaseUrl, token, credId);
|
|
4649
|
+
if (cancelled) return;
|
|
4650
|
+
} catch {
|
|
4651
|
+
}
|
|
4652
|
+
const resolved = resolvePostAuthStep({
|
|
4653
|
+
hasPasskey: true,
|
|
4654
|
+
accounts: accts,
|
|
4655
|
+
persistedMobileFlow: persisted,
|
|
4656
|
+
mobileSetupInProgress: false,
|
|
4657
|
+
connectingNewAccount: false
|
|
4658
|
+
});
|
|
4659
|
+
if (resolved.clearPersistedFlow) {
|
|
4660
|
+
clearMobileFlowState();
|
|
4661
|
+
}
|
|
4662
|
+
if (resolved.step === "open-wallet" && persisted) {
|
|
4663
|
+
try {
|
|
4664
|
+
const existingTransfer = await fetchTransfer(apiBaseUrl, token, persisted.transferId);
|
|
4665
|
+
if (cancelled) return;
|
|
4666
|
+
const terminalStatuses = ["AUTHORIZED", "COMPLETED", "FAILED"];
|
|
4667
|
+
if (terminalStatuses.includes(existingTransfer.status)) {
|
|
4668
|
+
clearMobileFlowState();
|
|
4669
|
+
setStep("deposit");
|
|
4670
|
+
return;
|
|
4671
|
+
}
|
|
4672
|
+
} catch {
|
|
4673
|
+
clearMobileFlowState();
|
|
4674
|
+
setStep("deposit");
|
|
4675
|
+
return;
|
|
4676
|
+
}
|
|
4629
4677
|
setMobileFlow(true);
|
|
4630
4678
|
setDeeplinkUri(persisted.deeplinkUri);
|
|
4631
4679
|
setSelectedProviderId(persisted.providerId);
|
|
4632
4680
|
pollingTransferIdRef.current = persisted.transferId;
|
|
4633
4681
|
mobileSetupFlowRef.current = persisted.isSetup;
|
|
4634
|
-
setStep("open-wallet");
|
|
4635
4682
|
polling.startPolling(persisted.transferId);
|
|
4636
|
-
} else {
|
|
4637
|
-
setStep("deposit");
|
|
4638
4683
|
}
|
|
4684
|
+
setStep(resolved.step);
|
|
4639
4685
|
};
|
|
4640
4686
|
const checkPasskey = async () => {
|
|
4641
4687
|
try {
|
|
@@ -4652,7 +4698,7 @@ function SwypePaymentInner({
|
|
|
4652
4698
|
return;
|
|
4653
4699
|
}
|
|
4654
4700
|
if (activeCredentialId && allPasskeys.some((p) => p.credentialId === activeCredentialId)) {
|
|
4655
|
-
restoreOrDeposit();
|
|
4701
|
+
await restoreOrDeposit(activeCredentialId, token);
|
|
4656
4702
|
return;
|
|
4657
4703
|
}
|
|
4658
4704
|
if (cancelled) return;
|
|
@@ -4662,7 +4708,7 @@ function SwypePaymentInner({
|
|
|
4662
4708
|
if (matched) {
|
|
4663
4709
|
setActiveCredentialId(matched);
|
|
4664
4710
|
window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, matched);
|
|
4665
|
-
restoreOrDeposit();
|
|
4711
|
+
await restoreOrDeposit(matched, token);
|
|
4666
4712
|
return;
|
|
4667
4713
|
}
|
|
4668
4714
|
setStep("create-passkey");
|
|
@@ -4706,11 +4752,22 @@ function SwypePaymentInner({
|
|
|
4706
4752
|
} else if (prov.length > 0 && !connectingNewAccount) {
|
|
4707
4753
|
setSelectedProviderId(prov[0].id);
|
|
4708
4754
|
}
|
|
4709
|
-
const
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4755
|
+
const persisted = loadMobileFlowState();
|
|
4756
|
+
const resolved = resolvePostAuthStep({
|
|
4757
|
+
hasPasskey: !!activeCredentialId,
|
|
4758
|
+
accounts: accts,
|
|
4759
|
+
persistedMobileFlow: persisted,
|
|
4760
|
+
mobileSetupInProgress: mobileSetupFlowRef.current,
|
|
4761
|
+
connectingNewAccount
|
|
4762
|
+
});
|
|
4763
|
+
if (resolved.clearPersistedFlow) {
|
|
4764
|
+
clearMobileFlowState();
|
|
4765
|
+
setMobileFlow(false);
|
|
4766
|
+
setDeeplinkUri(null);
|
|
4767
|
+
}
|
|
4768
|
+
const correctableSteps = ["deposit", "wallet-picker", "open-wallet"];
|
|
4769
|
+
if (correctableSteps.includes(step)) {
|
|
4770
|
+
setStep(resolved.step);
|
|
4714
4771
|
}
|
|
4715
4772
|
} catch (err) {
|
|
4716
4773
|
if (!cancelled) {
|
|
@@ -5021,15 +5078,18 @@ function SwypePaymentInner({
|
|
|
5021
5078
|
setActiveCredentialId(credentialId);
|
|
5022
5079
|
window.localStorage.setItem(ACTIVE_CREDENTIAL_STORAGE_KEY, credentialId);
|
|
5023
5080
|
setPasskeyPopupNeeded(false);
|
|
5024
|
-
const
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5081
|
+
const resolved = resolvePostAuthStep({
|
|
5082
|
+
hasPasskey: true,
|
|
5083
|
+
accounts,
|
|
5084
|
+
persistedMobileFlow: loadMobileFlowState(),
|
|
5085
|
+
mobileSetupInProgress: mobileSetupFlowRef.current,
|
|
5086
|
+
connectingNewAccount
|
|
5087
|
+
});
|
|
5088
|
+
if (resolved.clearPersistedFlow) {
|
|
5089
|
+
clearMobileFlowState();
|
|
5031
5090
|
}
|
|
5032
|
-
|
|
5091
|
+
setStep(resolved.step);
|
|
5092
|
+
}, [getAccessToken, apiBaseUrl, accounts, connectingNewAccount]);
|
|
5033
5093
|
const handleRegisterPasskey = useCallback(async () => {
|
|
5034
5094
|
setRegisteringPasskey(true);
|
|
5035
5095
|
setError(null);
|