import { gql } from 'graphql-tag' import Button from 'react-bootstrap/Button' import InputGroup from 'react-bootstrap/InputGroup' import { getGetServerSideProps } from '../../api/ssrApollo' import { Form, Input, SubmitButton } from '../../components/form' import Layout from '../../components/layout' import { useMutation, useQuery } from '@apollo/client' import Link from 'next/link' import { amountSchema } from '../../lib/validate' import Countdown from 'react-countdown' import { numWithUnits } from '../../lib/format' import PageLoading from '../../components/page-loading' import { useShowModal } from '../../components/modal' import dynamic from 'next/dynamic' import { SSR } from '../../lib/constants' import { useToast } from '../../components/toast' import { useLightning } from '../../components/lightning' import { ListUsers } from '../../components/user-list' import { Col, Row } from 'react-bootstrap' import { proportions } from '../../lib/madness' import { useData } from '../../components/use-data' const GrowthPieChart = dynamic(() => import('../../components/charts').then(mod => mod.GrowthPieChart), { loading: () =>
Loading...
}) const REWARDS_FULL = gql` { rewards { total time sources { name value } leaderboard { users { id name photoId ncomments(when: $when, from: $from, to: $to) nposts(when: $when, from: $from, to: $to) optional { streak stacked(when: $when, from: $from, to: $to) spent(when: $when, from: $from, to: $to) referrals(when: $when, from: $from, to: $to) } } } } } ` const REWARDS = gql` { rewards { total time sources { name value } } } ` export const getServerSideProps = getGetServerSideProps({ query: REWARDS_FULL }) export function RewardLine ({ total, time }) { return ( <> {numWithUnits(total)} in rewards {time && {props.formatted.days ? ` ${props.formatted.days}d ${props.formatted.hours}h ${props.formatted.minutes}m ${props.formatted.seconds}s` : ` ${props.formatted.hours}:${props.formatted.minutes}:${props.formatted.seconds}`} } />} ) } export default function Rewards ({ ssrData }) { // only poll for updates to rewards and not leaderboard const { data: rewardsData } = useQuery( REWARDS, SSR ? {} : { pollInterval: 1000, nextFetchPolicy: 'cache-and-network' }) const { data } = useQuery(REWARDS_FULL) if (!data && !ssrData) return let { rewards: [{ total, sources, time, leaderboard }] } = useData(data, ssrData) if (rewardsData?.rewards?.length > 0) { total = rewardsData.rewards[0].total sources = rewardsData.rewards[0].sources time = rewardsData.rewards[0].time } function EstimatedReward ({ rank }) { return (
estimated reward: {numWithUnits(Math.floor(total * proportions[rank - 1]))}
) } return (

learn about rewards

{leaderboard?.users &&

leaderboard

}
) } export function DonateButton () { const showModal = useShowModal() const toaster = useToast() const strike = useLightning() const [donateToRewards] = useMutation( gql` mutation donateToRewards($sats: Int!, $hash: String, $hmac: String) { donateToRewards(sats: $sats, hash: $hash, hmac: $hmac) }`) return ( <> ) }