Use WalletContext with React's useContext hook to access the current wallet state and control connection methods.
Available properties and methods:
wallet: Information about the connected wallet.accounts: Array of connected accounts.connectWallet(): Method to initiate wallet connection.disconnectWallet(): Method to disconnect the current wallet.evmWallet: Information about connected EVM wallets.walletType: The type of the connected wallet.
import { useContext } from 'react';
import { WalletContext } from '@bagpipes/wallet';
function AccountInfo() {
const { wallet, accounts, disconnectWallet } = useContext(WalletContext);
if (!wallet) {
return <p>No wallet connected</p>;
}
return (
<div>
<h2>Connected Wallet: {wallet.title}</h2>
<h3>Accounts:</h3>
{accounts.map((account) => (
<p key={account.address}>{account.address}</p>
))}
<button onClick={disconnectWallet}>Disconnect</button>
</div>
);
}