BigBlocks

Connect Wallet

A themed wallet connection button that handles detecting, connecting, and disconnecting BSV wallets via @1sat/react

Compact

Installation

bunx shadcn@latest add https://registry.bigblocks.dev/r/connect-wallet.json

Usage

The block must be rendered inside both WalletProvider and ConnectDialogProvider from @1sat/react. Place the providers once in your root layout.

import { WalletProvider, ConnectDialogProvider } from "@1sat/react"
import { ConnectWallet } from "@/components/blocks/connect-wallet"
 
function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <WalletProvider>
      <ConnectDialogProvider>
        {children}
      </ConnectDialogProvider>
    </WalletProvider>
  )
}
 
// Then anywhere in your app:
export function Header() {
  return (
    <header className="flex items-center justify-between p-4">
      <span>My App</span>
      <ConnectWallet
        onConnect={() => console.log("connected")}
        onDisconnect={() => console.log("disconnected")}
      />
    </header>
  )
}

Variants

Default

A full-width button showing the wallet icon and label when disconnected, and a gradient avatar with the truncated identity key when connected.

<ConnectWallet variant="default" connectLabel="Connect Wallet" />

Compact

An icon-only square button. Useful for tight navigation bars.

<ConnectWallet variant="compact" />

Outline

A smaller outlined button with reduced padding. Suitable for secondary placements.

<ConnectWallet variant="outline" />

Connection States

The button renders differently based on the wallet status from @1sat/react:

StatusRendered UI
disconnectedConnect button
detectingDisabled spinner button
connectingDisabled spinner button
selectingConnect button + wallet provider dialog
connectedDropdown with identity key, copy action, and disconnect

Props

ConnectWallet

PropTypeDefaultDescription
variant"default" | "compact" | "outline""default"Visual style of the button
classNamestringAdditional CSS classes applied to the trigger element
connectLabelstring"Connect Wallet"Label shown on the connect button and used as aria-label for the compact variant
onConnect() => voidCalled after a wallet connection succeeds
onDisconnect() => voidCalled after the wallet is disconnected
onError(error: Error) => voidCalled when a connection error occurs

Hook

useConnectWallet can be used independently if you want to build a custom connection UI.

import { useConnectWallet } from "@/components/blocks/connect-wallet"
 
function CustomTrigger() {
  const {
    status,
    identityKey,
    truncatedKey,
    gradient,
    handleTriggerClick,
    handleDisconnect,
    handleCopy,
    copied,
    error,
  } = useConnectWallet({
    onConnect: () => console.log("connected"),
    onDisconnect: () => console.log("disconnected"),
  })
 
  if (status === "connected" && identityKey) {
    return (
      <button onClick={handleDisconnect} style={{ background: gradient }}>
        {truncatedKey}
      </button>
    )
  }
 
  return <button onClick={handleTriggerClick}>Connect</button>
}

useConnectWallet Options

OptionTypeDefaultDescription
variant"default" | "compact" | "outline" | null"default"Used to compute isCompact in the return value
onConnect() => voidCalled after successful connection
onDisconnect() => voidCalled after disconnection
onError(error: Error) => voidCalled when a connection error occurs

useConnectWallet Return

PropertyTypeDescription
statusstringCurrent wallet status from @1sat/react
identityKeystring | undefinedIdentity key when connected
dialogOpenbooleanWhether the provider selection dialog is open
setDialogOpen(open: boolean) => voidControl the dialog open state
isCompactbooleantrue when variant === "compact"
gradientstringDeterministic CSS gradient derived from the identity key
truncatedKeystringIdentity key truncated for display (e.g. abc123...xyz9)
handleConnect() => Promise<void>Initiate wallet connection
handleDisconnect() => voidDisconnect the wallet
handleTriggerClick() => voidClick handler for the connect trigger button
handleCopy() => voidCopy the identity key to the clipboard
copiedbooleantrue for 2 seconds after a successful copy
errorError | nullLast error from the wallet provider