From d90fb571eb9cfc880748418c060de7777d81c56b Mon Sep 17 00:00:00 2001 From: oxwel77 Date: Thu, 16 Jul 2026 12:12:41 +0100 Subject: [PATCH] fix(request): show Completed on a fully funded request pot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A request link's status is an OPEN/CLOSED column that only flips to CLOSED when the requester explicitly closes it, so it never reports that the goal was met. mapEntryStatusToUiStatus had no OPEN case and fell through to the default branch, which returns 'pending' — so a fully funded pot and an untouched one rendered the same "Pending" badge, even at $0 remaining. Derive the badge from the collected sum against the goal for OPEN request links, which is the same data the progress bar already renders. Goal 0 is the "no goal set" pot and can never be fully funded, so it stays pending. Also add OPEN to EHistoryStatus — the backend casts past the type when it sends the field, so nothing flagged that the enum was missing a value the wire actually carries. --- .../__tests__/transactionTransformer.test.ts | 41 +++++++++++++++++++ .../transactionTransformer.ts | 8 ++++ src/utils/history.utils.ts | 1 + 3 files changed, 50 insertions(+) diff --git a/src/components/TransactionDetails/__tests__/transactionTransformer.test.ts b/src/components/TransactionDetails/__tests__/transactionTransformer.test.ts index 922d8dc087..2fbade543b 100644 --- a/src/components/TransactionDetails/__tests__/transactionTransformer.test.ts +++ b/src/components/TransactionDetails/__tests__/transactionTransformer.test.ts @@ -482,6 +482,47 @@ describe('mapTransactionDataForDrawer', () => { }) }) + describe('request pot rollup status', () => { + const pot = (overrides: Partial): HistoryEntry => + baseEntry({ + userRole: EHistoryUserRole.RECIPIENT, + status: EHistoryStatus.OPEN, + amount: '1750', + isRequestLink: true, + extraData: { kind: 'P2P_REQUEST_FULFILL', provider: 'PEANUT', isRequestPotRollup: true }, + ...overrides, + }) + + it('an open pot that met its goal reads as completed', () => { + const result = mapTransactionDataForDrawer(pot({ totalAmountCollected: 1750 })).transactionDetails + expect(result.status).toBe('completed') + }) + + it('an over-funded open pot reads as completed', () => { + const result = mapTransactionDataForDrawer(pot({ totalAmountCollected: 2000 })).transactionDetails + expect(result.status).toBe('completed') + }) + + it('a partially funded open pot stays pending', () => { + const result = mapTransactionDataForDrawer(pot({ totalAmountCollected: 500 })).transactionDetails + expect(result.status).toBe('pending') + }) + + it('a goal-less pot stays pending no matter what it collected', () => { + const result = mapTransactionDataForDrawer( + pot({ amount: '0', totalAmountCollected: 500 }) + ).transactionDetails + expect(result.status).toBe('pending') + }) + + it('a closed pot still reads as closed, not completed', () => { + const result = mapTransactionDataForDrawer( + pot({ status: EHistoryStatus.CLOSED, totalAmountCollected: 1750 }) + ).transactionDetails + expect(result.status).toBe('closed') + }) + }) + describe('refund credit rows (status + sign + flag)', () => { const negativeAuth = baseEntry({ userRole: EHistoryUserRole.SENDER, diff --git a/src/components/TransactionDetails/transactionTransformer.ts b/src/components/TransactionDetails/transactionTransformer.ts index 333e8a2742..95d09ca2e0 100644 --- a/src/components/TransactionDetails/transactionTransformer.ts +++ b/src/components/TransactionDetails/transactionTransformer.ts @@ -192,6 +192,14 @@ function mapEntryStatusToUiStatus(entry: HistoryEntry, direction: TransactionDir } } + // A request link stays OPEN until the requester closes it, so its raw status + // never reports that the goal was met — derive that from the collected sum. + // Goal 0 is the "no goal set" pot, which can never be fully funded. + if (entry.isRequestLink && status === 'OPEN') { + const goal = Number(entry.amount ?? 0) + return goal > 0 && (entry.totalAmountCollected ?? 0) >= goal ? 'completed' : 'pending' + } + switch (status) { case 'NEW': case 'PENDING': diff --git a/src/utils/history.utils.ts b/src/utils/history.utils.ts index 6913240bc7..a49a46a7df 100644 --- a/src/utils/history.utils.ts +++ b/src/utils/history.utils.ts @@ -52,6 +52,7 @@ export enum EHistoryStatus { refunded = 'refunded', canceled = 'canceled', // from simplefi, canceled with only one l expired = 'expired', + OPEN = 'OPEN', CLOSED = 'CLOSED', }