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:
Fringg
2026-03-09 05:00:08 +03:00
parent 7ce5341e95
commit 6a9fdac75c
3 changed files with 35 additions and 57 deletions

View File

@@ -12,6 +12,7 @@ import { Spinner } from '@/components/ui/Spinner';
import { AnimatedCheckmark } from '@/components/ui/AnimatedCheckmark';
import { AnimatedCrossmark } from '@/components/ui/AnimatedCrossmark';
import { loadTopUpPendingInfo, clearTopUpPendingInfo } from '../utils/topUpStorage';
import { isPaidStatus, isFailedStatus } from '../utils/paymentStatus';
// ── Constants ────────────────────────────────────────────────
const MAX_POLL_MS = 10 * 60 * 1000; // 10 minutes
@@ -177,39 +178,6 @@ function TimeoutState({ onRetry, onGoBack }: { onRetry: () => void; onGoBack: ()
);
}
// ── Determine paid status from provider-specific status strings ──
const PAID_STATUSES = new Set([
'succeeded',
'success',
'paid',
'paid_over',
'overpaid',
'completed',
'confirmed',
'closed',
]);
const FAILED_STATUSES = new Set([
'fail',
'failed',
'error',
'canceled',
'cancelled',
'declined',
'expired',
'cancel',
'system_fail',
'refund_paid',
]);
function isPaidStatus(status: string): boolean {
return PAID_STATUSES.has(status.toLowerCase());
}
function isFailedStatus(status: string): boolean {
return FAILED_STATUSES.has(status.toLowerCase());
}
// ── Main Component ───────────────────────────────────────────
export default function TopUpResult() {