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