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' const REWARDS = gql` { expectedRewards { total sources { name value } } } ` export const getServerSideProps = getGetServerSideProps(REWARDS) export default function Rewards ({ data: { expectedRewards: { total, sources } } }) { const { data } = useQuery(REWARDS, { pollInterval: 1000 }) if (data) { ({ expectedRewards: { total, sources } } = data) } return ( {total} sats to be rewarded today 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(true)}>DONATE TO REWARDS { setShow(false) }} > setShow(false)}>X { await donateToRewards({ variables: { sats: Number(amount) } }) setShow(false) }} > sats} /> donate > ) }