803acd1fc4
* invoices are no longer deleted to prevent double-spends but marked as confirmed. therefore, during checkInvoice, we also check if the invoice is already confirmed. * instead of showing FundError (with "fund wallet" and "pay invoice" as options), we now always immediately show an invoice * since flagging, paying bounties and poll voting used FundError but only allowed spending from balance, they now also support paying per invoice Co-authored-by: ekzyis <ek@stacker.news>
63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
import { gql, useMutation } from '@apollo/client'
|
|
import Dropdown from 'react-bootstrap/Dropdown'
|
|
import { useShowModal } from './modal'
|
|
import { useToast } from './toast'
|
|
import { InvoiceModal, payOrLoginError } from './invoice'
|
|
import { DONT_LIKE_THIS_COST } from '../lib/constants'
|
|
|
|
export default function DontLikeThisDropdownItem ({ id }) {
|
|
const toaster = useToast()
|
|
const showModal = useShowModal()
|
|
|
|
const [dontLikeThis] = useMutation(
|
|
gql`
|
|
mutation dontLikeThis($id: ID!, $hash: String, $hmac: String) {
|
|
dontLikeThis(id: $id, hash: $hash, hmac: $hmac)
|
|
}`, {
|
|
update (cache) {
|
|
cache.modify({
|
|
id: `Item:${id}`,
|
|
fields: {
|
|
meDontLike () {
|
|
return true
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
)
|
|
|
|
return (
|
|
<Dropdown.Item
|
|
onClick={async () => {
|
|
try {
|
|
await dontLikeThis({
|
|
variables: { id },
|
|
optimisticResponse: { dontLikeThis: true }
|
|
})
|
|
toaster.success('item flagged')
|
|
} catch (error) {
|
|
console.error(error)
|
|
if (payOrLoginError(error)) {
|
|
showModal(onClose => {
|
|
return (
|
|
<InvoiceModal
|
|
amount={DONT_LIKE_THIS_COST}
|
|
onPayment={async ({ hash, hmac }) => {
|
|
await dontLikeThis({ variables: { id, hash, hmac } })
|
|
toaster.success('item flagged')
|
|
}}
|
|
/>
|
|
)
|
|
})
|
|
} else {
|
|
toaster.danger('failed to flag item')
|
|
}
|
|
}
|
|
}}
|
|
>
|
|
flag
|
|
</Dropdown.Item>
|
|
)
|
|
}
|