Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,47 @@ describe('mapTransactionDataForDrawer', () => {
})
})

describe('request pot rollup status', () => {
const pot = (overrides: Partial<HistoryEntry>): 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,
Expand Down
8 changes: 8 additions & 0 deletions src/components/TransactionDetails/transactionTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
1 change: 1 addition & 0 deletions src/utils/history.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export enum EHistoryStatus {
refunded = 'refunded',
canceled = 'canceled', // from simplefi, canceled with only one l
expired = 'expired',
OPEN = 'OPEN',
CLOSED = 'CLOSED',
}

Expand Down
Loading