import React, { FC, useContext, useEffect } from "react"; import { Center, HStack, Spinner, Text, View, VStack } from "native-base"; import { NewsFeedContext, NewsFeedProvider, useTimer } from "@gooddollar/web3sdk-v2"; import moment from "moment"; import { isEmpty } from "lodash"; import { useWizard } from "react-use-wizard"; import { Platform } from "react-native"; import { NewsFeed } from "../../newsfeed"; import { Image } from "../../../core/images"; import { TransText, TransTitle } from "../../../core/layout"; import { TransactionList } from "../components/TransactionStateCard"; import { useClaimContext } from "../context"; import { GoodButton } from "../../../core/buttons"; import BillyHearts from "../../../assets/gifs/billy-hearts.gif"; import SwitchArrows from "../../../assets/images/goodid/switch-arrows.png"; const getEarliestClaimTime = (times: Date[], claimTime: Date) => { const allTimes = [...times, claimTime]; const earliestTime = allTimes.reduce((prev, curr) => (prev < curr ? prev : curr)); return moment(earliestTime).toDate(); }; const NextClaim = ({ poolTimes, nextClaimTime, onReset }: { poolTimes: Date[] | undefined; nextClaimTime: Date; onReset?: () => void; }) => { const { goToStep } = useWizard(); const [earliestNextTime, setEarliestTime] = React.useState(undefined); const [nextClaim, , setClaimTime] = useTimer(earliestNextTime); useEffect(() => { if (earliestNextTime) { const earliestMoment = moment(earliestNextTime); if (earliestMoment.isBefore(moment())) { onReset?.(); goToStep(2); } } const nextClaim = poolTimes && !isEmpty(poolTimes) ? getEarliestClaimTime(poolTimes, nextClaimTime) : nextClaimTime; setEarliestTime(nextClaim); }, [poolTimes, nextClaimTime]); useEffect(() => setClaimTime(earliestNextTime), [earliestNextTime?.toString()]); return ( {nextClaim ? ( <> {Platform.OS === "web" ? billy-hearts : null} {nextClaim} ) : ( )} ); }; const NewsFeedWrapper = ({ onNews }: { onNews: () => void }) => { const { feed } = useContext(NewsFeedContext); return ( "} fontFamily="subheading" color="primary" fontSize="ms" fontWeight="700" /> ); }; export const PostClaim: FC = () => { const { claimPools, claimDetails, claimedAlt, poolsDetails, withNewsFeed, newsProps, onNews, onReset, onTxDetailsPress, switchChain } = useClaimContext(); const { transactionList } = claimPools ?? {}; const { hasClaimed, altChain } = claimedAlt ?? {}; const { nextClaimTime, isWhitelisted } = claimDetails; const poolTimes: Date[] | undefined = poolsDetails?.map(pool => pool.nextClaimTime); if ((isWhitelisted as any) === undefined) return ; return ( {poolTimes || nextClaimTime ? : null} {!hasClaimed ? (
switchChain(altChain)} flexDir="row"> switch-arrows
) : null} {withNewsFeed ? ( ) : null}
{transactionList === undefined ? ( ) : transactionList.length === 0 ? ( ) : ( )}
); };