npx create-react-app aleo_dapp
cd aleo_dapp
import { useMemo } from "react";
import { WalletProvider, useConnect, useDisconnect } from "aleo-hooks";
import {
LeoWalletAdapter,
LeoWalletName,
} from "@demox-labs/aleo-wallet-adapter-leo";
import "./App.css";
function App() {
const wallets = useMemo(
() => [new LeoWalletAdapter({ appName: "Create React App" })],
[]
);
return (
<wallets={wallets} autoConnect>
<div className="App">
<UseConnect></UseConnect>
</div>
</WalletProvider>
);
}
export const UseConnect = () => {
const connectHandler = () => connect(LeoWalletName);
const disconnectHandler = () => disconnect();
const { connect, connected, connecting, address } = useConnect();
const { disconnect, disconnecting } = useDisconnect();
return (
<div>
{connected ? (
<>
<p>Successfuly connected {address}</p>
<button disabled={disconnecting} onClick={disconnect}>
Disconnect
</button>
</>
) : (
<>
<p>The wallet is disconnected</p>
<button disabled={connecting} onClick={connectHandler}>
Connect Leo wallet
</button>
</>
)}{" "}
</div>
);
};
export default App;
This code will create a blank page with a Connect/Disconnect button for Leo Wallet.