@volr/react-ui 0.1.80 → 0.1.82

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
@@ -2089,12 +2089,30 @@ function SiweLoginScreen({
2089
2089
  const [walletConnector, setWalletConnector] = React10.useState(
2090
2090
  void 0
2091
2091
  );
2092
+ const [hasWallet, setHasWallet] = React10.useState(null);
2093
+ const waitForEthereum = (timeout = 2e3, interval = 100) => {
2094
+ return new Promise((resolve) => {
2095
+ if (typeof window !== "undefined" && window.ethereum) {
2096
+ resolve(true);
2097
+ return;
2098
+ }
2099
+ const startTime = Date.now();
2100
+ const checkInterval = setInterval(() => {
2101
+ if (typeof window !== "undefined" && window.ethereum) {
2102
+ clearInterval(checkInterval);
2103
+ resolve(true);
2104
+ } else if (Date.now() - startTime >= timeout) {
2105
+ clearInterval(checkInterval);
2106
+ resolve(false);
2107
+ }
2108
+ }, interval);
2109
+ });
2110
+ };
2092
2111
  const detectWalletConnector = () => {
2093
2112
  if (typeof window === "undefined" || !window.ethereum) {
2094
2113
  return void 0;
2095
2114
  }
2096
2115
  const provider = window.ethereum;
2097
- console.log(provider.info);
2098
2116
  if (provider.info?.rdns) {
2099
2117
  return provider.info.rdns;
2100
2118
  }
@@ -2106,26 +2124,36 @@ function SiweLoginScreen({
2106
2124
  return "unknown";
2107
2125
  };
2108
2126
  React10.useEffect(() => {
2109
- if (typeof window !== "undefined" && window.ethereum) {
2110
- window.ethereum.request({ method: "eth_accounts" }).then((accounts) => {
2111
- if (accounts.length > 0) {
2112
- setAccount(accounts[0]);
2113
- setStep("sign");
2114
- setWalletConnector(detectWalletConnector());
2127
+ const initWallet = async () => {
2128
+ const walletAvailable = await waitForEthereum();
2129
+ setHasWallet(walletAvailable);
2130
+ if (walletAvailable && window.ethereum) {
2131
+ try {
2132
+ const accounts = await window.ethereum.request({
2133
+ method: "eth_accounts"
2134
+ });
2135
+ if (accounts.length > 0) {
2136
+ setAccount(accounts[0]);
2137
+ setStep("sign");
2138
+ setWalletConnector(detectWalletConnector());
2139
+ }
2140
+ } catch {
2115
2141
  }
2116
- }).catch(() => {
2117
- });
2118
- }
2142
+ }
2143
+ };
2144
+ initWallet();
2119
2145
  }, []);
2120
2146
  const handleConnectWallet = async () => {
2121
2147
  setError(null);
2122
2148
  setIsLoading(true);
2123
2149
  try {
2124
- if (typeof window === "undefined" || !window.ethereum) {
2150
+ const walletAvailable = await waitForEthereum(3e3, 100);
2151
+ if (!walletAvailable || !window.ethereum) {
2125
2152
  throw new Error(
2126
2153
  "No Ethereum wallet found. Please install MetaMask or another wallet."
2127
2154
  );
2128
2155
  }
2156
+ setHasWallet(true);
2129
2157
  const accounts = await window.ethereum.request({
2130
2158
  method: "eth_requestAccounts"
2131
2159
  });
@@ -2223,8 +2251,8 @@ Issued At: ${issuedAt}`;
2223
2251
  variant: "primary",
2224
2252
  fullWidth: true,
2225
2253
  onClick: handleConnectWallet,
2226
- disabled: isLoading,
2227
- children: isLoading ? t("common.loading") : t("login.wallet.connect")
2254
+ disabled: isLoading || hasWallet === null,
2255
+ children: isLoading || hasWallet === null ? t("common.loading") : t("login.wallet.connect")
2228
2256
  }
2229
2257
  ) : /* @__PURE__ */ jsxRuntime.jsx(
2230
2258
  Button,