import React, { useEffect, useMemo, useState } from 'react'; import { RefreshControl, ScrollView, StyleSheet, Text, View, } from 'react-native'; import type { CompositeScreenProps } from '@react-navigation/native'; import type { BottomTabScreenProps } from '@react-navigation/bottom-tabs'; import type { NativeStackScreenProps } from '@react-navigation/native-stack'; import Ionicons from '@react-native-vector-icons/ionicons'; import { Button, Card, EmptyState, Loader, ScreenShell } from '../../../components'; import { FeatureKey } from '../../../constants/featureKeys'; import { useFeature } from '../../../features'; import type { MainTabParamList, ServicesStackParamList } from '../../../navigation/types'; import { useTheme, fontFamily } from '../../../theme'; import { formatCompactCurrency, formatCurrency } from '../../../utils/formatters'; import { DepositAccountCard } from '../components/DepositAccountCard'; import { DepositOptionChip } from '../components/DepositOptionChip'; import { useDepositPortfolio } from '../hooks/useDepositPortfolio'; import { getDaysUntilMaturity, isDepositNearMaturity } from '../utils/depositCalculators'; type Props = CompositeScreenProps< NativeStackScreenProps, BottomTabScreenProps >; type FilterKey = 'all' | 'fd' | 'rd' | 'maturing'; const FILTERS: Array<{ id: FilterKey; label: string }> = [ { id: 'all', label: 'All deposits' }, { id: 'fd', label: 'Fixed deposit' }, { id: 'rd', label: 'Recurring deposit' }, { id: 'maturing', label: 'Maturing soon' }, ]; export default function DepositsOverviewScreen({ navigation, route }: Props) { const theme = useTheme(); const { deposits, isLoading, isError, onRefresh, refreshing } = useDepositPortfolio(); const [filter, setFilter] = useState(route.params?.initialKind ?? 'all'); useEffect(() => { if (route.params?.initialKind) { setFilter(route.params.initialKind); } }, [route.params?.initialKind]); const summary = useMemo(() => { const activeDeposits = deposits.filter((deposit) => deposit.status === 'active'); const nearMaturityDeposits = deposits.filter((deposit) => isDepositNearMaturity(deposit)); return { totalDeposits: deposits.length, activeDepositsCount: activeDeposits.length, totalActiveValue: activeDeposits.reduce( (sum, deposit) => sum + deposit.totalInvestment, 0, ), projectedMaturityValue: deposits.reduce( (sum, deposit) => sum + deposit.maturityAmount, 0, ), nearMaturityDeposits, }; }, [deposits]); const filteredDeposits = useMemo(() => { switch (filter) { case 'fd': return deposits.filter((deposit) => deposit.kind === 'fd'); case 'rd': return deposits.filter((deposit) => deposit.kind === 'rd'); case 'maturing': return deposits.filter((deposit) => isDepositNearMaturity(deposit)); case 'all': default: return deposits; } }, [deposits, filter]); const selectedFilterLabel = FILTERS.find((item) => item.id === filter)?.label ?? 'All deposits'; /** * Each action is gated on the route it opens. Without this the buttons * render whatever the config says, while the navigator refuses to register * the destination — a control that looks live and does nothing. */ const canOpenFd = useFeature(FeatureKey.SERVICES_DEPOSITS_OPEN_FD); const canOpenRd = useFeature(FeatureKey.SERVICES_DEPOSITS_OPEN_RD); const canCalculate = useFeature(FeatureKey.SERVICES_DEPOSITS_CALCULATOR); const showQuickActions = canOpenFd || canOpenRd || canCalculate; const handleOpenFixedDeposit = () => navigation.navigate('OpenFixedDeposit'); const handleOpenRecurringDeposit = () => navigation.navigate('OpenRecurringDeposit'); const handleOpenCalculator = () => navigation.navigate('DepositCalculator'); return ( } > Portfolio snapshot Keep every deposit journey in one clear view Review portfolio value, upcoming maturities, and quick actions without jumping across sections. Active portfolio {formatCompactCurrency(summary.totalActiveValue)} {summary.activeDepositsCount} active plans across fixed and recurring deposits {summary.nearMaturityDeposits.length} maturing soon Projected maturity {formatCompactCurrency(summary.projectedMaturityValue)} Estimated portfolio value when all plans mature Total deposits {summary.totalDeposits} {summary.totalDeposits === 1 ? '1 deposit' : `${summary.totalDeposits} deposits`} currently tracked {showQuickActions ? ( Quick actions Start a new plan or estimate returns from one place {canOpenFd ? (