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 (
{numWithUnits(baseFee, { abbreviate: false })} |
{parentId ? 'reply' : 'post'} fee |
{hasImgLink &&
x 10 |
image/link fee |
}
{repetition > 0 &&
x 10{repetition} |
{repetition} {parentId ? 'repeat or self replies' : 'posts'} in 10m |
}
{boost > 0 &&
+ {numWithUnits(boost, { abbreviate: false })} |
boost |
}
{numWithUnits(cost, { abbreviate: false })} |
total fee |
)
}
function AnonInfo () {
const showModal = useShowModal()
return (
showModal(onClose =>
You are posting without an account
- You'll pay by invoice
- Your content will be content-joined (get it?!) under the @anon account
- Any sats your content earns will go toward rewards
- We won't be able to notify you when you receive replies
btw if you don't need to be anonymous, posting is cheaper with an account
)
}
/>
)
}
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)
}, [formik?.getFieldProps('cost').value, 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 &&
<>
{numWithUnits(paidSats, { abbreviate: false })} |
{parentId ? 'reply' : 'post'} fee |
x 10 |
image/link fee |
- {numWithUnits(paidSats, { abbreviate: false })} |
already paid |
>}
{boost > 0 &&
+ {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) - (formik?.initialValues?.boost || 0)
const addImgLink = hasImgLink && !hadImgLink
const cost = (addImgLink ? paidSats * 9 : 0) + Number(boost)
useEffect(() => {
formik?.setFieldValue('cost', cost)
}, [formik?.getFieldProps('cost').value, cost])
const show = alwaysShow || !formik?.isSubmitting
return (
= 0 ? cost : 0, { abbreviate: false })}>
{text}{cost > 0 && show && {numWithUnits(cost, { abbreviate: false })}}
{cost > 0 && show &&
}
)
}