import { useEffect } from 'react' import Table from 'react-bootstrap/Table' import ActionTooltip from './action-tooltip' import Info from './info' import styles from './fee-button.module.css' import { gql, useQuery } from '@apollo/client' import { useFormikContext } from 'formik' import { SSR, ANON_COMMENT_FEE, ANON_POST_FEE } from '../lib/constants' import { numWithUnits } from '../lib/format' import { useMe } from './me' import AnonIcon from '../svgs/spy-fill.svg' import { useShowModal } from './modal' import Link from 'next/link' function Receipt ({ cost, repetition, hasImgLink, baseFee, parentId, boost }) { return ( {hasImgLink && } {repetition > 0 && } {boost > 0 && }
{numWithUnits(baseFee, { abbreviate: false })} {parentId ? 'reply' : 'post'} fee
x 10 image/link fee
x 10{repetition} {repetition} {parentId ? 'repeat or self replies' : 'posts'} in 10m
+ {numWithUnits(boost, { abbreviate: false })} boost
{numWithUnits(cost, { abbreviate: false })} total fee
) } function AnonInfo () { const showModal = useShowModal() return ( showModal(onClose =>
Hey sneaky! You are posting without an account.
  1. You'll pay by invoice
  2. Your content will be content-joined (get it?!) under the @anon account
  3. Any sats your content earns will go toward rewards
  4. We won't be able to notify about replies
) } /> ) } export default function FeeButton ({ parentId, hasImgLink, baseFee, ChildButton, variant, text, alwaysShow, disabled }) { const me = useMe() baseFee = me ? baseFee : (parentId ? ANON_COMMENT_FEE : ANON_POST_FEE) const query = parentId ? gql`{ itemRepetition(parentId: "${parentId}") }` : gql`{ itemRepetition }` const { data } = useQuery(query, SSR ? {} : { pollInterval: 1000, nextFetchPolicy: 'cache-and-network' }) const repetition = me ? data?.itemRepetition || 0 : 0 const formik = useFormikContext() const boost = Number(formik?.values?.boost) || 0 const cost = baseFee * (hasImgLink ? 10 : 1) * Math.pow(10, repetition) + Number(boost) useEffect(() => { formik.setFieldValue('cost', cost) }, [cost]) const show = alwaysShow || !formik?.isSubmitting return (
{text}{cost > 1 && show && {numWithUnits(cost, { abbreviate: false })}} {!me && } {cost > baseFee && show && }
) } function EditReceipt ({ cost, paidSats, addImgLink, boost, parentId }) { return ( {addImgLink && <> } {boost > 0 && }
{numWithUnits(paidSats, { abbreviate: false })} {parentId ? 'reply' : 'post'} fee
x 10 image/link fee
- {numWithUnits(paidSats, { abbreviate: false })} already paid
+ {numWithUnits(boost, { abbreviate: false })} boost
{numWithUnits(cost)} total fee
) } export function EditFeeButton ({ paidSats, hadImgLink, hasImgLink, ChildButton, variant, text, alwaysShow, parentId }) { const formik = useFormikContext() const boost = formik?.values?.boost || 0 const addImgLink = hasImgLink && !hadImgLink const cost = (addImgLink ? paidSats * 9 : 0) + Number(boost) const show = alwaysShow || !formik?.isSubmitting return (
{text}{cost > 0 && show && {numWithUnits(cost, { abbreviate: false })}} {cost > 0 && show && }
) }