@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.js CHANGED
@@ -1641,6 +1641,23 @@ function resolveRestoredMobileFlow(transferStatus, isSetup) {
1641
1641
  }
1642
1642
  return { kind: "resume-open-wallet", step: "open-wallet", clearPersistedFlow: false };
1643
1643
  }
1644
+
1645
+ // src/dataLoading.ts
1646
+ function resolveDataLoadAction({
1647
+ authenticated,
1648
+ step,
1649
+ accountsCount,
1650
+ hasActiveCredential,
1651
+ loading
1652
+ }) {
1653
+ if (!authenticated || step === "login" || step === "otp-verify" || accountsCount > 0 || !hasActiveCredential) {
1654
+ return "reset";
1655
+ }
1656
+ if (loading) {
1657
+ return "wait";
1658
+ }
1659
+ return "load";
1660
+ }
1644
1661
  var FOOTER_CSS = `
1645
1662
  .swype-screen-footer {
1646
1663
  padding-bottom: max(24px, env(safe-area-inset-bottom, 24px));
@@ -4483,6 +4500,7 @@ function SwypePaymentInner({
4483
4500
  const [oneTapLimit, setOneTapLimit] = useState(100);
4484
4501
  const [mobileFlow, setMobileFlow] = useState(false);
4485
4502
  const [deeplinkUri, setDeeplinkUri] = useState(null);
4503
+ const loadingDataRef = useRef(false);
4486
4504
  const pollingTransferIdRef = useRef(null);
4487
4505
  const mobileSigningTransferIdRef = useRef(null);
4488
4506
  const mobileSetupFlowRef = useRef(false);
@@ -4513,6 +4531,10 @@ function SwypePaymentInner({
4513
4531
  setConnectingNewAccount(false);
4514
4532
  }
4515
4533
  }, [getAccessToken, activeCredentialId, apiBaseUrl, depositAmount]);
4534
+ const resetDataLoadingState = useCallback(() => {
4535
+ loadingDataRef.current = false;
4536
+ setLoadingData(false);
4537
+ }, []);
4516
4538
  const enterPersistedMobileFlow = useCallback((persisted, errorMessage) => {
4517
4539
  setMobileFlow(true);
4518
4540
  setDeeplinkUri(persisted.deeplinkUri);
@@ -4530,6 +4552,7 @@ function SwypePaymentInner({
4530
4552
  clearMobileFlowState();
4531
4553
  try {
4532
4554
  await reloadAccounts();
4555
+ resetDataLoadingState();
4533
4556
  setTransfer(null);
4534
4557
  setError(null);
4535
4558
  setDeeplinkUri(null);
@@ -4550,7 +4573,7 @@ function SwypePaymentInner({
4550
4573
  setDeeplinkUri(null);
4551
4574
  setMobileFlow(false);
4552
4575
  setStep("confirm-sign");
4553
- }, [polling.stopPolling, reloadAccounts]);
4576
+ }, [polling.stopPolling, reloadAccounts, resetDataLoadingState]);
4554
4577
  const handleRetryMobileStatus = useCallback(() => {
4555
4578
  setError(null);
4556
4579
  const currentTransfer = polling.transfer ?? transfer;
@@ -4778,12 +4801,26 @@ function SwypePaymentInner({
4778
4801
  handleAuthorizedMobileReturn,
4779
4802
  onComplete
4780
4803
  ]);
4781
- const loadingDataRef = useRef(false);
4782
4804
  useEffect(() => {
4783
- if (!authenticated) return;
4784
- if (step === "login" || step === "otp-verify") return;
4785
- if (accounts.length > 0 || loadingDataRef.current) return;
4786
- if (!activeCredentialId) return;
4805
+ const loadAction = resolveDataLoadAction({
4806
+ authenticated,
4807
+ step,
4808
+ accountsCount: accounts.length,
4809
+ hasActiveCredential: !!activeCredentialId,
4810
+ loading: loadingDataRef.current
4811
+ });
4812
+ if (loadAction === "reset") {
4813
+ resetDataLoadingState();
4814
+ return;
4815
+ }
4816
+ if (loadAction === "wait") {
4817
+ return;
4818
+ }
4819
+ const credentialId = activeCredentialId;
4820
+ if (!credentialId) {
4821
+ resetDataLoadingState();
4822
+ return;
4823
+ }
4787
4824
  let cancelled = false;
4788
4825
  loadingDataRef.current = true;
4789
4826
  const load = async () => {
@@ -4794,7 +4831,7 @@ function SwypePaymentInner({
4794
4831
  if (!token) throw new Error("Not authenticated");
4795
4832
  const [prov, accts, chn] = await Promise.all([
4796
4833
  fetchProviders(apiBaseUrl, token),
4797
- fetchAccounts(apiBaseUrl, token, activeCredentialId),
4834
+ fetchAccounts(apiBaseUrl, token, credentialId),
4798
4835
  fetchChains(apiBaseUrl, token)
4799
4836
  ]);
4800
4837
  if (cancelled) return;
@@ -4832,8 +4869,7 @@ function SwypePaymentInner({
4832
4869
  }
4833
4870
  } finally {
4834
4871
  if (!cancelled) {
4835
- setLoadingData(false);
4836
- loadingDataRef.current = false;
4872
+ resetDataLoadingState();
4837
4873
  }
4838
4874
  }
4839
4875
  };
@@ -4842,7 +4878,7 @@ function SwypePaymentInner({
4842
4878
  cancelled = true;
4843
4879
  loadingDataRef.current = false;
4844
4880
  };
4845
- }, [authenticated, step, accounts.length, apiBaseUrl, getAccessToken, activeCredentialId, depositAmount, connectingNewAccount]);
4881
+ }, [authenticated, step, accounts.length, apiBaseUrl, getAccessToken, activeCredentialId, depositAmount, connectingNewAccount, resetDataLoadingState]);
4846
4882
  useEffect(() => {
4847
4883
  if (!polling.transfer) return;
4848
4884
  if (polling.transfer.status === "COMPLETED") {