Compare commits
No commits in common. "6e1d67b3c0b880774940f33b3d0a8b1597448767" and "ca11ac9fb85547096d61f398443f7d0b649a5e1f" have entirely different histories.
6e1d67b3c0
...
ca11ac9fb8
@ -59,7 +59,6 @@ export default function ItemAct ({ onClose, item, down, children, abortSignal })
|
||||
}, [onClose, item.id])
|
||||
|
||||
const act = useAct()
|
||||
const strike = useLightning()
|
||||
|
||||
const onSubmit = useCallback(async ({ amount, hash, hmac }) => {
|
||||
if (abortSignal && zapUndoTrigger({ me, amount })) {
|
||||
@ -83,7 +82,6 @@ export default function ItemAct ({ onClose, item, down, children, abortSignal })
|
||||
optimisticResponse: me
|
||||
? {
|
||||
act: {
|
||||
__typename: 'ItemActPaidAction',
|
||||
result: {
|
||||
id: item.id, sats: Number(amount), act: down ? 'DONT_LIKE_THIS' : 'TIP', path: item.path
|
||||
}
|
||||
@ -92,13 +90,12 @@ export default function ItemAct ({ onClose, item, down, children, abortSignal })
|
||||
: undefined,
|
||||
// don't close modal immediately because we want the QR modal to stack
|
||||
onCompleted: () => {
|
||||
strike()
|
||||
onClose?.()
|
||||
if (!me) setItemMeAnonSats({ id: item.id, amount })
|
||||
}
|
||||
})
|
||||
addCustomTip(Number(amount))
|
||||
}, [me, act, down, item.id, onClose, abortSignal, strike])
|
||||
}, [me, act, down, item.id, onClose, abortSignal])
|
||||
|
||||
return (
|
||||
<Form
|
||||
@ -177,6 +174,7 @@ export function useAct ({ query = ACT_MUTATION, ...options } = {}) {
|
||||
// because the mutation name we use varies,
|
||||
// we need to extract the result/invoice from the response
|
||||
const getPaidActionResult = data => Object.values(data)[0]
|
||||
const strike = useLightning()
|
||||
|
||||
const [act] = usePaidMutation(query, {
|
||||
...options,
|
||||
@ -185,6 +183,7 @@ export function useAct ({ query = ACT_MUTATION, ...options } = {}) {
|
||||
if (!response) return
|
||||
modifyActCache(cache, response)
|
||||
options?.update?.(cache, { data })
|
||||
if (response.result) strike()
|
||||
},
|
||||
onPayError: (e, cache, { data }) => {
|
||||
const response = getPaidActionResult(data)
|
||||
@ -206,7 +205,7 @@ export function useAct ({ query = ACT_MUTATION, ...options } = {}) {
|
||||
export function useZap () {
|
||||
const act = useAct()
|
||||
const me = useMe()
|
||||
const strike = useLightning()
|
||||
|
||||
const toaster = useToast()
|
||||
|
||||
return useCallback(async ({ item, abortSignal }) => {
|
||||
@ -216,11 +215,10 @@ export function useZap () {
|
||||
const sats = nextTip(meSats, { ...me?.privates })
|
||||
|
||||
const variables = { id: item.id, sats, act: 'TIP' }
|
||||
const optimisticResponse = { act: { __typename: 'ItemActPaidAction', result: { path: item.path, ...variables } } }
|
||||
const optimisticResponse = { act: { result: { path: item.path, ...variables } } }
|
||||
|
||||
try {
|
||||
await abortSignal.pause({ me, amount: sats })
|
||||
strike()
|
||||
await act({ variables, optimisticResponse })
|
||||
} catch (error) {
|
||||
if (error instanceof InvoiceCanceledError || error instanceof ActCanceledError) {
|
||||
@ -231,7 +229,7 @@ export function useZap () {
|
||||
|
||||
toaster.danger('zap failed: ' + reason)
|
||||
}
|
||||
}, [me?.id, strike])
|
||||
}, [me?.id])
|
||||
}
|
||||
|
||||
export class ActCanceledError extends Error {
|
||||
|
@ -51,7 +51,7 @@ export default function PayBounty ({ children, item }) {
|
||||
const variables = { id: item.id, sats: root.bounty, act: 'TIP' }
|
||||
const act = useAct({
|
||||
variables,
|
||||
optimisticResponse: { act: { __typename: 'ItemActPaidAction', result: { ...variables, path: item.path } } },
|
||||
optimisticResponse: { act: { result: { ...variables, path: item.path } } },
|
||||
...payBountyCacheMods
|
||||
})
|
||||
|
||||
|
@ -23,7 +23,7 @@ export default function Poll ({ item }) {
|
||||
onClick={me
|
||||
? async () => {
|
||||
const variables = { id: v.id }
|
||||
const optimisticResponse = { pollVote: { __typename: 'PollVotePaidAction', result: { id: v.id } } }
|
||||
const optimisticResponse = { pollVote: { result: { id: v.id } } }
|
||||
try {
|
||||
await pollVote({
|
||||
variables,
|
||||
|
Loading…
x
Reference in New Issue
Block a user