@swype-org/react-sdk 0.1.73 → 0.1.76

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
@@ -1604,6 +1604,28 @@ function shouldUseWalletConnector(options) {
1604
1604
  return options.useWalletConnector ?? !isMobileUserAgent(options.userAgent);
1605
1605
  }
1606
1606
 
1607
+ // src/deeplink.ts
1608
+ var IFRAME_CLEANUP_DELAY_MS = 3e3;
1609
+ var LOCATION_FALLBACK_DELAY_MS = 100;
1610
+ function triggerDeeplink(uri) {
1611
+ try {
1612
+ const iframe = document.createElement("iframe");
1613
+ iframe.style.display = "none";
1614
+ iframe.src = uri;
1615
+ document.body.appendChild(iframe);
1616
+ setTimeout(() => {
1617
+ try {
1618
+ document.body.removeChild(iframe);
1619
+ } catch {
1620
+ }
1621
+ }, IFRAME_CLEANUP_DELAY_MS);
1622
+ } catch {
1623
+ }
1624
+ setTimeout(() => {
1625
+ window.location.href = uri;
1626
+ }, LOCATION_FALLBACK_DELAY_MS);
1627
+ }
1628
+
1607
1629
  // src/mobileFlow.ts
1608
1630
  function hasActiveWallet(accounts) {
1609
1631
  return accounts.some((account) => account.wallets.some((wallet) => wallet.status === "ACTIVE"));
@@ -4112,7 +4134,7 @@ function OpenWalletScreen({
4112
4134
  react.useEffect(() => {
4113
4135
  if (loading || !deeplinkUri || autoOpenedRef.current === deeplinkUri) return;
4114
4136
  autoOpenedRef.current = deeplinkUri;
4115
- window.location.href = deeplinkUri;
4137
+ triggerDeeplink(deeplinkUri);
4116
4138
  }, [loading, deeplinkUri]);
4117
4139
  const handleOpen = react.useCallback(() => {
4118
4140
  const opened = window.open(deeplinkUri, "_blank");
@@ -4513,6 +4535,7 @@ function SwypePaymentInner({
4513
4535
  const pollingTransferIdRef = react.useRef(null);
4514
4536
  const mobileSigningTransferIdRef = react.useRef(null);
4515
4537
  const mobileSetupFlowRef = react.useRef(false);
4538
+ const handlingMobileReturnRef = react.useRef(false);
4516
4539
  const processingStartedAtRef = react.useRef(null);
4517
4540
  const [selectSourceChainName, setSelectSourceChainName] = react.useState("");
4518
4541
  const [selectSourceTokenSymbol, setSelectSourceTokenSymbol] = react.useState("");
@@ -4555,6 +4578,8 @@ function SwypePaymentInner({
4555
4578
  polling.startPolling(persisted.transferId);
4556
4579
  }, [polling]);
4557
4580
  const handleAuthorizedMobileReturn = react.useCallback(async (authorizedTransfer, isSetup) => {
4581
+ if (handlingMobileReturnRef.current) return;
4582
+ handlingMobileReturnRef.current = true;
4558
4583
  polling.stopPolling();
4559
4584
  if (isSetup) {
4560
4585
  mobileSetupFlowRef.current = false;
@@ -4568,6 +4593,7 @@ function SwypePaymentInner({
4568
4593
  setMobileFlow(false);
4569
4594
  setStep("deposit");
4570
4595
  } catch (err) {
4596
+ handlingMobileReturnRef.current = false;
4571
4597
  setError(
4572
4598
  err instanceof Error ? err.message : "Wallet authorized, but we could not refresh your account yet."
4573
4599
  );
@@ -4585,6 +4611,7 @@ function SwypePaymentInner({
4585
4611
  }, [polling.stopPolling, reloadAccounts, resetDataLoadingState]);
4586
4612
  const handleRetryMobileStatus = react.useCallback(() => {
4587
4613
  setError(null);
4614
+ handlingMobileReturnRef.current = false;
4588
4615
  const currentTransfer = polling.transfer ?? transfer;
4589
4616
  if (currentTransfer?.status === "AUTHORIZED") {
4590
4617
  void handleAuthorizedMobileReturn(currentTransfer, mobileSetupFlowRef.current);
@@ -4930,18 +4957,23 @@ function SwypePaymentInner({
4930
4957
  return () => window.clearTimeout(timeoutId);
4931
4958
  }, [step, polling.transfer, transfer, polling.stopPolling, onError]);
4932
4959
  react.useEffect(() => {
4933
- if (!mobileFlow) return;
4960
+ if (!mobileFlow) {
4961
+ handlingMobileReturnRef.current = false;
4962
+ return;
4963
+ }
4964
+ if (handlingMobileReturnRef.current) return;
4934
4965
  const polledTransfer = polling.transfer;
4935
4966
  if (!polledTransfer || polledTransfer.status !== "AUTHORIZED") return;
4936
4967
  void handleAuthorizedMobileReturn(polledTransfer, mobileSetupFlowRef.current);
4937
4968
  }, [mobileFlow, polling.transfer, handleAuthorizedMobileReturn]);
4938
4969
  react.useEffect(() => {
4939
4970
  if (!mobileFlow) return;
4971
+ if (handlingMobileReturnRef.current) return;
4940
4972
  const transferIdToResume = pollingTransferIdRef.current ?? transfer?.id;
4941
4973
  if (!transferIdToResume) return;
4942
4974
  if (!polling.isPolling) polling.startPolling(transferIdToResume);
4943
4975
  const handleVisibility = () => {
4944
- if (document.visibilityState === "visible") {
4976
+ if (document.visibilityState === "visible" && !handlingMobileReturnRef.current) {
4945
4977
  polling.startPolling(transferIdToResume);
4946
4978
  }
4947
4979
  };
@@ -5126,7 +5158,7 @@ function SwypePaymentInner({
5126
5158
  providerId: sourceOverrides?.sourceType === "providerId" ? sourceOverrides.sourceId : selectedProviderId,
5127
5159
  isSetup: mobileSetupFlowRef.current
5128
5160
  });
5129
- window.location.href = uri;
5161
+ triggerDeeplink(uri);
5130
5162
  return;
5131
5163
  } else {
5132
5164
  await authExecutor.executeSession(t);
@@ -5225,6 +5257,7 @@ function SwypePaymentInner({
5225
5257
  userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
5226
5258
  });
5227
5259
  if (isMobile) {
5260
+ handlingMobileReturnRef.current = false;
5228
5261
  mobileSetupFlowRef.current = true;
5229
5262
  const amount2 = depositAmount ?? 5;
5230
5263
  handlePay(amount2, { sourceType: "providerId", sourceId: providerId });