Skip to content

Add an audit trail with optimistic UI and rollback for role assignment mutations #332

Description

@Lakes41

Difficulty: Advanced
Type: feature

Background
POST /v1/members/:address/roles is a Bearer-authenticated admin mutation (per the Live API endpoints table) that assigns a role to a member, and the app already uses React Query for data fetching/mutations.

Problem
Role assignment currently likely waits for the network round-trip before updating the UI (or, if optimistic, has no visible history of who changed what and when), and any failure handling/rollback behavior isn't documented — admins have no way to see a history of role changes made through the dashboard.

Expected outcome
Assigning a role updates the UI immediately (optimistic update via React Query's onMutate), automatically rolls back cleanly on failure (including on a 401 that isn't resolved by the auto-retry flow), and a local "recent changes" panel shows a short audit trail (who/what/when) of role changes made in the current admin session.

Suggested implementation

  • Implement the mutation with React Query's optimistic update pattern: snapshot the previous member/role state in onMutate, apply the optimistic change, and roll back in onError.
  • Add a lightweight, session-scoped (not necessarily persisted) audit log of role changes attempted in the UI, including failed/rolled-back attempts marked as such.
  • Integrate with the existing SIWE re-auth retry flow (if implemented) so a 401-triggered rollback doesn't falsely mark a change as permanently failed if it's about to be retried.
  • Add tests (mocking the API layer) for: successful optimistic update, network failure rollback, and 401-then-retry-success.

Acceptance criteria

  • Role changes reflect optimistically in the UI before the network call resolves
  • Failed mutations roll back the optimistic change and are clearly marked in the audit panel
  • Audit panel shows a readable history of attempted role changes for the current session
  • Tests cover success, failure/rollback, and 401-retry-success paths

Likely affected files/directories

  • app/admin/ (role assignment UI)
  • lib/api/live.ts, lib/api/mock.ts
  • lib/wallet/providers.tsx

Metadata

Metadata

Assignees

Labels

GrantFox OSSGrantFox Open Source Sponsorship program tagMaybe RewardedIssue may qualify for a reward upon successful completion per campaign rulesOfficial Campaign | FWC26Official FWC26 campaign issue — eligible for campaign scoring and rewardsadvancedAdvanced difficulty tasks requiring significant domain knowledge and implementation effortfeatureNew feature, enhancement, or functional addition

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions