@swype-org/react-sdk 0.1.10 → 0.1.12
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 +54 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +54 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -560,6 +560,27 @@ async function getWalletClient(config, parameters = {}) {
|
|
|
560
560
|
const client = await getConnectorClient(config, parameters);
|
|
561
561
|
return client.extend(walletActions);
|
|
562
562
|
}
|
|
563
|
+
|
|
564
|
+
// src/passkeyRpId.ts
|
|
565
|
+
function normalizeConfiguredDomain(value) {
|
|
566
|
+
return value.replace(/^https?:\/\//, "").replace(/\/.*$/, "").replace(/^\./, "").trim();
|
|
567
|
+
}
|
|
568
|
+
function resolveRootDomainFromHostname(hostname) {
|
|
569
|
+
const trimmedHostname = hostname.trim().toLowerCase();
|
|
570
|
+
if (!trimmedHostname) {
|
|
571
|
+
return "localhost";
|
|
572
|
+
}
|
|
573
|
+
if (trimmedHostname === "localhost" || /^\d{1,3}(?:\.\d{1,3}){3}$/.test(trimmedHostname)) {
|
|
574
|
+
return trimmedHostname;
|
|
575
|
+
}
|
|
576
|
+
const parts = trimmedHostname.split(".").filter(Boolean);
|
|
577
|
+
if (parts.length < 2) {
|
|
578
|
+
return trimmedHostname;
|
|
579
|
+
}
|
|
580
|
+
return parts.slice(-2).join(".");
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// src/hooks.ts
|
|
563
584
|
var WALLET_CLIENT_MAX_ATTEMPTS = 15;
|
|
564
585
|
var WALLET_CLIENT_POLL_MS = 200;
|
|
565
586
|
var ACTION_POLL_INTERVAL_MS = 500;
|
|
@@ -610,10 +631,10 @@ function readEnvValue(name) {
|
|
|
610
631
|
function resolvePasskeyRpId() {
|
|
611
632
|
const configuredDomain = readEnvValue("VITE_DOMAIN") ?? readEnvValue("SWYPE_DOMAIN");
|
|
612
633
|
if (configuredDomain) {
|
|
613
|
-
return configuredDomain
|
|
634
|
+
return normalizeConfiguredDomain(configuredDomain);
|
|
614
635
|
}
|
|
615
636
|
if (typeof window !== "undefined") {
|
|
616
|
-
return window.location.hostname;
|
|
637
|
+
return resolveRootDomainFromHostname(window.location.hostname);
|
|
617
638
|
}
|
|
618
639
|
return "localhost";
|
|
619
640
|
}
|
|
@@ -2043,6 +2064,7 @@ function SwypePayment({
|
|
|
2043
2064
|
});
|
|
2044
2065
|
const [mobileFlow, setMobileFlow] = useState(false);
|
|
2045
2066
|
const pollingTransferIdRef = useRef(null);
|
|
2067
|
+
const mobileSigningTransferIdRef = useRef(null);
|
|
2046
2068
|
const [selectSourceChainName, setSelectSourceChainName] = useState("");
|
|
2047
2069
|
const [selectSourceTokenSymbol, setSelectSourceTokenSymbol] = useState("");
|
|
2048
2070
|
const initializedSelectSourceActionRef = useRef(null);
|
|
@@ -2151,19 +2173,43 @@ function SwypePayment({
|
|
|
2151
2173
|
}
|
|
2152
2174
|
}, [polling.transfer, onComplete]);
|
|
2153
2175
|
useEffect(() => {
|
|
2154
|
-
if (!mobileFlow
|
|
2176
|
+
if (!mobileFlow) return;
|
|
2177
|
+
const polledTransfer = polling.transfer;
|
|
2178
|
+
if (!polledTransfer) return;
|
|
2179
|
+
if (polledTransfer.status !== "AUTHORIZED") return;
|
|
2180
|
+
if (transferSigning.signing) return;
|
|
2181
|
+
if (mobileSigningTransferIdRef.current === polledTransfer.id) return;
|
|
2182
|
+
mobileSigningTransferIdRef.current = polledTransfer.id;
|
|
2183
|
+
const sign = async () => {
|
|
2184
|
+
try {
|
|
2185
|
+
const signedTransfer = await transferSigning.signTransfer(polledTransfer.id);
|
|
2186
|
+
setTransfer(signedTransfer);
|
|
2187
|
+
} catch (err) {
|
|
2188
|
+
mobileSigningTransferIdRef.current = null;
|
|
2189
|
+
const msg = err instanceof Error ? err.message : "Failed to sign transfer";
|
|
2190
|
+
setError(msg);
|
|
2191
|
+
onError?.(msg);
|
|
2192
|
+
}
|
|
2193
|
+
};
|
|
2194
|
+
void sign();
|
|
2195
|
+
}, [mobileFlow, polling.transfer, transferSigning, onError]);
|
|
2196
|
+
useEffect(() => {
|
|
2197
|
+
if (!mobileFlow) return;
|
|
2198
|
+
const transferIdToResume = pollingTransferIdRef.current ?? transfer?.id;
|
|
2199
|
+
if (!transferIdToResume) return;
|
|
2200
|
+
if (!polling.isPolling) {
|
|
2201
|
+
polling.startPolling(transferIdToResume);
|
|
2202
|
+
}
|
|
2155
2203
|
const handleVisibility = () => {
|
|
2156
2204
|
if (document.visibilityState === "visible") {
|
|
2157
|
-
|
|
2158
|
-
polling.startPolling(pollingTransferIdRef.current);
|
|
2159
|
-
}
|
|
2205
|
+
polling.startPolling(transferIdToResume);
|
|
2160
2206
|
}
|
|
2161
2207
|
};
|
|
2162
2208
|
document.addEventListener("visibilitychange", handleVisibility);
|
|
2163
2209
|
return () => {
|
|
2164
2210
|
document.removeEventListener("visibilitychange", handleVisibility);
|
|
2165
2211
|
};
|
|
2166
|
-
}, [mobileFlow, polling]);
|
|
2212
|
+
}, [mobileFlow, transfer?.id, polling.isPolling, polling.startPolling]);
|
|
2167
2213
|
const pendingSelectSourceAction = authExecutor.pendingSelectSource;
|
|
2168
2214
|
const selectSourceChoices = useMemo(() => {
|
|
2169
2215
|
if (!pendingSelectSourceAction) return [];
|
|
@@ -2303,6 +2349,7 @@ function SwypePayment({
|
|
|
2303
2349
|
setAmount(depositAmount != null ? depositAmount.toString() : "");
|
|
2304
2350
|
setMobileFlow(false);
|
|
2305
2351
|
pollingTransferIdRef.current = null;
|
|
2352
|
+
mobileSigningTransferIdRef.current = null;
|
|
2306
2353
|
setConnectingNewAccount(false);
|
|
2307
2354
|
setSelectedWalletId(null);
|
|
2308
2355
|
setAdvancedSettings({ asset: null, chain: null });
|