@swype-org/react-sdk 0.1.10 → 0.1.11
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 +46 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +46 -2
- 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);
|
|
@@ -2150,6 +2172,27 @@ function SwypePayment({
|
|
|
2150
2172
|
setError("Transfer failed.");
|
|
2151
2173
|
}
|
|
2152
2174
|
}, [polling.transfer, onComplete]);
|
|
2175
|
+
useEffect(() => {
|
|
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]);
|
|
2153
2196
|
useEffect(() => {
|
|
2154
2197
|
if (!mobileFlow || !polling.isPolling) return;
|
|
2155
2198
|
const handleVisibility = () => {
|
|
@@ -2303,6 +2346,7 @@ function SwypePayment({
|
|
|
2303
2346
|
setAmount(depositAmount != null ? depositAmount.toString() : "");
|
|
2304
2347
|
setMobileFlow(false);
|
|
2305
2348
|
pollingTransferIdRef.current = null;
|
|
2349
|
+
mobileSigningTransferIdRef.current = null;
|
|
2306
2350
|
setConnectingNewAccount(false);
|
|
2307
2351
|
setSelectedWalletId(null);
|
|
2308
2352
|
setAdvancedSettings({ asset: null, chain: null });
|