mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-30 02:23:47 +00:00
refactor: extract shared payment status sets to utility module
- Move PAID_STATUSES/FAILED_STATUSES from Balance.tsx and TopUpResult.tsx to src/utils/paymentStatus.ts - Eliminates code duplication between the two pages
This commit is contained in:
@@ -13,6 +13,7 @@ import type { PaginatedResponse, Transaction } from '../types';
|
||||
import { Card } from '@/components/data-display/Card';
|
||||
import { Button } from '@/components/primitives/Button';
|
||||
import { staggerContainer, staggerItem } from '@/components/motion/transitions';
|
||||
import { isPaidStatus, isFailedStatus } from '../utils/paymentStatus';
|
||||
|
||||
// Icons
|
||||
const ChevronDownIcon = ({ className = 'h-5 w-5' }: { className?: string }) => (
|
||||
@@ -64,32 +65,10 @@ export default function Balance() {
|
||||
if (paymentHandledRef.current) return;
|
||||
|
||||
const paymentStatus = searchParams.get('payment') || searchParams.get('status');
|
||||
const paidSet = new Set([
|
||||
'succeeded',
|
||||
'success',
|
||||
'paid',
|
||||
'paid_over',
|
||||
'overpaid',
|
||||
'completed',
|
||||
'confirmed',
|
||||
'closed',
|
||||
]);
|
||||
const failedSet = new Set([
|
||||
'fail',
|
||||
'failed',
|
||||
'error',
|
||||
'canceled',
|
||||
'cancelled',
|
||||
'declined',
|
||||
'expired',
|
||||
'cancel',
|
||||
'system_fail',
|
||||
'refund_paid',
|
||||
]);
|
||||
|
||||
const normalised = paymentStatus?.toLowerCase() ?? '';
|
||||
const isSuccess = paidSet.has(normalised) || searchParams.get('success') === 'true';
|
||||
const isFailed = failedSet.has(normalised);
|
||||
const isSuccess = isPaidStatus(normalised) || searchParams.get('success') === 'true';
|
||||
const isFailed = isFailedStatus(normalised);
|
||||
|
||||
if (isSuccess) {
|
||||
paymentHandledRef.current = true;
|
||||
|
||||
Reference in New Issue
Block a user