Files
emaui/apps/portal/src/app/features/payment/utils/money.ts
estifanos 06eb9eca4f feat(payment): implement payment feature with Telebirr integration first try
- Define shared payment types and interfaces in payment.ts
- Create PaymentModal component for handling payment interactions
- Implement payment API client for initiating and confirming payments
- Add payment history management with localStorage
- Create PaymentsPage for displaying payment status and history
- Introduce utility functions for money conversion and formatting
- Set up hooks for managing payment flow and state
- Update SeamanBookApplicationPage to utilize new payment modal
- Add tests for payment API functions and history management
2026-07-30 07:33:30 +00:00

21 lines
771 B
TypeScript

/** Whole-birr major amount -> minor units (cents). Rounds to avoid float drift (19.99 -> 1999). */
export function toMinor(major: number): number {
return Math.round(major * 100);
}
export function fromMinor(minor: number): number {
return minor / 100;
}
/**
* Matches the format already used across the portal (`ETB ${n.toFixed(2)}`, e.g.
* SeamanBookApplicationPage.tsx) rather than Intl.NumberFormat({style:'currency'}), whose ETB
* output varies by ICU build. Not unifying the ~20 existing inline call sites — out of scope here.
*/
export function formatMinor(amountMinor: number, currency: string): string {
return `${currency} ${fromMinor(amountMinor).toLocaleString(undefined, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})}`;
}