@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 +37 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +37 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1601,6 +1601,28 @@ function shouldUseWalletConnector(options) {
|
|
|
1601
1601
|
return options.useWalletConnector ?? !isMobileUserAgent(options.userAgent);
|
|
1602
1602
|
}
|
|
1603
1603
|
|
|
1604
|
+
// src/deeplink.ts
|
|
1605
|
+
var IFRAME_CLEANUP_DELAY_MS = 3e3;
|
|
1606
|
+
var LOCATION_FALLBACK_DELAY_MS = 100;
|
|
1607
|
+
function triggerDeeplink(uri) {
|
|
1608
|
+
try {
|
|
1609
|
+
const iframe = document.createElement("iframe");
|
|
1610
|
+
iframe.style.display = "none";
|
|
1611
|
+
iframe.src = uri;
|
|
1612
|
+
document.body.appendChild(iframe);
|
|
1613
|
+
setTimeout(() => {
|
|
1614
|
+
try {
|
|
1615
|
+
document.body.removeChild(iframe);
|
|
1616
|
+
} catch {
|
|
1617
|
+
}
|
|
1618
|
+
}, IFRAME_CLEANUP_DELAY_MS);
|
|
1619
|
+
} catch {
|
|
1620
|
+
}
|
|
1621
|
+
setTimeout(() => {
|
|
1622
|
+
window.location.href = uri;
|
|
1623
|
+
}, LOCATION_FALLBACK_DELAY_MS);
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1604
1626
|
// src/mobileFlow.ts
|
|
1605
1627
|
function hasActiveWallet(accounts) {
|
|
1606
1628
|
return accounts.some((account) => account.wallets.some((wallet) => wallet.status === "ACTIVE"));
|
|
@@ -4109,7 +4131,7 @@ function OpenWalletScreen({
|
|
|
4109
4131
|
useEffect(() => {
|
|
4110
4132
|
if (loading || !deeplinkUri || autoOpenedRef.current === deeplinkUri) return;
|
|
4111
4133
|
autoOpenedRef.current = deeplinkUri;
|
|
4112
|
-
|
|
4134
|
+
triggerDeeplink(deeplinkUri);
|
|
4113
4135
|
}, [loading, deeplinkUri]);
|
|
4114
4136
|
const handleOpen = useCallback(() => {
|
|
4115
4137
|
const opened = window.open(deeplinkUri, "_blank");
|
|
@@ -4510,6 +4532,7 @@ function SwypePaymentInner({
|
|
|
4510
4532
|
const pollingTransferIdRef = useRef(null);
|
|
4511
4533
|
const mobileSigningTransferIdRef = useRef(null);
|
|
4512
4534
|
const mobileSetupFlowRef = useRef(false);
|
|
4535
|
+
const handlingMobileReturnRef = useRef(false);
|
|
4513
4536
|
const processingStartedAtRef = useRef(null);
|
|
4514
4537
|
const [selectSourceChainName, setSelectSourceChainName] = useState("");
|
|
4515
4538
|
const [selectSourceTokenSymbol, setSelectSourceTokenSymbol] = useState("");
|
|
@@ -4552,6 +4575,8 @@ function SwypePaymentInner({
|
|
|
4552
4575
|
polling.startPolling(persisted.transferId);
|
|
4553
4576
|
}, [polling]);
|
|
4554
4577
|
const handleAuthorizedMobileReturn = useCallback(async (authorizedTransfer, isSetup) => {
|
|
4578
|
+
if (handlingMobileReturnRef.current) return;
|
|
4579
|
+
handlingMobileReturnRef.current = true;
|
|
4555
4580
|
polling.stopPolling();
|
|
4556
4581
|
if (isSetup) {
|
|
4557
4582
|
mobileSetupFlowRef.current = false;
|
|
@@ -4565,6 +4590,7 @@ function SwypePaymentInner({
|
|
|
4565
4590
|
setMobileFlow(false);
|
|
4566
4591
|
setStep("deposit");
|
|
4567
4592
|
} catch (err) {
|
|
4593
|
+
handlingMobileReturnRef.current = false;
|
|
4568
4594
|
setError(
|
|
4569
4595
|
err instanceof Error ? err.message : "Wallet authorized, but we could not refresh your account yet."
|
|
4570
4596
|
);
|
|
@@ -4582,6 +4608,7 @@ function SwypePaymentInner({
|
|
|
4582
4608
|
}, [polling.stopPolling, reloadAccounts, resetDataLoadingState]);
|
|
4583
4609
|
const handleRetryMobileStatus = useCallback(() => {
|
|
4584
4610
|
setError(null);
|
|
4611
|
+
handlingMobileReturnRef.current = false;
|
|
4585
4612
|
const currentTransfer = polling.transfer ?? transfer;
|
|
4586
4613
|
if (currentTransfer?.status === "AUTHORIZED") {
|
|
4587
4614
|
void handleAuthorizedMobileReturn(currentTransfer, mobileSetupFlowRef.current);
|
|
@@ -4927,18 +4954,23 @@ function SwypePaymentInner({
|
|
|
4927
4954
|
return () => window.clearTimeout(timeoutId);
|
|
4928
4955
|
}, [step, polling.transfer, transfer, polling.stopPolling, onError]);
|
|
4929
4956
|
useEffect(() => {
|
|
4930
|
-
if (!mobileFlow)
|
|
4957
|
+
if (!mobileFlow) {
|
|
4958
|
+
handlingMobileReturnRef.current = false;
|
|
4959
|
+
return;
|
|
4960
|
+
}
|
|
4961
|
+
if (handlingMobileReturnRef.current) return;
|
|
4931
4962
|
const polledTransfer = polling.transfer;
|
|
4932
4963
|
if (!polledTransfer || polledTransfer.status !== "AUTHORIZED") return;
|
|
4933
4964
|
void handleAuthorizedMobileReturn(polledTransfer, mobileSetupFlowRef.current);
|
|
4934
4965
|
}, [mobileFlow, polling.transfer, handleAuthorizedMobileReturn]);
|
|
4935
4966
|
useEffect(() => {
|
|
4936
4967
|
if (!mobileFlow) return;
|
|
4968
|
+
if (handlingMobileReturnRef.current) return;
|
|
4937
4969
|
const transferIdToResume = pollingTransferIdRef.current ?? transfer?.id;
|
|
4938
4970
|
if (!transferIdToResume) return;
|
|
4939
4971
|
if (!polling.isPolling) polling.startPolling(transferIdToResume);
|
|
4940
4972
|
const handleVisibility = () => {
|
|
4941
|
-
if (document.visibilityState === "visible") {
|
|
4973
|
+
if (document.visibilityState === "visible" && !handlingMobileReturnRef.current) {
|
|
4942
4974
|
polling.startPolling(transferIdToResume);
|
|
4943
4975
|
}
|
|
4944
4976
|
};
|
|
@@ -5123,7 +5155,7 @@ function SwypePaymentInner({
|
|
|
5123
5155
|
providerId: sourceOverrides?.sourceType === "providerId" ? sourceOverrides.sourceId : selectedProviderId,
|
|
5124
5156
|
isSetup: mobileSetupFlowRef.current
|
|
5125
5157
|
});
|
|
5126
|
-
|
|
5158
|
+
triggerDeeplink(uri);
|
|
5127
5159
|
return;
|
|
5128
5160
|
} else {
|
|
5129
5161
|
await authExecutor.executeSession(t);
|
|
@@ -5222,6 +5254,7 @@ function SwypePaymentInner({
|
|
|
5222
5254
|
userAgent: typeof navigator === "undefined" ? void 0 : navigator.userAgent
|
|
5223
5255
|
});
|
|
5224
5256
|
if (isMobile) {
|
|
5257
|
+
handlingMobileReturnRef.current = false;
|
|
5225
5258
|
mobileSetupFlowRef.current = true;
|
|
5226
5259
|
const amount2 = depositAmount ?? 5;
|
|
5227
5260
|
handlePay(amount2, { sourceType: "providerId", sourceId: providerId });
|