Skip to content

feat(wallet): integrate @stellar/freighter-api with network switching & connection management#71

Merged
meshackyaro merged 1 commit into
trustflow-protocol:mainfrom
Topmatrixmor2014:feat/freighter-wallet-integration-21
Jul 21, 2026
Merged

feat(wallet): integrate @stellar/freighter-api with network switching & connection management#71
meshackyaro merged 1 commit into
trustflow-protocol:mainfrom
Topmatrixmor2014:feat/freighter-wallet-integration-21

Conversation

@Topmatrixmor2014

Copy link
Copy Markdown
Contributor

Summary

This PR completes the Freighter wallet integration by implementing a robust connection lifecycle, network detection, and reusable shared UI components. The core objective — "Add a Connect Wallet button in the navbar that handles network switching and connection" — is now fully addressed.


Changes Made

1. New useWallet Hook (hooks/useWallet.ts) 📦

A comprehensive hook that manages the full Freighter connection lifecycle:

Feature Details
Connection detection Polls isConnected() + getUserInfo() + isAllowed() every 2s
Network detection Calls getNetworkDetails() to display testnet/mainnet/futurenet
connect() Resets disconnect flag and syncs state (the ConnectButton calls setAllowed() directly)
disconnect() Sets a ref-based flag so polling yields to the UI while avoiding spurious reconnects
Error resilience Each API call is wrapped in its own try/catch so a single failure doesn't cascade
Loading/error state isBusy and error fields for UI feedback

2. Backward Compatible useAccount (hooks/useAccount.ts) 🔄

  • Now delegates to useWallet() internally and returns account only
  • No breaking changes to 5+ existing consumers

3. Enhanced ConnectButton 🎯

  • Loading spinner while connecting
  • Inline error text if the connection fails
  • onConnect callback for parent sync
  • Disabled state to prevent double-clicks

4. Enhanced WalletButton 💳

  • Network badge in dropdown (Testnet/Mainnet/Futurenet)
  • Chevron icon that rotates on open
  • i18n support via props

5. Updated Navbar 🧭

  • Removed local disconnected state — managed by useWallet
  • Passes network info to WalletButton
  • Uses i18n for wallet strings

6. Shared DashboardSidebar Component 📊

  • Extracted from 4 duplicated pages
  • Bottom card shows actual connected account via useAccount()

7. i18n Updates 🌐

New Wallet section with 8 localized keys in both en/es.


CI Verification ✅

npm run lint       ✅ No errors
npm run typecheck  ✅ No TypeScript errors
npm run build      ✅ 30 pages built (production)

Files Changed (16 files, +310 / -230)

File Description
hooks/useWallet.ts New — Full Freighter wallet state hook
hooks/useAccount.ts Refactored to delegate to useWallet
hooks/index.ts Added useWallet barrel export
components/atoms/connect-button/index.tsx Loading/error states, onConnect callback
components/atoms/connect-button/style.module.css Spinner animation, error text, disabled states
components/atoms/wallet-button/index.tsx Network display, chevron, i18n props
components/molecules/dashboard-sidebar/index.tsx New — Shared sidebar with live wallet info
components/molecules/index.tsx Added dashboard-sidebar export
components/molecules/wallet-data/index.tsx Now uses useWallet
components/organisms/navbar/index.tsx Uses useWallet, removes local state, i18n
pages/dashboard.tsx Uses shared DashboardSidebar
pages/dashboard/profile.tsx Uses shared DashboardSidebar
pages/dashboard/disputes.tsx Uses shared DashboardSidebar
pages/dashboard/settings.tsx Uses shared DashboardSidebar
messages/en.json Added Wallet i18n section
messages/es.json Added Wallet i18n section

How to Test

  1. Ensure the Freighter browser extension is installed
  2. Run npm run dev and navigate to http://localhost:3000
  3. Click "Connect Wallet" → approve in Freighter popup
  4. Verify address appears with green dot in navbar
  5. Click address → dropdown shows network and options
  6. Test "Switch account" and "Disconnect"
  7. Verify dashboard sidebar card shows connected address

Closes #21

… & connection management (trustflow-protocol#21)

- Add comprehensive useWallet hook with connect/disconnect/network detection
- Enhance ConnectButton with loading spinner and error states
- Enhance WalletButton with network display, chevron, and i18n props
- Refactor Navbar to use useWallet, removing local connection state
- Create reusable DashboardSidebar component (replaces 4 page duplicates)
- Add Wallet i18n keys for en/es locales
- Ensure CI passes: lint, typecheck, and build all green
@vercel

vercel Bot commented Jul 21, 2026

Copy link
Copy Markdown

@Topmatrixmor2014 is attempting to deploy a commit to the Meshack Yaro 's projects Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Jul 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
trustflow-frontend Ready Ready Preview, Comment Jul 21, 2026 2:05pm

@meshackyaro meshackyaro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done and thanks for your contribution

@meshackyaro
meshackyaro merged commit 616602f into trustflow-protocol:main Jul 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrate @stellar/freighter-api

2 participants