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