connectButton
UI Component for Connecting to Plug Wallet
ConnectPlugButton.tsx
ConnectPlugButton.tsxProps
type Props = {
whitelist?: string[]; // List of canister IDs the wallet should authorize
host?: string; // Network host (e.g., "https://ic0.app" for ICP mainnet)
className?: string; // Optional CSS class for custom styling
};Logic
const plug = usePlug({ whitelist, host });const short = (p?: string) => (p ? `${p.slice(0, 5)}...${p.slice(-5)}` : "");if (!plug.available) { return <a href="https://plugwallet.ooo/">Install Plug</a>; }if (plug.connected) { return ( <div> Connected: {short(plug.principal)} <button onClick={plug.disconnect}>Disconnect</button> </div> ); }return ( <button onClick={() => plug.connect({ whitelist, host })}> Connect Plug </button> );
Last updated