diff --git a/p2p-safe-swap/frontend/components/chat/chat-header.tsx b/p2p-safe-swap/frontend/components/chat/chat-header.tsx new file mode 100644 index 0000000..82ea0bb --- /dev/null +++ b/p2p-safe-swap/frontend/components/chat/chat-header.tsx @@ -0,0 +1,158 @@ +"use client"; + +import { useCallback, useState } from "react"; +import { cn } from "@/lib/utils"; +import { WalletBadge } from "@/frontend/components/ui/wallet-badge"; +import { truncateAddress } from "./utils"; + +export interface ChatHeaderProps { + counterpartAddress: string; + isOnline?: boolean; + onBack?: () => void; + onMore?: () => void; + className?: string; +} + +export function ChatHeader({ + counterpartAddress, + isOnline = true, + onBack, + onMore, + className, +}: ChatHeaderProps) { + const [copied, setCopied] = useState(false); + const truncated = truncateAddress(counterpartAddress); + + const handleCopy = useCallback(async () => { + if (typeof navigator === "undefined" || !navigator.clipboard) return; + try { + await navigator.clipboard.writeText(counterpartAddress); + setCopied(true); + window.setTimeout(() => setCopied(false), 1500); + } catch { + setCopied(false); + } + }, [counterpartAddress]); + + return ( +
+ {onBack ? ( + + ) : null} + + + +
+ + {truncated} + + + +
+ + + + +
+ ); +} diff --git a/p2p-safe-swap/frontend/components/chat/chat-input-bar.tsx b/p2p-safe-swap/frontend/components/chat/chat-input-bar.tsx new file mode 100644 index 0000000..01ed05b --- /dev/null +++ b/p2p-safe-swap/frontend/components/chat/chat-input-bar.tsx @@ -0,0 +1,92 @@ +"use client"; + +import { useState, type FormEvent, type KeyboardEvent } from "react"; +import { cn } from "@/lib/utils"; +import { Button } from "@/frontend/components/ui/Button/Button"; + +export interface ChatInputBarProps { + onSendMessage: (text: string) => void; + onSendPayment: () => void; + placeholder?: string; + disabled?: boolean; + className?: string; +} + +export function ChatInputBar({ + onSendMessage, + onSendPayment, + placeholder = "Escribe un mensaje…", + disabled = false, + className, +}: ChatInputBarProps) { + const [text, setText] = useState(""); + + const submit = () => { + const trimmed = text.trim(); + if (!trimmed || disabled) return; + onSendMessage(trimmed); + setText(""); + }; + + const handleSubmit = (event: FormEvent) => { + event.preventDefault(); + submit(); + }; + + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key === "Enter" && !event.shiftKey) { + event.preventDefault(); + submit(); + } + }; + + const canSend = text.trim().length > 0 && !disabled; + + return ( +
+