Fix empty invoice creation attempts

I stumbled across this while checking if anons can edit their items.

I monkey patched the code to make it possible (so they can see the 'edit' button) and tried to edit an item but I got this error:

  Variable "$amount" of required type "Int!" was not provided.

I fixed this even though this function should never be called without an amount anyway. It will return a sane error in that case now.
This commit is contained in:
ekzyis 2023-08-11 05:11:41 +02:00
parent 28b4588a12
commit 41f46cf41e
2 changed files with 5 additions and 1 deletions

View File

@ -140,6 +140,10 @@ export function EditFeeButton ({ paidSats, hadImgLink, hasImgLink, ChildButton,
const addImgLink = hasImgLink && !hadImgLink
const cost = (addImgLink ? paidSats * 9 : 0) + Number(boost)
useEffect(() => {
formik.setFieldValue('cost', cost)
}, [cost])
const show = alwaysShow || !formik?.isSubmitting
return (
<div className='d-flex align-items-center'>

View File

@ -215,7 +215,7 @@ export const useInvoiceable = (fn, options = defaultOptions) => {
if (!me && options.requireSession) {
throw new Error('you must be logged in')
}
if (me && !options.forceInvoice) {
if (!amount || (me && !options.forceInvoice)) {
try {
return await fn(amount, ...args)
} catch (error) {