import { type ReactElement } from 'react'; import { BaseError, UserRejectedRequestError } from 'viem'; /** * Renders an error object in a user-friendly format. * * This utility function takes an error object and renders it as a React element * with consistent styling. It handles different types of errors including: * - Error objects with message properties * - Objects with error properties * - String errors * - Unknown error types * - User rejection errors (special handling for wallet rejections) * * The rendered error is displayed in a gray container with monospace font * for better readability of technical error details. User rejections are * displayed with a simpler, more user-friendly message. * * @param error - The error object to render * @returns ReactElement - A styled error display component, or null if no error * * @example * ```tsx * {isError && renderError(error)} * ``` */ export function renderError(error: unknown): ReactElement | null { // Handle null/undefined errors if (!error) return null; // Special handling for user rejections in wallet operations if (error instanceof BaseError) { const isUserRejection = error.walk( e => e instanceof UserRejectedRequestError ); if (isUserRejection) { return (