@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 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.replace(/^https?:\/\//, "").replace(/\/.*$/, "").replace(/^\./, "").trim();
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);
@@ -2154,19 +2176,43 @@ function SwypePayment({
2154
2176
  }
2155
2177
  }, [polling.transfer, onComplete]);
2156
2178
  react.useEffect(() => {
2157
- if (!mobileFlow || !polling.isPolling) return;
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]);
2199
+ react.useEffect(() => {
2200
+ if (!mobileFlow) return;
2201
+ const transferIdToResume = pollingTransferIdRef.current ?? transfer?.id;
2202
+ if (!transferIdToResume) return;
2203
+ if (!polling.isPolling) {
2204
+ polling.startPolling(transferIdToResume);
2205
+ }
2158
2206
  const handleVisibility = () => {
2159
2207
  if (document.visibilityState === "visible") {
2160
- if (pollingTransferIdRef.current) {
2161
- polling.startPolling(pollingTransferIdRef.current);
2162
- }
2208
+ polling.startPolling(transferIdToResume);
2163
2209
  }
2164
2210
  };
2165
2211
  document.addEventListener("visibilitychange", handleVisibility);
2166
2212
  return () => {
2167
2213
  document.removeEventListener("visibilitychange", handleVisibility);
2168
2214
  };
2169
- }, [mobileFlow, polling]);
2215
+ }, [mobileFlow, transfer?.id, polling.isPolling, polling.startPolling]);
2170
2216
  const pendingSelectSourceAction = authExecutor.pendingSelectSource;
2171
2217
  const selectSourceChoices = react.useMemo(() => {
2172
2218
  if (!pendingSelectSourceAction) return [];
@@ -2306,6 +2352,7 @@ function SwypePayment({
2306
2352
  setAmount(depositAmount != null ? depositAmount.toString() : "");
2307
2353
  setMobileFlow(false);
2308
2354
  pollingTransferIdRef.current = null;
2355
+ mobileSigningTransferIdRef.current = null;
2309
2356
  setConnectingNewAccount(false);
2310
2357
  setSelectedWalletId(null);
2311
2358
  setAdvancedSettings({ asset: null, chain: null });