Open
Description
Description
Add a new frontend component to allow authenticated users to manually override the latest evaluation for a DAO proposal by setting the vote (Yes or No) for a specific wallet. This will directly update the recommendation
field in the evaluations
table in Supabase for the user's latest evaluation, ensuring that when the vote is auto-scheduled, it reflects the manual override. The component will use the Supabase JavaScript client for authentication and direct database updates, leveraging React with Tailwind CSS for styling and a CDN-hosted React setup.
Requirements
System Overview
- Objective: Enable authenticated users to modify the latest evaluation for a proposal by setting the vote (Yes/No) for a specific wallet, updating the
evaluations
table directly via Supabase. - Scope: Create a
ProposalEvaluationOverride
component to query and update theevaluations
table using the Supabase client, integrating withAIBTC_SUPABASE_URL
for authentication and data access, and display confirmation or error messages. - Compatibility: Ensure integration with the backend's Supabase-based DAO proposal system and LangGraph-based evaluation workflow.
- Features:
- UI form to select a proposal, wallet, and vote (Yes/No) for authenticated users.
- Update the
recommendation
field of the latest evaluation (highestrevision
) for the selectedproposal_id
,dao
, andwallet_id
in theevaluations
table. - Display confirmation or error messages for the override action.
- Securely manage Supabase authentication and database access.
Technical Requirements
- Frontend Framework:
- Use React (CDN-hosted via
cdn.jsdelivr.net
, e.g.,react
,react-dom
). - Use JSX for component rendering, compiled with Babel.
- Apply Tailwind CSS for styling, included via CDN.
- Use React (CDN-hosted via
- Supabase Integration:
- Use the Supabase JavaScript client (
@supabase/supabase-js
) for authentication and direct database access. - Authenticate users and retrieve the Supabase access token from the session.
- Query the
evaluations
table to find the latest evaluation (max(revision)
) for a givenproposal_id
,dao
, andwallet_id
. - Update the
recommendation
field (to "Yes" or "No") for the matching evaluation.
- Use the Supabase JavaScript client (
- Database Operations:
- Query:
SELECT * FROM evaluations WHERE proposal_id = :proposal_id AND dao = :dao AND wallet_id = :wallet_id ORDER BY revision DESC LIMIT 1
. - Update:
UPDATE evaluations SET recommendation = :recommendation, updated_at = NOW() WHERE id = :evaluation_id
. - Ensure the user has permission to modify the evaluation (e.g.,
wallet_id
is associated with the authenticated user).
- Query:
- UI Components:
- Create a
ProposalEvaluationOverride
component:- Display a form with dropdowns for selecting
proposal_id
(from active proposals),wallet_id
(from user-associated wallets), and a radio button or dropdown forvote
(Yes/No). - Disable form for unauthenticated users or if no active proposals/wallets are available.
- Show loading state during Supabase query and update.
- Display success message on successful update (e.g., "Vote override set to {vote} for wallet {wallet_id}") or error message on failure (e.g., "Please log in", "No evaluation found").
- Display a form with dropdowns for selecting
- Style with Tailwind CSS for responsiveness and consistency.
- Create a
- State Management:
- Use React hooks (
useState
,useEffect
) for managing form state, Supabase query/update responses, and loading/error states. - Use Supabase’s
onAuthStateChange
to monitor authentication state and retrieve the access token. - Fetch active proposals and user wallets from Supabase tables (
proposals
and a presumedwallets
table or user metadata) to populate dropdowns.
- Use React hooks (
- Error Handling:
- Display user-friendly error messages for failed operations (e.g., "You must be logged in to override evaluations", "No evaluation found for this wallet").
- Handle authentication errors by prompting the user to log in via Supabase auth UI or redirect.
- Handle cases where no evaluation exists (e.g., "No active evaluation found for this proposal and wallet").
- Log errors to console for debugging, avoiding exposure of sensitive details like tokens.
- Testing:
- Test component rendering, Supabase integration, and form interactions with mock Supabase sessions and data.
- Validate UI responsiveness across devices.
- Ensure Supabase access token and database operations are secure and not exposed in client code.
Acceptance Criteria
-
ProposalEvaluationOverride
component is implemented in React with JSX. - Form includes dropdowns for
proposal_id
,wallet_id
, and a Yes/No vote selector, disabled for unauthenticated users. - Supabase client queries the latest evaluation (
max(revision)
) forproposal_id
,dao
, andwallet_id
fromevaluations
table. - Supabase client updates the
recommendation
field to "Yes" or "No" for the latest evaluation. - Component verifies user permission to modify the evaluation (e.g.,
wallet_id
matches user). - UI displays loading state during Supabase operations.
- Successful update triggers success message (e.g., "Vote override set to Yes for wallet {wallet_id}").
- Error responses display user-friendly messages (e.g., "Please log in", "No evaluation found").
- Authentication errors prompt user to log in via Supabase auth.
- Styling uses Tailwind CSS, ensuring responsiveness.
- Active proposals and user wallets are fetched from Supabase and displayed in dropdowns.
- Unit tests validate component rendering, authentication, form interactions, and Supabase operations.
- Integration tests confirm correct Supabase queries/updates and UI updates with mock sessions.
- Application runs correctly with CDN-hosted React, Tailwind CSS, and Supabase client.
Tasks
- Set up Supabase client (
@supabase/supabase-js
) withAIBTC_SUPABASE_URL
andAIBTC_SUPABASE_ANON_KEY
for authentication and database access. - Create a new React component (
ProposalEvaluationOverride
) with JSX. - Implement Supabase query to fetch the latest evaluation (
max(revision)
) forproposal_id
,dao
, andwallet_id
fromevaluations
table. - Implement Supabase update to set
recommendation
to "Yes" or "No" for the matching evaluation. - Add form with dropdowns for
proposal_id
,wallet_id
, and Yes/No vote selector, styled with Tailwind CSS, disabling for unauthenticated users. - Implement Supabase queries to fetch active proposals (
proposals
table, e.g.,state IN ('evaluating', 'voting')
) and user wallets (fromwallets
table or user metadata). - Implement state management with
useState
,useEffect
, and Supabase’sonAuthStateChange
for auth state, token retrieval, and form state. - Add error handling and user feedback for Supabase operations, including authentication errors.
- Style component with Tailwind CSS for responsiveness.
- Write unit tests for component rendering, authentication, form interactions, and Supabase operations.
- Write integration tests with mock Supabase sessions and data.
- Update documentation in
README.md
ordocs/frontend.md
with setup, authentication, and usage instructions.
Dependencies
- CDN-hosted React and React DOM (
cdn.jsdelivr.net
). - CDN-hosted Tailwind CSS for styling.
- Supabase JavaScript client (
@supabase/supabase-js
) for authentication and database access. - Supabase backend (
AIBTC_SUPABASE_URL
,AIBTC_SUPABASE_ANON_KEY
) forevaluations
,proposals
, and wallet data. - Testing framework (e.g., Jest, React Testing Library) for unit and integration tests.
Additional Notes
- Configure Supabase client with environment variables (e.g.,
VITE_SUPABASE_URL
,VITE_SUPABASE_ANON_KEY
) in.env.local
for development. - Use Supabase’s auth UI or custom login flow to handle user authentication, redirecting to login on authentication errors.
- Ensure Supabase access token is not exposed in client code (e.g., avoid logging or storing in insecure state).
- Fetch proposals with
state
inevaluating
orvoting
to ensure only active proposals are shown. - Verify user ownership of
wallet_id
(e.g., via Supabase user