Skip to content

feat: wire agreement chat to Nest + use real agreement UUID #98

Description

@Kalchaqui

Context

Agreement chat UI exists (components/agreements/agreement-chat.tsx) but today it talks to Supabase via service-role Server Actions (lib/actions/agreement-chat.ts), bypassing Nest auth.

Nest already has JWT endpoints (ready after BE work):

  • GET /v1/agreements/:agreementId/messages
  • POST /v1/agreements/:agreementId/messages

Depends on: ThalosBackend#86 (schema sender_id + fail-hard participants).

Problem

  1. UI agreement ids are often AGR-* / mocks / contractId — not the UUID FK expected by agreement_messages → Postgres UUID errors (#92).
  2. Create flow injects optimistic AGR-… ids and does not persist a shared DB agreement UUID for both parties.
  3. Chat does not use Nest JWT → no participant checks on the FE path.
  4. SHOW_MOCKED_AGREEMENTS defaults to true (prod risk).

Scope (keep tight — make A↔B chat work)

  • Persist agreement on create (Nest or existing DB helpers) so both parties share a UUID (or resolve contractId → agreements UUID before opening chat).
  • Stop injecting fake AGR-* ids into chat after create; UI chat must receive a real UUID.
  • Wire AgreementChat to Nest via lib/api + JWT (auth_token / auth store). Remove or stop using Supabase service-role chat actions for this path.
  • Guard: if id is non-UUID / mock (AGR-*, ENT-*), do not call API — show clear “demo / unavailable” (covers fix: block agreement chat (and mutating actions) on mocked non-UUID agreement ids #92).
  • Default mocks off for production (NEXT_PUBLIC_SHOW_MOCKED_AGREEMENTS=false or invert default); gate business ENT-* the same way as personal.

Out of scope

  • Business wizard full Trustless create (can stay limited if personal A↔B works)
  • Approve/release on-chain wiring beyond what’s needed to create a real agreement
  • Admin mock page
  • Realtime WebSockets (polling OK)
  • Trustless API-key proxy (separate security follow-up)

Acceptance criteria

  1. User A creates a real agreement with User B as counterparty.
  2. Both see the same agreement UUID in the dashboard (not AGR-*).
  3. A opens chat → sends a message → B opens the same agreement chat → sees it → replies → A sees reply.
  4. Opening chat on a mock id does not hit Postgres / Nest with invalid UUID.
  5. Production/demo with mocks disabled does not show demo agreements by default.

Test plan

  • Two wallets / two accounts on shared Nest + Supabase
  • Create → list → chat A→B→A
  • Mock id path shows friendly message (no console UUID error)
  • NEXT_PUBLIC_API_URL points at Nest /v1

Related

DoD

  • PR on main with Nest chat client + UUID path
  • Proof: short clip or screenshots A↔B + mock guard
  • Closes #NN (this issue) and Closes #92 if fixed here

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions