The useWalletState hook provides methods to get and set the currently selected wallet, which is used as the default for signing operations.

Import

import { useWalletState } from "@getpara/react-sdk@alpha";

Usage

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>
  );
}