@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.cjs
CHANGED
|
@@ -563,6 +563,27 @@ async function getWalletClient(config, parameters = {}) {
|
|
|
563
563
|
const client = await getConnectorClient(config, parameters);
|
|
564
564
|
return client.extend(viem.walletActions);
|
|
565
565
|
}
|
|
566
|
+
|
|
567
|
+
// src/passkeyRpId.ts
|
|
568
|
+
function normalizeConfiguredDomain(value) {
|
|
569
|
+
return value.replace(/^https?:\/\//, "").replace(/\/.*$/, "").replace(/^\./, "").trim();
|
|
570
|
+
}
|
|
571
|
+
function resolveRootDomainFromHostname(hostname) {
|
|
572
|
+
const trimmedHostname = hostname.trim().toLowerCase();
|
|
573
|
+
if (!trimmedHostname) {
|
|
574
|
+
return "localhost";
|
|
575
|
+
}
|
|
576
|
+
if (trimmedHostname === "localhost" || /^\d{1,3}(?:\.\d{1,3}){3}$/.test(trimmedHostname)) {
|
|
577
|
+
return trimmedHostname;
|
|
578
|
+
}
|
|
579
|
+
const parts = trimmedHostname.split(".").filter(Boolean);
|
|
580
|
+
if (parts.length < 2) {
|
|
581
|
+
return trimmedHostname;
|
|
582
|
+
}
|
|
583
|
+
return parts.slice(-2).join(".");
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// src/hooks.ts
|
|
566
587
|
var WALLET_CLIENT_MAX_ATTEMPTS = 15;
|
|
567
588
|
var WALLET_CLIENT_POLL_MS = 200;
|
|
568
589
|
var ACTION_POLL_INTERVAL_MS = 500;
|
|
@@ -613,10 +634,10 @@ function readEnvValue(name) {
|
|
|
613
634
|
function resolvePasskeyRpId() {
|
|
614
635
|
const configuredDomain = readEnvValue("VITE_DOMAIN") ?? readEnvValue("SWYPE_DOMAIN");
|
|
615
636
|
if (configuredDomain) {
|
|
616
|
-
return configuredDomain
|
|
637
|
+
return normalizeConfiguredDomain(configuredDomain);
|
|
617
638
|
}
|
|
618
639
|
if (typeof window !== "undefined") {
|
|
619
|
-
return window.location.hostname;
|
|
640
|
+
return resolveRootDomainFromHostname(window.location.hostname);
|
|
620
641
|
}
|
|
621
642
|
return "localhost";
|
|
622
643
|
}
|
|
@@ -2046,6 +2067,7 @@ function SwypePayment({
|
|
|
2046
2067
|
});
|
|
2047
2068
|
const [mobileFlow, setMobileFlow] = react.useState(false);
|
|
2048
2069
|
const pollingTransferIdRef = react.useRef(null);
|
|
2070
|
+
const mobileSigningTransferIdRef = react.useRef(null);
|
|
2049
2071
|
const [selectSourceChainName, setSelectSourceChainName] = react.useState("");
|
|
2050
2072
|
const [selectSourceTokenSymbol, setSelectSourceTokenSymbol] = react.useState("");
|
|
2051
2073
|
const initializedSelectSourceActionRef = react.useRef(null);
|
|
@@ -2153,6 +2175,27 @@ function SwypePayment({
|
|
|
2153
2175
|
setError("Transfer failed.");
|
|
2154
2176
|
}
|
|
2155
2177
|
}, [polling.transfer, onComplete]);
|
|
2178
|
+
react.useEffect(() => {
|
|
2179
|
+
if (!mobileFlow) return;
|
|
2180
|
+
const polledTransfer = polling.transfer;
|
|
2181
|
+
if (!polledTransfer) return;
|
|
2182
|
+
if (polledTransfer.status !== "AUTHORIZED") return;
|
|
2183
|
+
if (transferSigning.signing) return;
|
|
2184
|
+
if (mobileSigningTransferIdRef.current === polledTransfer.id) return;
|
|
2185
|
+
mobileSigningTransferIdRef.current = polledTransfer.id;
|
|
2186
|
+
const sign = async () => {
|
|
2187
|
+
try {
|
|
2188
|
+
const signedTransfer = await transferSigning.signTransfer(polledTransfer.id);
|
|
2189
|
+
setTransfer(signedTransfer);
|
|
2190
|
+
} catch (err) {
|
|
2191
|
+
mobileSigningTransferIdRef.current = null;
|
|
2192
|
+
const msg = err instanceof Error ? err.message : "Failed to sign transfer";
|
|
2193
|
+
setError(msg);
|
|
2194
|
+
onError?.(msg);
|
|
2195
|
+
}
|
|
2196
|
+
};
|
|
2197
|
+
void sign();
|
|
2198
|
+
}, [mobileFlow, polling.transfer, transferSigning, onError]);
|
|
2156
2199
|
react.useEffect(() => {
|
|
2157
2200
|
if (!mobileFlow || !polling.isPolling) return;
|
|
2158
2201
|
const handleVisibility = () => {
|
|
@@ -2306,6 +2349,7 @@ function SwypePayment({
|
|
|
2306
2349
|
setAmount(depositAmount != null ? depositAmount.toString() : "");
|
|
2307
2350
|
setMobileFlow(false);
|
|
2308
2351
|
pollingTransferIdRef.current = null;
|
|
2352
|
+
mobileSigningTransferIdRef.current = null;
|
|
2309
2353
|
setConnectingNewAccount(false);
|
|
2310
2354
|
setSelectedWalletId(null);
|
|
2311
2355
|
setAdvancedSettings({ asset: null, chain: null });
|