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 { useMe } from './me'
import { ANON_COMMENT_FEE, ANON_POST_FEE } from '../lib/constants'
import { useEffect } from 'react'
function Receipt ({ cost, repetition, hasImgLink, baseFee, parentId, boost }) {
return (
{baseFee} sats |
{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 &&
+ {boost} sats |
boost |
}
{cost} sats |
total fee |
)
}
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, { 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 > baseFee && show && {cost} sats}
{cost > baseFee && show &&
}
)
}
function EditReceipt ({ cost, paidSats, addImgLink, boost, parentId }) {
return (
{addImgLink &&
<>
{paidSats} sats |
{parentId ? 'reply' : 'post'} fee |
x 10 |
image/link fee |
- {paidSats} sats |
already paid |
>}
{boost > 0 &&
+ {boost} sats |
boost |
}
{cost} sats |
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 && {cost} sats}
{cost > 0 && show &&
}
)
}