/** * Copyright since 2025 Mifos Initiative * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /** * Maps a clearing status/decision string to one of the three shared .pill classes * (ok / bad / neutral). Shared by every CTS, NACH and settlement/reconciliation screen so the * colour language stays consistent across the whole clearing feature. */ export function pillClass(status: string | null | undefined): 'ok' | 'bad' | 'neutral' { const s = (status || '').toUpperCase(); const ok = [ 'PASSED', 'PASS', 'POSTED', 'MATCHED', 'SETTLED', 'SENT', 'SENT_TO_CLEARING_HOUSE', 'PROCESSED', 'VALIDATED', 'ACTIVE', 'CLEARED', 'HONOURED', 'COMPLETED' ]; const bad = [ 'RETURNED', 'RETURN', 'REJECTED', 'MISMATCH', 'DISHONOURED', 'CANCELLED', 'FAILED', 'FAIL', 'UNROUTABLE' ]; if (ok.includes(s)) { return 'ok'; } if (bad.includes(s)) { return 'bad'; } return 'neutral'; } /** Extracts the most specific backend error message from a Fineract-style error response. */ export function clearingError(err: any, fallback = 'Request failed'): string { return err?.error?.errors?.[0]?.defaultUserMessage ?? err?.error?.defaultUserMessage ?? fallback; }