Hook for managing the currently selected wallet
The useWalletState
hook provides methods to get and set the currently selected wallet, which is used as the default for signing operations.
import { useWalletState } from "@getpara/react-sdk@alpha";
function WalletSelector() {
const { selectedWallet, setSelectedWallet, updateSelectedWallet } = useWalletState();
const { data: account } = useAccount();
const handleWalletChange = (walletId: string, walletType: TWalletType) => {
setSelectedWallet({ id: walletId, type: walletType });
};
return (
<div>
<p>Current Wallet ID: {selectedWallet.id || "None"}</p>
<p>Current Wallet Type: {selectedWallet.type || "None"}</p>
{account?.wallets.map((wallet) => (
<button
key={wallet.id}
onClick={() => handleWalletChange(wallet.id, wallet.type)}
style={{
fontWeight: selectedWallet.id === wallet.id ? "bold" : "normal"
}}
>
Select {wallet.type} Wallet
</button>
))}
</div>
);
}