Skip to content

feat(give): support account swaps for back campaigns and payment_due notices - #310

Merged
JOY (JOY) merged 1 commit into
devfrom
antigravity/give-92-back-account-swap
Nov 22, 2026
Merged

JOY (JOY) merged 1 commit into
devfrom
antigravity/give-92-back-account-swap

Conversation

@JOY

@JOY JOY (JOY) commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Refs #92

Summary

Phase 2 (DOS/Give app surface) following Phase 1 DB migration DOS/DOS.Me#1873 (20261130140000_give_back_campaign_account_swap.sql, merged & deployed to Beta):

  • Account swap eligibility & owner-only boundary (#55, #92, #264):
    • Extended canAskSwap, approvalBlock, loadEditorAccounts, and requestAccountSwap to allow finance-approved receiving-account swaps for back campaigns in live, suspended, changes_requested (with recorded transactions; 0-tx still redirects to GIVE_SWAP_USE_RELEASE), and succeeded when pledges still have payments due (campaignHasPaymentsDue).
    • Strictly preserved #264 owner-only money boundary: co-organizers/editors never see ReceivingAccountSection or AccountSwapBlock, never query receiving_accounts/account_swap_requests, and are refused by requestAccountSwap/cancelAccountSwap.
    • Updated ReceivingAccountSection, AccountSwapBlock, /admin/account-swaps, /admin recoveryAdvice, and lib/errors.ts Vietnamese copy to cover both give and back campaigns (removing the obsolete "back campaigns cannot swap" guidance).
  • Backer in-app notice (payment_account_changed) & transactional email (pledge_account_swapped):
    • Added payment_account_changed rendering in lib/notices.ts and registered it in asksForPayment so stoppedNoticeCampaigns (#93) hides the payment CTA while payment requests are stopped.
    • Added pledge_account_swapped transactional email template in server/email/templates.ts (no stop/unsubscribe links, live net amount due recomputed net of refunds, deadline, /me/pledges/[code] CTA, HTML/header escaping) and lib/email-outbox.ts (outboxMaxAgeDays = 14, Vietnamese label).
    • Shared strict anti-leak masking helpers (maskedAccountLast4, swappedNewAccountLine, swappedOldAccountTarget) across in-app notices and emails so raw multi-digit account numbers can never leak even from malformed payloads.
  • Verification:
    • pnpm format:check, pnpm lint, pnpm typecheck, pnpm test (181 files / 2,675 tests), and pnpm build all pass locally.

📌 TL;DR

This PR extends the account swap feature to support "back" (reward-based) campaigns, allowing organizers to request account changes for live, suspended, or succeeded campaigns with pending payments. It updates the admin review interface to validate payment obligations and ensures backers are notified of new payment details upon approval.

🎯 Type of Change

  • 🚀 New feature
  • 🐛 Bugfix
  • 🧹 Refactor
  • ⚡ Performance
  • 📚 Documentation
  • ⚙️ CI / Configuration

🔍 Changes Walkthrough

File Summary of Changes
apps/web/src/lib/account-swaps.ts Core logic updates: canAskSwap now accepts hasPaymentsDue to allow swaps for succeeded back campaigns. Added campaignHasPaymentsDue and campaignsWithPaymentsDue helpers to query pending pledges. Updated approvalBlock to validate payment status for back campaigns.
apps/web/src/lib/campaign-account.ts Updated loadEditorAccounts to fetch payment status and swap requests for back campaigns. Modified checkSubmitAccount to direct back campaigns with transactions to the swap flow instead of "contact support".
apps/web/src/app/me/campaigns/swap-actions.ts Server action requestAccountSwap now checks for pending payments on succeeded back campaigns before allowing the request.
apps/web/src/app/me/campaigns/[id]/page.tsx UI updates: ReceivingAccountSection and AccountSwapBlock now render for back campaigns when eligible. Added specific copy for backers regarding payment updates.
apps/web/src/app/admin/account-swaps/page.tsx Admin UI updates: Fetches payment status for pending swaps. Passes hasPaymentsDue to SwapCard to enable/disable approval based on whether the back campaign still has obligations.
apps/web/src/app/admin/account-swaps/actions.ts Updated success message to mention backer notifications. Added revalidatePath for pledge and notice pages to ensure UI updates immediately after approval.
apps/web/src/app/me/notices/page.test.ts Added tests for rendering payment_account_changed notices, verifying distinct CTAs for active vs. stopped campaigns.
apps/web/src/app/admin/account-swaps/page.test.ts New test file verifying admin page logic: approval is enabled only for back campaigns with pending payments.
apps/web/src/app/me/campaigns/[id]/page.test.ts Updated tests to verify swap UI visibility for back campaigns in various states (live, suspended, succeeded with/without payments).
apps/web/src/app/me/campaigns/swap-actions.test.ts Updated tests to cover new eligibility rules for back campaigns and payment checks.
apps/web/src/lib/account-swaps.test.ts Updated unit tests for canAskSwap and approvalBlock to reflect new back campaign logic.
apps/web/src/lib/campaign-account.test.ts Updated tests for loadEditorAccounts and checkSubmitAccount to verify new data fetching and messaging.
apps/web/src/app/admin/page.test.ts Updated admin review tests to reflect that back campaigns now offer a swap form instead of a "contact support" callout.

📊 Architectural Flow

sequenceDiagram
    participant Organizer
    participant Web_App as Web App (Organizer)
    participant DB as Database
    participant Admin as Admin (Finance)
    participant Backer as Backer

    Note over Organizer, Web_App: Request Swap
    Organizer->>Web_App: Request Account Swap
    Web_App->>DB: Check Campaign Status & Pending Payments
    alt Succeeded Back Campaign with Payments Due
        Web_App->>DB: Create Swap Request (Pending)
    else Ineligible
        Web_App-->>Organizer: Show Error/Contact Support
    end

    Note over Admin, Web_App: Review & Approve
    Admin->>Web_App: Review Swap Request
    Web_App->>DB: Verify Payments Still Due (if Back Campaign)
    alt Valid & Payments Due
        Admin->>Web_App: Approve Swap
        Web_App->>DB: Execute Swap (Old Binding End, New Binding Start)
        Web_App->>DB: Create Notice for Backers with Pending Payments
        Web_App-->>Admin: Success (Backers Notified)
    else No Payments Due
        Web_App-->>Admin: Block Approval (No Obligations)
    end

    Note over Backer, Web_App: Notification
    Backer->>Web_App: View Notices
    Web_App-->>Backer: Show New Payment Details & CTA
Loading

@JOY JOY (JOY) added line:campaigns Product line: campaigns po:agy Owned by Antigravity PO (mutual-exclusion parallel PO label) labels Nov 22, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
give Ready Ready Preview Nov 22, 2026 10:38am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 40256d04-0b57-4938-b42d-ecc359355a26

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

dos[bot]
dos Bot approved these changes Nov 22, 2026

@dos dos Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⏱️ Code Review completed (24 eligible files · 105,554 chars · 3 model call(s) · 4 PR unit(s))

Whole diff with bounded context at base dd40557 / head 8045782.

✅ CLEAN_PASS: Complete diff reviewed

Context investigation was bounded to the explicitly requested snapshot paths.

@JOY

Copy link
Copy Markdown
Contributor Author

PO acceptance: merge at 8045782

Independent PO flagship money-domain security review (ee890ade-c899-4b4a-ba80-fa2710a5e382): APPROVE (0 P0/P1/P2 findings).

@JOY
JOY (JOY) merged commit 581915e into dev Nov 22, 2026
6 checks passed
@JOY
JOY (JOY) deleted the antigravity/give-92-back-account-swap branch November 22, 2026 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

line:campaigns Product line: campaigns po:agy Owned by Antigravity PO (mutual-exclusion parallel PO label)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant