Skip to content

feat(open-credit): create credit line on offer acceptance - #1338

Open
AugistineCreates wants to merge 1 commit into
Creditra:mainfrom
AugistineCreates:feat/open-credit-acceptance-flow
Open

AugistineCreates wants to merge 1 commit into
Creditra:mainfrom
AugistineCreates:feat/open-credit-acceptance-flow

Conversation

@AugistineCreates

Copy link
Copy Markdown
Contributor

Summary

On /open-credit (RequestEvaluation), clicking "Accept Credit Line" previously moved the wizard to step 5 without creating a credit line in state, without binding the offer to the connected wallet, and without checking offer expiry.

This PR resolves the issue by extending the credit data port with an acceptOffer operation, requiring a connected wallet at evaluation and acceptance time, binding the offer identity to the wallet's public key, enforcing offer time expiration, and navigating the user to /credit-lines?highlight=<id> upon successful acceptance.

Resolves Creditra/Creditra-Frontend open credit acceptance issue.


Key Changes

  1. Extend the Credit Data Port (src/services/credit/index.ts):

    • Added offerId: string and expiresAt: number to the EvalResult type interface.
    • Added acceptOffer(owner: string, offerId: string): Promise<CreditLine> to the credit data port.
    • The mock adapter appends a new Active line to its in-memory store, so subsequent listCreditLines and useCreditLines calls return it.
  2. Wallet Gate & Owner Binding (src/pages/RequestEvaluation.tsx):

    • Bound owner identity using walletIdentityKey from src/context/WalletContext.tsx.
    • Requires status === 'connected' to start an evaluation and to accept.
    • If the identity switches or disconnects before acceptance, the offer is invalidated with the message:

      "This offer was issued to a different wallet."

  3. Server-Based Offer Expiry & Accessibility (src/pages/RequestEvaluation.tsx):

    • Displays real-time countdown timer: "Offer expires in mm:ss".
    • Uses server-derived expiresAt timestamp to prevent clock skew manipulation.
    • Text is announced once at 60s using aria-live="polite".
    • When expired, Accept is disabled and "Re-run evaluation" is shown.
  4. Double-Submit Guard & Pending / Error UX:

    • Repeated clicks are blocked via PendingButton.
    • On success, the credit provider is refreshed and step 5 links to /credit-lines?highlight=<lineId>.
    • On failure, shows an error with role="alert" and a "Retry" button, remaining on step 4.

Test Verification

All 7 scenarios pass in src/pages/__tests__/RequestEvaluation.accept.test.tsx and src/services/credit/__tests__/credit.test.ts:

  • Disconnected wallet on /open-credit disables evaluation start with connect prompt.
  • Accept with a valid offer calls acceptOffer once, adds line to useCreditLines(), and links step 5 with ?highlight=.
  • Double-click / rapid clicks invoke acceptOffer exactly once.
  • Offer expires with fake timers: disables Accept and shows "Re-run evaluation".
  • Wallet switch between evaluation and accept invalidates offer with the mismatch message.
  • When acceptOffer rejects, an alert is rendered, user stays on step 4, and "Retry" re-attempts.
  • Step 5 is strictly unreachable without a successful acceptOffer.
  • Production build passes (npm run build).

Closes #1168

@greatest0fallt1me

Copy link
Copy Markdown
Contributor

This PR currently has no file changes compared to main (its branch may have been reset, or the commits were already merged elsewhere), so there is nothing to review or merge. Please push the commits for your issue onto this branch, rebased on the latest main, and make sure CI passes.

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.

Open credit: accepting an /open-credit offer must create the line in credit state, bind it to the wallet and honour offer expiry

2 participants