{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "address-input",
  "title": "Address Input",
  "description": "Recipient input for an address or ENS name: debounced ENS resolution on mainnet (useEnsAddress) with avatar and resolved-address preview, reverse ENS name for pasted addresses, a hint line that morphs between 'Looking up…', the name and the address (MorphText), strict checksum validation that catches typos, a paste button, and errors shown after blur rather than while typing. onResolve returns { phase, address, ensName, error }. Exports useAddressInput. data-phase: empty | incomplete | resolving | valid | invalid | not-found. With the shielded prop it also accepts private 0zk addresses (Railgun format), validated by length and bech32m checksum and reported as state.shieldedAddress; they are never sent to a resolver.",
  "dependencies": [
    "wagmi",
    "viem",
    "lucide-react"
  ],
  "registryDependencies": [
    "@0xui/address-avatar",
    "@0xui/0xui-utils",
    "@0xui/morph-text"
  ],
  "files": [
    {
      "path": "registry/default/components/address-input.tsx",
      "content": "// Docs: https://0xui.io/components/address-input.md\nimport { ClipboardPasteIcon, EyeOffIcon, Loader2Icon } from \"lucide-react\";\nimport {\n  useEffect,\n  useId,\n  useState,\n  type ComponentProps,\n} from \"react\";\nimport { getAddress, isAddress, type Address } from \"viem\";\nimport { normalize } from \"viem/ens\";\nimport { useEnsAddress, useEnsName } from \"wagmi\";\nimport { mainnet } from \"wagmi/chains\";\nimport { AddressAvatar } from \"@/components/address-avatar\";\nimport { MorphText } from \"@/components/morph-text\";\nimport {\n  SHIELDED_ADDRESS_LENGTH,\n  SHIELDED_ADDRESS_PREFIX,\n  isShieldedAddress,\n  truncateAddress,\n} from \"@/lib/0xui-utils\";\nimport { cn } from \"@/lib/utils\";\n\nexport type AddressInputPhase =\n  | \"empty\"\n  | \"incomplete\"\n  | \"resolving\"\n  | \"valid\"\n  | \"invalid\"\n  | \"not-found\";\n\nexport type AddressInputState = {\n  phase: AddressInputPhase;\n  /** Checksummed address once the input is a valid address or a resolved ENS name. */\n  address: Address | undefined;\n  /** ENS name typed or found for the address. */\n  ensName: string | undefined;\n  /** The private (`0zk…`) address, when the input is one and `shielded` is on. `address` is then undefined. */\n  shieldedAddress: string | undefined;\n  /** Why the input is invalid, for display. */\n  error: string | undefined;\n};\n\nfunction useDebounced<T>(value: T, delay: number) {\n  const [debounced, setDebounced] = useState(value);\n  useEffect(() => {\n    const timer = setTimeout(() => setDebounced(value), delay);\n    return () => clearTimeout(timer);\n  }, [value, delay]);\n  return debounced;\n}\n\nfunction normalizeName(value: string) {\n  try {\n    return normalize(value);\n  } catch {\n    return undefined;\n  }\n}\n\n/**\n * Validate an address or resolve an ENS name (on mainnet). Lookups wait for\n * typing to pause. Mixed-case addresses must match their checksum. With\n * `shielded`, private `0zk…` addresses are accepted too and checked against\n * their own checksum; they are never sent to a resolver.\n */\nexport function useAddressInput(\n  value: string,\n  { debounce = 300, shielded = false }: { debounce?: number; shielded?: boolean } = {}\n) {\n  const text = value.trim();\n  const looksLikeAddress = /^0x[0-9a-fA-F]*$/.test(text);\n  // An ENS name may start with \"0zk\" too; a private address never has a dot.\n  const looksShielded =\n    text.toLowerCase().startsWith(SHIELDED_ADDRESS_PREFIX) && !text.includes(\".\");\n  const isName = !looksLikeAddress && !looksShielded && text.includes(\".\");\n  const name = isName ? normalizeName(text) : undefined;\n  const debouncedName = useDebounced(name, debounce);\n  const nameSettled = debouncedName === name;\n\n  const ens = useEnsAddress({\n    name: debouncedName,\n    chainId: mainnet.id,\n    query: { enabled: Boolean(debouncedName) },\n  });\n  const validAddress = looksLikeAddress && isAddress(text) ? getAddress(text) : undefined;\n  const reverse = useEnsName({\n    address: validAddress,\n    chainId: mainnet.id,\n    query: { enabled: Boolean(validAddress) },\n  });\n\n  const state = ((): AddressInputState => {\n    const base = {\n      address: undefined,\n      ensName: undefined,\n      shieldedAddress: undefined,\n      error: undefined,\n    };\n    if (!text) return { ...base, phase: \"empty\" };\n    if (looksShielded) {\n      if (!shielded)\n        return { ...base, phase: \"invalid\", error: \"Private (0zk) addresses can't be used here.\" };\n      if (isShieldedAddress(text)) return { ...base, phase: \"valid\", shieldedAddress: text };\n      if (text.length < SHIELDED_ADDRESS_LENGTH)\n        return {\n          ...base,\n          phase: \"incomplete\",\n          error: `Enter the full ${SHIELDED_ADDRESS_LENGTH}-character private address.`,\n        };\n      if (text.length > SHIELDED_ADDRESS_LENGTH)\n        return { ...base, phase: \"invalid\", error: \"Private address is too long.\" };\n      return {\n        ...base,\n        phase: \"invalid\",\n        error: \"Checksum doesn't match. Check the private address for typos.\",\n      };\n    }\n    if (looksLikeAddress) {\n      if (validAddress)\n        return { ...base, phase: \"valid\", address: validAddress, ensName: reverse.data ?? undefined };\n      if (text.length === 42)\n        return { ...base, phase: \"invalid\", error: \"Checksum doesn't match. Check the address for typos.\" };\n      if (text.length > 42) return { ...base, phase: \"invalid\", error: \"Address is too long.\" };\n      return { ...base, phase: \"incomplete\", error: \"Enter a full 42-character address.\" };\n    }\n    if (isName) {\n      if (!name) return { ...base, phase: \"invalid\", error: \"Not a valid ENS name.\" };\n      if (!nameSettled || ens.isPending) return { ...base, phase: \"resolving\", ensName: name };\n      if (ens.isError) return { ...base, phase: \"invalid\", ensName: name, error: \"Couldn't look up this name. Try again.\" };\n      if (!ens.data) return { ...base, phase: \"not-found\", ensName: name, error: `No address found for ${name}.` };\n      return { ...base, phase: \"valid\", address: ens.data, ensName: name };\n    }\n    return {\n      ...base,\n      phase: \"incomplete\",\n      error: shielded\n        ? \"Enter an address (0x…), an ENS name or a private address (0zk…).\"\n        : \"Enter an address (0x…) or ENS name.\",\n    };\n  })();\n\n  return state;\n}\n\nexport type AddressInputProps = Omit<\n  ComponentProps<\"input\">,\n  \"value\" | \"onChange\" | \"type\"\n> & {\n  value: string;\n  /** Called with the text on every change. */\n  onValueChange: (value: string) => void;\n  /** Called when validation settles on a new result, e.g. an ENS name resolved. Use `state.address` as the recipient. */\n  onResolve?: (state: AddressInputState) => void;\n  /** Accessible label. Defaults to \"Recipient\". */\n  label?: string;\n  /** Show a paste button while the input is empty. */\n  showPaste?: boolean;\n  /** Also accept private `0zk…` addresses. The result is then in `state.shieldedAddress`. */\n  shielded?: boolean;\n};\n\n/**\n * Recipient input: takes an address or an ENS name, resolves names as you\n * type, shows the avatar and resolved address, and catches checksum typos.\n * Problems show after the field loses focus, not while typing.\n */\nexport function AddressInput({\n  value,\n  onValueChange,\n  onResolve,\n  label = \"Recipient\",\n  showPaste = true,\n  shielded = false,\n  placeholder = shielded ? \"Address, ENS name or 0zk address\" : \"Address or ENS name\",\n  className,\n  id,\n  onBlur,\n  ...props\n}: AddressInputProps) {\n  const fallbackId = useId();\n  const inputId = id ?? fallbackId;\n  const messageId = `${inputId}-message`;\n  const [touched, setTouched] = useState(false);\n  const state = useAddressInput(value, { shielded });\n\n  // Report each new validation result, including async ENS resolution.\n  useEffect(() => {\n    onResolve?.(state);\n    // Fire on result changes only, not when the caller passes a new callback.\n  }, [state.phase, state.address, state.ensName, state.shieldedAddress]);\n\n  const showError =\n    state.error !== undefined &&\n    (state.phase === \"not-found\" || (touched && state.phase !== \"resolving\"));\n\n  const message =\n    state.shieldedAddress\n      ? // Start and end, so a pasted address can be checked against its source.\n        `Private address ${truncateAddress(state.shieldedAddress, { start: 9, end: 6 })}`\n      : state.phase === \"valid\" && state.ensName && value.includes(\".\")\n      ? truncateAddress(state.address!)\n      : state.phase === \"valid\" && state.ensName\n        ? state.ensName\n        : state.phase === \"resolving\"\n          ? `Looking up ${state.ensName}…`\n          : showError\n            ? state.error\n            : undefined;\n\n  return (\n    <div\n      data-slot=\"address-input\"\n      data-phase={state.phase}\n      className={cn(\"flex flex-col gap-1.5\", className)}\n    >\n      <div\n        className={cn(\n          \"flex h-11 items-center gap-2 rounded-lg border bg-background px-3 focus-within:ring-3 focus-within:ring-ring/50\",\n          showError && \"border-destructive\"\n        )}\n      >\n        {state.address && <AddressAvatar address={state.address} size={22} />}\n        {state.shieldedAddress && (\n          <EyeOffIcon aria-hidden className=\"size-4 shrink-0 text-muted-foreground\" />\n        )}\n        <input\n          id={inputId}\n          type=\"text\"\n          autoComplete=\"off\"\n          autoCorrect=\"off\"\n          autoCapitalize=\"off\"\n          spellCheck={false}\n          aria-label={label}\n          aria-invalid={showError || undefined}\n          aria-describedby={message ? messageId : undefined}\n          placeholder={placeholder}\n          value={value}\n          onChange={(e) => {\n            onValueChange(e.target.value);\n            if (touched) setTouched(false);\n          }}\n          onBlur={(e) => {\n            setTouched(true);\n            onBlur?.(e);\n          }}\n          className=\"h-full min-w-0 flex-1 bg-transparent font-mono text-sm outline-none placeholder:font-sans\"\n          {...props}\n        />\n        {state.phase === \"resolving\" && (\n          <Loader2Icon aria-hidden className=\"size-4 shrink-0 animate-spin text-muted-foreground\" />\n        )}\n        {showPaste && !value && (\n          <button\n            type=\"button\"\n            aria-label=\"Paste address\"\n            onClick={async () => {\n              try {\n                const text = (await navigator.clipboard.readText()).trim();\n                onValueChange(text);\n                setTouched(true);\n              } catch {\n                // Clipboard read denied: the user can still paste with the keyboard.\n              }\n            }}\n            className=\"shrink-0 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground\"\n          >\n            <ClipboardPasteIcon className=\"size-4\" />\n          </button>\n        )}\n      </div>\n      <p\n        id={messageId}\n        role={showError ? \"alert\" : \"status\"}\n        className={cn(\n          \"min-h-5 text-sm\",\n          showError ? \"text-destructive\" : \"text-muted-foreground\",\n          state.phase === \"valid\" && value.includes(\".\") && \"font-mono\"\n        )}\n      >\n        {/* The hint morphs: \"Looking up name…\" into the address, or a name\n            appearing for a pasted address. Errors are announced as-is. */}\n        {showError ? message : <MorphText>{message}</MorphText>}\n      </p>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Docs: https://0xui.io/components/address-input.md",
  "categories": [
    "identity"
  ],
  "type": "registry:component"
}