import { BottomSheetModal, BottomSheetSectionList } from '@gorhom/bottom-sheet' import React, { useMemo } from 'react' import { useTranslation } from 'react-i18next' import { ActivityIndicator, ListRenderItem, StyleSheet, Text, View } from 'react-native' import { useSafeAreaInsets } from 'react-native-safe-area-context' import AppAnalytics from 'src/analytics/AppAnalytics' import { PointsEvents } from 'src/analytics/Events' import BottomSheetBase from 'src/components/BottomSheetBase' import Button, { BtnSizes, BtnTypes } from 'src/components/Button' import { NotificationVariant } from 'src/components/InLineNotification' import SectionHead from 'src/components/SectionHead' import Toast from 'src/components/Toast' import { default as Attention, default as AttentionIcon } from 'src/icons/Attention' import LogoHeart from 'src/images/LogoHeart' import { HistoryCardMetadata, useGetHistoryDefinition } from 'src/points/cardDefinitions' import { nextPageUrlSelector, pointsHistorySelector, pointsHistoryStatusSelector, } from 'src/points/selectors' import { getHistoryStarted } from 'src/points/slice' import { ClaimHistoryCardItem } from 'src/points/types' import { useDispatch, useSelector } from 'src/redux/hooks' import { default as Colors, default as colors } from 'src/styles/colors' import { typeScale } from 'src/styles/fonts' import { Spacing } from 'src/styles/styles' import { groupFeedItemsInSections } from 'src/transactions/utils' interface Props { forwardedRef: React.RefObject } function PointsHistoryCard({ icon, title, subtitle, pointsAmount, testID, }: HistoryCardMetadata & { testID?: string }) { return ( {icon} {title} {subtitle} +{pointsAmount} ) } function PointsHistoryBottomSheet({ forwardedRef }: Props) { const { t } = useTranslation() const dispatch = useDispatch() const pointsHistoryStatus = useSelector(pointsHistoryStatusSelector) const pointsHistory = useSelector(pointsHistorySelector) const hasNextPage = useSelector(nextPageUrlSelector) const getHistoryDefinition = useGetHistoryDefinition() const insets = useSafeAreaInsets() const onFetchMoreHistory = () => { if (!hasNextPage || pointsHistoryStatus !== 'idle') { // prevent fetching more history if there is no next page. onEndReached // will continue to fire if this is not checked. onEndReached also does // not have a throttle so prevent fetching more history when there is // already a request in flight. return } AppAnalytics.track(PointsEvents.points_screen_activity_fetch_more) dispatch( getHistoryStarted({ getNextPage: true, }) ) } const renderItem: ListRenderItem = ({ item }) => { const historyDefinition = getHistoryDefinition(item) if (!historyDefinition) { return null } return ( ) } const onPressTryAgain = (getNextPage: boolean) => { AppAnalytics.track(PointsEvents.points_screen_activity_try_again_press, { getNextPage, }) dispatch( getHistoryStarted({ getNextPage, }) ) } const onPressLearnMore = () => { AppAnalytics.track(PointsEvents.points_screen_activity_learn_more_press) forwardedRef.current?.close() } const Loading = pointsHistoryStatus === 'loading' ? ( ) : null const EmptyOrError = pointsHistoryStatus === 'errorFirstPage' ? ( {t('points.history.error.title')} {t('points.history.error.subtitle')}