mirror of
https://github.com/bitbaum/orangecat.git
synced 2026-12-04 08:18:42 +01:00
Adds incoming-offer management to the loans dashboard, connects accept flows to payment creation/completion and refinance obligation creation, and tightens touched loan dialogs/cards for mobile-first responsiveness. Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com>
4.8 KiB
4.8 KiB
created_date: 2025-12-04 last_modified_date: 2026-07-09 last_modified_summary: Borrower dashboard now wires incoming offers through accept -> payment -> obligation flow with mobile-first offer management UI.
OrangeCat Loans Flow (Refinance & Payoff)
Borrower path
- Create a loan listing with remaining balance, current rate/term, lender mask, minimum acceptable offer, negotiable flag, visibility (public/private), and contact preference.
- Listing appears under
My Loans; public listings appear inAvailable Loans. - Borrower can view offers per loan, then accept or reject. Acceptance marks the loan as
refinancedorpaid_offand triggers payment handoff.
Lender path
- Browse
Available Loans, filter by category/amount/rate, open details to assess risk. - Submit an offer:
- Payoff: propose amount to clear the balance.
- Refinance: propose payoff + new rate/term; monthly payment preview shown.
- Offers are validated (min offer, no self-offers, active/public loans).
- Borrower reviews offers and accepts or rejects.
Payment handoff (next iteration)
- On accept, record payoff payment (payer, recipient, amount, method). Once completed, the original loan is archived and a new obligation to the offerer is created with the accepted terms.
- Schedule generation and reminders for refinance terms follow the acceptance.
Implementation notes
- Frontend now loads “My Offers” and borrower offer lists; borrower can accept/reject offers per loan.
- Borrower dashboard surfaces incoming offers under
My Loans, with responsive cards and an accept dialog that records payment details on all screen sizes. - Service layer includes
getUserOffersand typed offer mutations routed via/api/loans/offers; UI uses service calls with toasts for feedback. - RLS and backend validations remain the source of truth; loan mutations use
/api/loans,/api/loans/offers,/api/loans/obligation, and/api/loans/payments(no direct DB access from UI). - Currency source of truth lives in
src/config/currencies.tsand is reused by UI, validation, services, and DB constraints (CHF included). - Assets now use real Supabase CRUD APIs (
/api/assetsand/api/assets/[id]) with edit/delete support; entity form drives both create and edit flows.
Payoff / Refinance Payment Handoff (implementation plan)
- Trigger: borrower accepts an offer.
- Status transitions:
- Set offer to
acceptedwith timestamp. - Set loan to
refinanced(for refinance offers) orpaid_off(for payoff offers); stamppaid_off_atwhen payoff funds settle.
- Set offer to
- Payment record (uses existing
loan_payments):- payer_id: offerer (the new lender)
- recipient_id: original lender/borrower counterparty (today we treat as borrower for simplicity; extend later for external lender profiles)
- loan_id: original loan; offer_id: accepted offer
- amount: offer_amount; payment_type:
payoff(orrefinanceif reused) - currency/method/notes captured from UI
- status: start as
pending, move tocompletedwhen borrower confirms receipt or via webhook in future
- New obligation (refinance path):
- On payment
completed, create a new loan row for the borrower with:- original_amount & remaining_balance = offer_amount
- interest_rate/term/monthly_payment from accepted offer
- status
active, lender set to the offerer (store aslender_name= profile display or a dedicated creditor field)
- Archive original loan as
refinancedand keep linkage via aparent_loan_idfield on the new loan (additive migration when implemented).
- On payment
- UX steps:
- After accept: show “Record payoff” dialog to capture payer/recipient/method; allow “mark as completed” once funds clear.
- Dashboard shows original loan as “Refinancing in progress” until payment completion; then moves to archived and surfaces the new loan.
- Validation & security:
- UI validation mirrored by service; backend enforces auth/RLS and ownership (only borrower can accept; only parties can mark payment status).
- No console logging; use structured logger on service side.
Implemented now
- Borrower can accept an offer and immediately open “Record Payoff” to create and complete a payment record (payer = offerer, recipient = borrower for now).
- Incoming offer acceptance now calls
respondToOffer->createPayment->completePayment, and refinance completion also creates the obligation loan in the same flow. - Offer creation / update / accept / reject route through
/api/loans/offershandlers instead of browser Supabase writes. - Service layer:
createPayment/completePaymentcall/api/loans/payments;completePaymentaccepts optionalcreateObligationto create the refinance obligation loan in one step. - UI uses typed forms with validation, toasts for feedback, and disables controls while processing.