diff --git a/client/src/App.js b/client/src/App.js index 79b3020..6c14d8b 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -1,13 +1,46 @@ import "./App.css"; +import {} from "ethers"; +import { useEffect, useState } from "react"; +import { withEth } from "./lib/eth"; function App() { + const [currentAccount, setCurrentAccount] = useState(""); + + const checkIfWalletConnected = withEth(async (ethereum) => { + const accounts = await ethereum.request({ method: "eth_accounts" }); + if (accounts.length !== 0) { + console.log(`Found authorized account ${accounts[0]}`); + setCurrentAccount(accounts[0]); + } + }); + + const connectWallet = withEth(async (ethereum) => { + const accounts = await ethereum.request({ method: "eth_requestAccounts" }); + console.log(`connected to ${accounts[0]}`); + setCurrentAccount(accounts[0]); + }); + + const mintNFT = withEth(async (ethereum) => {}); + + useEffect(() => { + checkIfWalletConnected(); + }, []); + return (

EpicNFTs Collection

Each unique. Each beautiful. Discover your NFT today.

- + {currentAccount ? ( + + ) : ( + + )}
diff --git a/client/src/index.js b/client/src/index.js index 046fc88..37074f2 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -3,13 +3,10 @@ import ReactDOM from "react-dom"; import reportWebVitals from "./reportWebVitals"; import App from "./App"; import "./index.css"; -import { MantineProvider } from "@mantine/core"; ReactDOM.render( - - - + , document.getElementById("root") ); diff --git a/client/src/lib/eth.js b/client/src/lib/eth.js new file mode 100644 index 0000000..630e391 --- /dev/null +++ b/client/src/lib/eth.js @@ -0,0 +1,16 @@ +const getEth = () => { + const { ethereum } = window; + if (!ethereum) { + alert("Wallet not detected. Make sure you have Metamask extension installed and activated."); + } + return ethereum; +}; + +export const withEth = (f) => async (props) => { + try { + const ethereum = getEth(); + await f(ethereum, props); + } catch (error) { + console.error(error); + } +};