import { gql } from 'apollo-server-micro' import { useEffect, useRef, useState } from 'react' import { Button, InputGroup, Modal } from 'react-bootstrap' import { Cell, Pie, PieChart, ResponsiveContainer, Tooltip } from 'recharts' import { getGetServerSideProps } from '../api/ssrApollo' import { Form, Input, SubmitButton } from '../components/form' import LayoutCenter from '../components/layout-center' import { useMutation, useQuery } from '@apollo/client' import Link from 'next/link' import { amountSchema } from '../lib/validate' import Countdown from 'react-countdown' import { abbrNum } from '../lib/format' const REWARDS = gql` { expectedRewards { total sources { name value } } } ` export const getServerSideProps = getGetServerSideProps(REWARDS) export function RewardLine ({ total }) { const [threshold, setThreshold] = useState(0) useEffect(() => { const date = new Date() date.setHours(24, 0, 0, 0) // Central Daylight Saving Time UTC offset in minutes const targetOffset = -5 * 60 const localOffset = -date.getTimezoneOffset() const ts = date.getTime() + ((localOffset - targetOffset) * 60 * 1000) setThreshold(ts) }, []) return ( <> {abbrNum(total)} sats in rewards {threshold && {props.formatted.hours}:{props.formatted.minutes}:{props.formatted.seconds}} />} ) } export default function Rewards ({ data: { expectedRewards: { total, sources } } }) { const { data } = useQuery(REWARDS, { pollInterval: 1000, fetchPolicy: 'cache-and-network' }) if (data) { ({ expectedRewards: { total, sources } } = data) } return (

learn about rewards

) } const COLORS = [ 'var(--secondary)', 'var(--info)', 'var(--success)', 'var(--boost)', 'var(--grey)' ] function GrowthPieChart ({ data }) { return ( { data.map((entry, index) => ( )) } ) } export function DonateButton () { const [show, setShow] = useState(false) const inputRef = useRef(null) const [donateToRewards] = useMutation( gql` mutation donateToRewards($sats: Int!) { donateToRewards(sats: $sats) }`) useEffect(() => { inputRef.current?.focus() }, [show]) return ( <> { setShow(false) }} >
setShow(false)}>X
{ await donateToRewards({ variables: { sats: Number(amount) } }) setShow(false) }} > sats} />
donate
) }