From ee3168e6d2172b01c8bf266d4c8332a3cbeb27e2 Mon Sep 17 00:00:00 2001 From: utahkanz-ops <272119084+utahkanz-ops@users.noreply.github.com> Date: Tue, 2 Jun 2026 04:13:48 +0100 Subject: [PATCH 1/2] feat(ui): add wallet connect button to header - Added WalletContext to manage wallet connection state - Created WalletConnectButton component with connect, disconnect, and copy functionality - Integrated WalletConnectButton into layout.tsx header - Updated ActionPanel to gate milestone, dispute, and release funds actions based on wallet state - Added tests for WalletConnectButton covering connected, disconnected, and error states - Added documentation for WalletConnectButton Closes #45 --- docs/components/WalletConnectButton.md | 38 +++++++ src/app/layout.tsx | 18 +++- src/components/ActionPanel.tsx | 22 +++- src/components/WalletConnectButton.tsx | 95 ++++++++++++++++ .../__tests__/WalletConnectButton.test.tsx | 102 ++++++++++++++++++ src/contexts/WalletContext.tsx | 52 +++++++++ 6 files changed, 322 insertions(+), 5 deletions(-) create mode 100644 docs/components/WalletConnectButton.md create mode 100644 src/components/WalletConnectButton.tsx create mode 100644 src/components/__tests__/WalletConnectButton.test.tsx create mode 100644 src/contexts/WalletContext.tsx diff --git a/docs/components/WalletConnectButton.md b/docs/components/WalletConnectButton.md new file mode 100644 index 0000000..8211d1b --- /dev/null +++ b/docs/components/WalletConnectButton.md @@ -0,0 +1,38 @@ +# WalletConnectButton + +The `WalletConnectButton` component provides a unified control for users to connect and manage their crypto wallet session within the TalentTrust application. + +## Location +`src/components/WalletConnectButton.tsx` + +## Usage + +```tsx +import { WalletConnectButton } from '@/components/WalletConnectButton'; + +export function Header() { + return ( +
+ +
+ ); +} +``` + +## Features +- **Global State Integration:** Uses `useWallet` context to ensure the connection state is shared across the app, such as gating actions in `ActionPanel`. +- **States:** + - **Disconnected:** Displays a prominent "Connect Wallet" button. + - **Connecting:** Displays a loading spinner and "Connecting..." text. Disables the button. + - **Error:** Displays a "Connection Error" message with a "Retry" link. + - **Connected:** Displays the truncated wallet address along with options to copy to clipboard or disconnect. +- **Accessibility:** Fully accessible with ARIA labels, semantic HTML, and proper focus states. Buttons are keyboard operable. +- **Responsiveness:** Works across mobile and desktop viewpoints. + +## Dependencies +- `lucide-react` (icons) or inline SVGs. +- `@/contexts/WalletContext` +- `@/lib/truncateAddress` + +## Testing +Tested with Jest and React Testing Library in `src/components/__tests__/WalletConnectButton.test.tsx`. Covers all UI states and interactions (click, copy, etc.). diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 1f1e6d2..083773a 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -9,6 +9,8 @@ export const metadata: Metadata = { import { PreferencesProvider } from '@/lib/preferences'; import { SettingsTrigger } from '@/components/settings/SettingsTrigger'; +import { WalletProvider } from '@/contexts/WalletContext'; +import { WalletConnectButton } from '@/components/WalletConnectButton'; export default function RootLayout({ children, @@ -20,8 +22,20 @@ export default function RootLayout({ - {children} - + +
+
+
+ TalentTrust +
+ +
+
+ {children} +
+
+ +
diff --git a/src/components/ActionPanel.tsx b/src/components/ActionPanel.tsx index 8cba46c..8c80a56 100644 --- a/src/components/ActionPanel.tsx +++ b/src/components/ActionPanel.tsx @@ -1,5 +1,7 @@ 'use client'; +import { useWallet } from '@/contexts/WalletContext'; + export type ActionPanelProps = { status: 'Active' | 'Completed' | 'Disputed' | 'Pending'; onSubmitMilestone?: () => void; @@ -29,12 +31,20 @@ const ActionPanel = ({ onViewSummary, }: ActionPanelProps) => { const actions = getActionButtons(status); + const { address } = useWallet(); + const isWalletConnected = !!address; + const noWalletMsg = 'Connect wallet to perform this action'; return (