diff --git a/app/Components/Metamask/DiscoverWalletProviders.tsx b/app/Components/Metamask/DiscoverWalletProviders.tsx index df776e6..b65052c 100644 --- a/app/Components/Metamask/DiscoverWalletProviders.tsx +++ b/app/Components/Metamask/DiscoverWalletProviders.tsx @@ -1,50 +1,126 @@ -import { useState, type SetStateAction } from 'react'; -import { useSyncProviders } from './useSyncProviders'; -import useAuth from '~/hooks/useAuth'; -// code from https://metamask.io/news/how-to-implement-eip-6963-support-in-your-web3-dapp +// ...existing code... +import React, { useState } from "react"; +import { useSyncProviders } from "./useSyncProviders"; +import useAuth from "~/hooks/useAuth"; +import type { EIP6963ProviderDetail } from "./EthereumProviderTypes"; +import { + Box, + Grid, + Card, + CardContent, + Avatar, + Typography, + Button, + Stack, + CircularProgress, + Alert, +} from "@mui/material"; -import type { - EIP6963ProviderDetail -} from "./EthereumProviderTypes"; +const shortAddress = (addr: string) => + addr.length > 12 ? `${addr.slice(0, 6)}...${addr.slice(-6)}` : addr; -export const DiscoverWalletProviders = () => { +export const DiscoverWalletProviders: React.FC = () => { const providers = useSyncProviders(); const { auth, setAuth } = useAuth(); + const [loadingUuid, setLoadingUuid] = useState(null); + const [error, setError] = useState(null); const handleConnect = async (providerWithInfo: EIP6963ProviderDetail) => { - const accounts = await providerWithInfo.provider.request({ method: 'eth_requestAccounts' }).catch(console.error); + setError(null); + setLoadingUuid(providerWithInfo.info.uuid); + try { + const accounts = await providerWithInfo.provider.request({ + method: "eth_requestAccounts", + }); - if (Array.isArray(accounts) && accounts.length > 0 && accounts[0]) { - setAuth({providerWithInfo: providerWithInfo, accounts: accounts}); + if (Array.isArray(accounts) && accounts.length > 0 && typeof accounts[0] === "string") { + setAuth({ providerWithInfo, accounts }); + } else { + setError("No accounts returned from wallet."); + } + } catch (err: any) { + console.error(err); + setError(err?.message ?? String(err)); + } finally { + setLoadingUuid(null); } }; return ( - <> -

Wallets Detected:

-
- {providers.length > 0 ? ( - providers.map((provider) => { - return ( - - ); - }) - ) : ( -
There are no announced providers.
- )} -
-
-

{auth.accounts.length > 0 ? 'Wallet Selected' : 'No Wallet Selected'}

- {auth.accounts.length > 0 && ( -
- {auth.providerWithInfo!.info.name} -
{auth.providerWithInfo!.info.name}
-
({auth.accounts[0]})
-
+ + + Wallets Detected + + + {error && ( + + {error} + )} - + + {providers.length === 0 ? ( + There are no announced providers. + ) : ( + + {providers.map((p) => ( + + + + + + + {p.info.name} + + + + + + + + + ))} + + )} + + + + {auth?.accounts?.length > 0 ? "Wallet Selected" : "No Wallet Selected"} + + + {auth?.accounts?.length > 0 && auth.providerWithInfo && ( + + + + + + {auth.providerWithInfo.info.name} + + {shortAddress(auth.accounts[0])} + + + + + + + )} + + ); -}; \ No newline at end of file +}; + +export default DiscoverWalletProviders; +// ...existing code... \ No newline at end of file diff --git a/app/Components/Metamask/NewDiscover.tsx b/app/Components/Metamask/NewDiscover.tsx deleted file mode 100644 index b65052c..0000000 --- a/app/Components/Metamask/NewDiscover.tsx +++ /dev/null @@ -1,126 +0,0 @@ -// ...existing code... -import React, { useState } from "react"; -import { useSyncProviders } from "./useSyncProviders"; -import useAuth from "~/hooks/useAuth"; -import type { EIP6963ProviderDetail } from "./EthereumProviderTypes"; -import { - Box, - Grid, - Card, - CardContent, - Avatar, - Typography, - Button, - Stack, - CircularProgress, - Alert, -} from "@mui/material"; - -const shortAddress = (addr: string) => - addr.length > 12 ? `${addr.slice(0, 6)}...${addr.slice(-6)}` : addr; - -export const DiscoverWalletProviders: React.FC = () => { - const providers = useSyncProviders(); - const { auth, setAuth } = useAuth(); - const [loadingUuid, setLoadingUuid] = useState(null); - const [error, setError] = useState(null); - - const handleConnect = async (providerWithInfo: EIP6963ProviderDetail) => { - setError(null); - setLoadingUuid(providerWithInfo.info.uuid); - try { - const accounts = await providerWithInfo.provider.request({ - method: "eth_requestAccounts", - }); - - if (Array.isArray(accounts) && accounts.length > 0 && typeof accounts[0] === "string") { - setAuth({ providerWithInfo, accounts }); - } else { - setError("No accounts returned from wallet."); - } - } catch (err: any) { - console.error(err); - setError(err?.message ?? String(err)); - } finally { - setLoadingUuid(null); - } - }; - - return ( - - - Wallets Detected - - - {error && ( - - {error} - - )} - - {providers.length === 0 ? ( - There are no announced providers. - ) : ( - - {providers.map((p) => ( - - - - - - - {p.info.name} - - - - - - - - - ))} - - )} - - - - {auth?.accounts?.length > 0 ? "Wallet Selected" : "No Wallet Selected"} - - - {auth?.accounts?.length > 0 && auth.providerWithInfo && ( - - - - - - {auth.providerWithInfo.info.name} - - {shortAddress(auth.accounts[0])} - - - - - - - )} - - - ); -}; - -export default DiscoverWalletProviders; -// ...existing code... \ No newline at end of file diff --git a/app/Components/ServerList.tsx b/app/Components/ServerList.tsx index b85241a..6b20ba6 100644 --- a/app/Components/ServerList.tsx +++ b/app/Components/ServerList.tsx @@ -36,7 +36,6 @@ function NodeItem({node}: {node: Node}) { } const disconnect = ({ip}: {ip: string}) => { - // TODO check code setRatingOpen(true); } @@ -51,12 +50,12 @@ function NodeItem({node}: {node: Node}) { } setSubmittingRating(true); try { - // await axios.post('http://' + node.ip + ":8080/rate", { - // rating: ratingValue, - // }, { - // headers: { "Content-Type": "application/json" } - // }); - // console.log('Rating submitted'); + await axios.post('http://' + node.ip + ":8080/rate", { + rating: ratingValue, + }, { + headers: { "Content-Type": "application/json" } + }); + console.log('Rating submitted'); } catch (err) { console.error('Failed to submit rating', err); } finally { diff --git a/app/routes/home.tsx b/app/routes/home.tsx index 53bcd66..cdc11b6 100644 --- a/app/routes/home.tsx +++ b/app/routes/home.tsx @@ -3,8 +3,8 @@ import type { Route } from "./+types/home"; export function meta({}: Route.MetaArgs) { return [ - { title: "New React Router App" }, - { name: "description", content: "Welcome to React Router!" }, + { title: "CLEARNET" }, + { name: "description", content: "Welcome to CLEARNET!" }, ]; } diff --git a/app/routes/wallets.tsx b/app/routes/wallets.tsx index 5a7ec66..d67ab79 100644 --- a/app/routes/wallets.tsx +++ b/app/routes/wallets.tsx @@ -1,10 +1,8 @@ import { DiscoverWalletProviders } from "~/Components/Metamask/DiscoverWalletProviders"; -import NewDiscover from "~/Components/Metamask/NewDiscover"; export default function Wallets() { return( - // - + ); } \ No newline at end of file diff --git a/public/favicon.ico b/public/favicon.ico index 5dbdfcd..2cff345 100644 Binary files a/public/favicon.ico and b/public/favicon.ico differ