@swype-org/react-sdk 0.1.70 → 0.1.71

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
@@ -1644,6 +1644,23 @@ function resolveRestoredMobileFlow(transferStatus, isSetup) {
1644
1644
  }
1645
1645
  return { kind: "resume-open-wallet", step: "open-wallet", clearPersistedFlow: false };
1646
1646
  }
1647
+
1648
+ // src/dataLoading.ts
1649
+ function resolveDataLoadAction({
1650
+ authenticated,
1651
+ step,
1652
+ accountsCount,
1653
+ hasActiveCredential,
1654
+ loading
1655
+ }) {
1656
+ if (!authenticated || step === "login" || step === "otp-verify" || accountsCount > 0 || !hasActiveCredential) {
1657
+ return "reset";
1658
+ }
1659
+ if (loading) {
1660
+ return "wait";
1661
+ }
1662
+ return "load";
1663
+ }
1647
1664
  var FOOTER_CSS = `
1648
1665
  .swype-screen-footer {
1649
1666
  padding-bottom: max(24px, env(safe-area-inset-bottom, 24px));
@@ -4486,6 +4503,7 @@ function SwypePaymentInner({
4486
4503
  const [oneTapLimit, setOneTapLimit] = react.useState(100);
4487
4504
  const [mobileFlow, setMobileFlow] = react.useState(false);
4488
4505
  const [deeplinkUri, setDeeplinkUri] = react.useState(null);
4506
+ const loadingDataRef = react.useRef(false);
4489
4507
  const pollingTransferIdRef = react.useRef(null);
4490
4508
  const mobileSigningTransferIdRef = react.useRef(null);
4491
4509
  const mobileSetupFlowRef = react.useRef(false);
@@ -4516,6 +4534,10 @@ function SwypePaymentInner({
4516
4534
  setConnectingNewAccount(false);
4517
4535
  }
4518
4536
  }, [getAccessToken, activeCredentialId, apiBaseUrl, depositAmount]);
4537
+ const resetDataLoadingState = react.useCallback(() => {
4538
+ loadingDataRef.current = false;
4539
+ setLoadingData(false);
4540
+ }, []);
4519
4541
  const enterPersistedMobileFlow = react.useCallback((persisted, errorMessage) => {
4520
4542
  setMobileFlow(true);
4521
4543
  setDeeplinkUri(persisted.deeplinkUri);
@@ -4533,6 +4555,7 @@ function SwypePaymentInner({
4533
4555
  clearMobileFlowState();
4534
4556
  try {
4535
4557
  await reloadAccounts();
4558
+ resetDataLoadingState();
4536
4559
  setTransfer(null);
4537
4560
  setError(null);
4538
4561
  setDeeplinkUri(null);
@@ -4553,7 +4576,7 @@ function SwypePaymentInner({
4553
4576
  setDeeplinkUri(null);
4554
4577
  setMobileFlow(false);
4555
4578
  setStep("confirm-sign");
4556
- }, [polling.stopPolling, reloadAccounts]);
4579
+ }, [polling.stopPolling, reloadAccounts, resetDataLoadingState]);
4557
4580
  const handleRetryMobileStatus = react.useCallback(() => {
4558
4581
  setError(null);
4559
4582
  const currentTransfer = polling.transfer ?? transfer;
@@ -4781,12 +4804,26 @@ function SwypePaymentInner({
4781
4804
  handleAuthorizedMobileReturn,
4782
4805
  onComplete
4783
4806
  ]);
4784
- const loadingDataRef = react.useRef(false);
4785
4807
  react.useEffect(() => {
4786
- if (!authenticated) return;
4787
- if (step === "login" || step === "otp-verify") return;
4788
- if (accounts.length > 0 || loadingDataRef.current) return;
4789
- if (!activeCredentialId) return;
4808
+ const loadAction = resolveDataLoadAction({
4809
+ authenticated,
4810
+ step,
4811
+ accountsCount: accounts.length,
4812
+ hasActiveCredential: !!activeCredentialId,
4813
+ loading: loadingDataRef.current
4814
+ });
4815
+ if (loadAction === "reset") {
4816
+ resetDataLoadingState();
4817
+ return;
4818
+ }
4819
+ if (loadAction === "wait") {
4820
+ return;
4821
+ }
4822
+ const credentialId = activeCredentialId;
4823
+ if (!credentialId) {
4824
+ resetDataLoadingState();
4825
+ return;
4826
+ }
4790
4827
  let cancelled = false;
4791
4828
  loadingDataRef.current = true;
4792
4829
  const load = async () => {
@@ -4797,7 +4834,7 @@ function SwypePaymentInner({
4797
4834
  if (!token) throw new Error("Not authenticated");
4798
4835
  const [prov, accts, chn] = await Promise.all([
4799
4836
  fetchProviders(apiBaseUrl, token),
4800
- fetchAccounts(apiBaseUrl, token, activeCredentialId),
4837
+ fetchAccounts(apiBaseUrl, token, credentialId),
4801
4838
  fetchChains(apiBaseUrl, token)
4802
4839
  ]);
4803
4840
  if (cancelled) return;
@@ -4835,8 +4872,7 @@ function SwypePaymentInner({
4835
4872
  }
4836
4873
  } finally {
4837
4874
  if (!cancelled) {
4838
- setLoadingData(false);
4839
- loadingDataRef.current = false;
4875
+ resetDataLoadingState();
4840
4876
  }
4841
4877
  }
4842
4878
  };
@@ -4845,7 +4881,7 @@ function SwypePaymentInner({
4845
4881
  cancelled = true;
4846
4882
  loadingDataRef.current = false;
4847
4883
  };
4848
- }, [authenticated, step, accounts.length, apiBaseUrl, getAccessToken, activeCredentialId, depositAmount, connectingNewAccount]);
4884
+ }, [authenticated, step, accounts.length, apiBaseUrl, getAccessToken, activeCredentialId, depositAmount, connectingNewAccount, resetDataLoadingState]);
4849
4885
  react.useEffect(() => {
4850
4886
  if (!polling.transfer) return;
4851
4887
  if (polling.transfer.status === "COMPLETED") {