| 1 | import { useEffect, useRef } from "react"; |
| 2 | import reactLogo from "./assets/react.svg"; |
| 3 | import viteLogo from "/vite.svg"; |
| 4 | import "./App.css"; |
| 5 | import "./components/connect-wallet"; |
| 6 | |
| 7 | function App() { |
| 8 | const walletRef = useRef<any>(null); |
| 9 | |
| 10 | // Example of using callbacks |
| 11 | useEffect(() => { |
| 12 | const walletElement = walletRef.current; |
| 13 | if (!walletElement) return; |
| 14 | |
| 15 | walletElement.onWalletConnected = (detail: any) => { |
| 16 | console.log("connected via callback: ", detail); |
| 17 | }; |
| 18 | |
| 19 | walletElement.onWalletDisconnected = () => { |
| 20 | console.log("disconnected via callback"); |
| 21 | }; |
| 22 | |
| 23 | walletElement.onWalletError = (detail: any) => { |
| 24 | console.log("error via callback: ", detail); |
| 25 | }; |
| 26 | }, []); |
| 27 | |
| 28 | return ( |
| 29 | <> |
| 30 | <div> |
| 31 | <a href="https://vite.dev" target="_blank"> |
| 32 | <img src={viteLogo} className="logo" alt="Vite logo" /> |
| 33 | </a> |
| 34 | <a href="https://react.dev" target="_blank"> |
| 35 | <img src={reactLogo} className="logo react" alt="React logo" /> |
| 36 | </a> |
| 37 | </div> |
| 38 | <h1>Vite + React</h1> |
| 39 | <div className="card"> |
| 40 | <connect-wallet chain-id="1" ref={walletRef}></connect-wallet> |
| 41 | </div> |
| 42 | <p className="read-the-docs"> |
| 43 | Click on the Vite and React logos to learn more |
| 44 | </p> |
| 45 | </> |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | export default App; |