Skip to content

Wire defaultClaimAmount to mobile and bulk-update allowances on config change#6

Closed
darthnithin wants to merge 5 commits intomainfrom
claude/investigate-pool-available-tx4ZZ
Closed

Wire defaultClaimAmount to mobile and bulk-update allowances on config change#6
darthnithin wants to merge 5 commits intomainfrom
claude/investigate-pool-available-tx4ZZ

Conversation

@darthnithin
Copy link
Copy Markdown
Owner

No description provided.

Active codes with expiresAt < now are excluded from all claim
count and sum queries using or(ne(status,'active'), gte(expiresAt, now)).
This fixes Pool Available, Allocated, Utilization %, Claims This Week,
All-time Claims, and Avg Pts/Requester being inflated by expired codes.

Also removes the Expired status bucket from the Claims This Week
breakdown UI since that status is never written to the DB.

https://claude.ai/code/session_017in4tv2Nd1kg39cy5qrWV7
Issue 3 (option A): Pool history bars now show real redeemed amounts
derived from claim codes grouped by weeklyPoolId, rather than the always-
zero stored values in weeklyPools.totalAmount / allocatedAmount. The
estimatedWeeklyTotal (current active donors) is used as a consistent
capacity baseline across all historical weeks.

Issue 4 (option C): Rename 'Total Pool' to 'Live Capacity' and change
'(estimated)' / '(est)' annotations to '(current donors)' to make it
clear the figure reflects today's active donor set, not a week-start
snapshot.

https://claude.ai/code/session_017in4tv2Nd1kg39cy5qrWV7
Apply the same read-time expiry inference used by the mobile history
endpoint: if status='active' and expiresAt < now, return 'expired'
instead of the raw DB value. The DB intentionally never writes 'expired'
since expiresAt is the ground truth; the admin stats endpoint just
wasn't applying the conversion.

https://claude.ai/code/session_017in4tv2Nd1kg39cy5qrWV7
…g change

- Admin config save now bulk-updates all existing userAllowances for the
  current week when defaultWeeklyAllowance changes, adjusting weeklyLimit
  and remaining (usedAmount preserved). Returns allowancesUpdated count.
- Requester allowance endpoint always fetches config and returns
  defaultClaimAmount alongside allowance data.
- Mobile requester screen replaces hardcoded DEFAULT_CLAIM_AMOUNT=10 with
  state driven from the API, so changing the config takes effect immediately.
- lib/api.ts: typed getRequesterAllowance return as RequesterAllowance.

https://claude.ai/code/session_017in4tv2Nd1kg39cy5qrWV7
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Feb 18, 2026

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

Project Deployment Actions Updated (UTC)
slugswap Ready Ready Preview, Comment Feb 18, 2026 5:39am

@darthnithin
Copy link
Copy Markdown
Owner Author

@claude how do I even test this?

@claude
Copy link
Copy Markdown

claude bot commented Feb 18, 2026

Claude finished @darthnithin's task in 1m 20s —— View job


Testing Instructions

  • Read changed files to understand implementation
  • Review database schema
  • Provide step-by-step testing guide

What This PR Does

This PR implements two key features:

  1. Wire defaultClaimAmount to mobile app - The mobile request screen now displays the configured default claim amount from the admin dashboard
  2. Bulk-update allowances on config change - When you change defaultWeeklyAllowance in the admin dashboard, all existing user allowances for the current week are automatically updated

Testing Guide

Part 1: Test Mobile App Receives defaultClaimAmount

Setup:

  1. Make sure your dashboard is deployed (or run npm run dashboard:dev)
  2. Make sure your mobile app is running (npm run mobile:start and npm run mobile:ios or npm run mobile:android)

Test Steps:

  1. Go to the admin dashboard → Configuration section
  2. Note the current "Default Claim Amount" value (let's say it's 10)
  3. Open the mobile app and navigate to the Request tab
  4. You should see "Generate Claim Code" button
  5. Tap it - it should generate a code for 10 points (matching the dashboard config)

Change the config:

  1. In admin dashboard, change "Default Claim Amount" to 15
  2. Click "Save Changes"
  3. In mobile app, pull down to refresh the Request screen
  4. Generate a new claim code
  5. Expected: The new code should be for 15 points (not 10)

Where to verify:

  • Mobile UI: Look at the generated claim code amount
  • API response: Check the network tab - /api/requesters/allowance should return defaultClaimAmount: 15
  • Database: Check the claim_codes table - new codes should have amount = 15

Part 2: Test Bulk Allowance Update

Setup:

  1. Create 2-3 test users by signing in to the mobile app with different Google accounts
  2. Have each user generate at least one claim code (this creates their allowance record)
  3. Go to admin dashboard → User Allowances section and verify you can see these users

Test Steps:

  1. Check current allowances:

    • In admin dashboard, go to Configuration section
    • Note the current "Weekly Allowance / User" value (let's say it's 50)
    • Go to User Allowances section
    • Select a test user - you should see their allowance is 50 points total
  2. Change the default allowance:

    • Go back to Configuration section
    • Change "Weekly Allowance / User" from 50 to 100
    • Click "Save Changes"
    • Expected: You should see a success message like "Configuration updated" with allowancesUpdated: 3 (or however many users you have)
  3. Verify allowances were updated:

    • Go to User Allowances section
    • Select each of your test users
    • Expected: Each user's weekly limit should now be 100 points
    • Expected: If a user had used 10 points before (remaining 40), they should now have remaining = 90 (new limit 100 - used 10)
  4. Test on mobile:

    • Open mobile app (any of your test accounts)
    • Pull down to refresh the Request tab
    • Expected: The "Weekly Allowance" card should show the new limit (100 points)
    • Expected: Remaining points should be recalculated correctly

Important edge cases to test:

  • User who used more than new limit: If old limit was 50, user used 30, then you lower to 20:

    • Expected: Remaining should be 0 (not negative) - the code uses GREATEST(0, ...) to prevent negatives
  • New week rollover:

    • If you change the config and then a new week starts, new allowances should use the updated default
    • Old week allowances are not affected (only current week is bulk-updated)

Where the Changes Happen

  1. Backend: /api/admin/config route (apps/dashboard/app/api/admin/[action]/route.ts:148-184)

    • When defaultWeeklyAllowance changes, it finds the current week's pool
    • Bulk updates all userAllowances records for that pool
    • Returns allowancesUpdated count in response
  2. Backend: /api/requesters/allowance route (apps/dashboard/app/api/requesters/[action]/route.ts:141)

    • Now returns defaultClaimAmount in the response
  3. Frontend: Mobile Request screen (apps/mobile/app/(tabs)/(request)/index.tsx:61,184)

    • Fetches and displays defaultClaimAmount
    • Uses it when generating claim codes
  4. Shared API client (lib/api.ts:117)

    • TypeScript type updated to include defaultClaimAmount

Database Verification

If you want to verify at the database level (using Drizzle Studio with npm run db:studio):

Check config:

SELECT default_claim_amount, default_weekly_allowance, updated_at 
FROM admin_config 
WHERE id = 'global';

Check user allowances for current week:

SELECT ua.user_id, ua.weekly_limit, ua.used_amount, ua.remaining_amount, u.email
FROM user_allowances ua
JOIN users u ON ua.user_id = u.id
JOIN weekly_pools wp ON ua.weekly_pool_id = wp.id
WHERE wp.week_start <= NOW() AND wp.week_end >= NOW();

Troubleshooting

Mobile app not showing updated default:

  • Pull down to refresh the Request screen (it calls /api/requesters/allowance)
  • Check if the API is returning the new value in the network inspector

Allowances not updating:

  • Make sure you're testing with users who have existing allowance records for the current week
  • Check the API response - it should include allowancesUpdated: N where N > 0
  • Verify there's an active weekly pool for the current week in the database

Values are negative:

  • This shouldn't happen - the SQL uses GREATEST(0, ...) to clamp to zero
  • If you see negatives, that's a bug to investigate

…llow admin access to user APIs

- Remove stored remainingAmount from userAllowances; derive it as
  max(0, weeklyLimit - usedAmount) at read time everywhere so allowance
  changes are always accurate without extra writes
- Switch requesters/allowance and claims/generate pool lookup from exact
  weekStart match to lte/gte range query, matching the admin dashboard
  approach so all endpoints always find the same pool record
- Add resolveRequestIdentity() to admin-auth that falls back to the
  admin session cookie when no Bearer token is present, allowing admin
  to call /api/requesters/allowance and /api/users/* without 401
- Support ?userId= override in /api/requesters/allowance when called
  with admin session, skipping user-sync and querying any user directly
- Fix /api/users/me to look up the authenticated user instead of a
  hardcoded example email

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@darthnithin
Copy link
Copy Markdown
Owner Author

not relevant anymore

@darthnithin darthnithin closed this Apr 1, 2026
@darthnithin darthnithin deleted the claude/investigate-pool-available-tx4ZZ branch April 11, 2026 00:28
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.

2 participants