From 9f06fd65ee716aa0f5ce5a77000af3f797ecd557 Mon Sep 17 00:00:00 2001 From: Keyan <34140557+huumn@users.noreply.github.com> Date: Wed, 25 Sep 2024 13:32:52 -0500 Subject: [PATCH] UX latency enhancements for paid actions (#1434) * prevent multiple retries & pulse retry button * fix lint * don't wait for settlement on pessimistic zaps * optimistic act modal --- api/paidAction/index.js | 15 +-- api/resolvers/paidAction.js | 9 +- components/comment.js | 4 +- components/form.js | 2 +- components/invoice.js | 18 +++- components/item-act.js | 22 +++-- components/item-info.js | 161 ++++++++++++++++++-------------- components/item.js | 4 +- components/notifications.js | 24 +++-- components/use-paid-mutation.js | 7 +- styles/globals.scss | 14 +++ worker/index.js | 4 - 12 files changed, 177 insertions(+), 107 deletions(-) diff --git a/api/paidAction/index.js b/api/paidAction/index.js index e18ec8ee..3ae9cfb3 100644 --- a/api/paidAction/index.js +++ b/api/paidAction/index.js @@ -160,7 +160,7 @@ async function performPessimisticAction (actionType, args, context) { export async function retryPaidAction (actionType, args, context) { const { models, me } = context - const { invoiceId } = args + const { invoice: failedInvoice } = args console.log('retryPaidAction', actionType, args) @@ -181,18 +181,13 @@ export async function retryPaidAction (actionType, args, context) { throw new Error(`retryPaidAction - action does not support retrying ${actionType}`) } - if (!invoiceId) { - throw new Error(`retryPaidAction - missing invoiceId ${actionType}`) + if (!failedInvoice) { + throw new Error(`retryPaidAction - missing invoice ${actionType}`) } context.optimistic = true context.me = await models.user.findUnique({ where: { id: me.id } }) - const failedInvoice = await models.invoice.findUnique({ where: { id: invoiceId, actionState: 'FAILED' } }) - if (!failedInvoice) { - throw new Error(`retryPaidAction ${actionType} - invoice ${invoiceId} not found or not in failed state`) - } - const { msatsRequested, actionId } = failedInvoice context.cost = BigInt(msatsRequested) context.actionId = actionId @@ -204,7 +199,7 @@ export async function retryPaidAction (actionType, args, context) { // update the old invoice to RETRYING, so that it's not confused with FAILED await tx.invoice.update({ where: { - id: invoiceId, + id: failedInvoice.id, actionState: 'FAILED' }, data: { @@ -216,7 +211,7 @@ export async function retryPaidAction (actionType, args, context) { const invoice = await createDbInvoice(actionType, args, context, invoiceArgs) return { - result: await action.retry({ invoiceId, newInvoiceId: invoice.id }, context), + result: await action.retry({ invoiceId: failedInvoice.id, newInvoiceId: invoice.id }, context), invoice, paymentMethod: 'OPTIMISTIC' } diff --git a/api/resolvers/paidAction.js b/api/resolvers/paidAction.js index 41b0c253..23327903 100644 --- a/api/resolvers/paidAction.js +++ b/api/resolvers/paidAction.js @@ -56,7 +56,14 @@ export default { throw new Error('Invoice not found') } - const result = await retryPaidAction(invoice.actionType, { invoiceId }, { models, me, lnd }) + if (invoice.actionState !== 'FAILED') { + if (invoice.actionState === 'PAID') { + throw new Error('Invoice is already paid') + } + throw new Error(`Invoice is not in failed state: ${invoice.actionState}`) + } + + const result = await retryPaidAction(invoice.actionType, { invoice }, { models, me, lnd }) return { ...result, diff --git a/components/comment.js b/components/comment.js index 6ea35bdf..176ab6f1 100644 --- a/components/comment.js +++ b/components/comment.js @@ -94,7 +94,7 @@ export function CommentFlat ({ item, rank, siblingComments, ...props }) { export default function Comment ({ item, children, replyOpen, includeParent, topLevel, - rootText, noComments, noReply, truncate, depth, pin + rootText, noComments, noReply, truncate, depth, pin, setDisableRetry, disableRetry }) { const [edit, setEdit] = useState() const { me } = useMe() @@ -169,6 +169,8 @@ export default function Comment ({ embellishUser={op && <> {op}} onQuoteReply={quoteReply} nested={!includeParent} + setDisableRetry={setDisableRetry} + disableRetry={disableRetry} extraInfo={ <> {includeParent && } diff --git a/components/form.js b/components/form.js index 169f61e9..350d1d48 100644 --- a/components/form.js +++ b/components/form.js @@ -53,7 +53,7 @@ export function SubmitButton ({ return (