Skip to content

Commit

Permalink
give two more chances to retry an invoice with fee credit and manually
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed Nov 6, 2024
1 parent 947cc1a commit e4fa21f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
25 changes: 22 additions & 3 deletions api/paidAction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export default async function performPaidAction (actionType, args, context) {
context.descriptionHash = context.descriptionHash ?? (paidAction.describeHash ? await paidAction.describeHash(args, context) : undefined)
context.fallbackToSN = context.fallbackToSN ?? true
context.actionAttempt = context.actionAttempt ?? 0
context.retriedWithFeeCredits = context.retriedWithFeeCredits ?? false
context.retriedManually = context.retriedManually ?? false

const { me, forceFeeCredits, cost, description, descriptionHash, sybilFeePercent, fallbackToSN, disableFeeCredit, actionAttempt } = context
let canPerformOptimistically = paidAction.supportsOptimism
Expand Down Expand Up @@ -263,7 +265,22 @@ export async function retryPaidAction (actionType, { invoice, forceFeeCredits },
throw new Error(`retryPaidAction - missing invoice ${actionType}`)
}

if (!failedInvoice.retriable && !forceFeeCredits) { // always retriable with fee credits
let retriable = false
if (failedInvoice.retriable) retriable = true
context.retriedWithFeeCredits = !failedInvoice.retriableWithFeeCredits
context.retriedManually = !failedInvoice.retriableManually

if (forceFeeCredits && failedInvoice.retriableWithFeeCredits) {
retriable = true
context.retriedWithFeeCredits = true
}

if (!retriable && failedInvoice.retriableManually) {
retriable = true
context.retriedManually = true
}

if (!retriable) {
throw new Error(`retryPaidAction - invoice is not retriable ${actionType}`)
}

Expand Down Expand Up @@ -295,7 +312,7 @@ export async function retryPaidAction (actionType, { invoice, forceFeeCredits },
}, { isolationLevel: Prisma.TransactionIsolationLevel.ReadCommitted })
}

export async function createDbInvoice (invoiceData, actionData, { me, models, tx }) {
export async function createDbInvoice (invoiceData, actionData, { me, models, tx, retriedWithFeeCredits, retriedManually }) {
const { invoice: servedBolt11, wallet, maxFee, preimage, innerInvoice: bolt11, isWrapped, isHodl, isFeeCredit } = invoiceData
const { actionId, actionType, optimistic: isOptimisticAction, args } = actionData

Expand Down Expand Up @@ -338,7 +355,9 @@ export async function createDbInvoice (invoiceData, actionData, { me, models, tx
expiresAt,
actionId,
desc: invoiceData.description ?? servedInvoice.description,
retriable: invoiceData.retriable
retriable: invoiceData.retriable,
retriableWithFeeCredits: retriedWithFeeCredits ? invoiceData.retriable : true,
retriableManually: retriedManually ? invoiceData.retriable : true
}

let invoiceEntry
Expand Down
2 changes: 0 additions & 2 deletions components/use-paid-mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ export function usePaidMutation (mutation,
}

if (alwaysShowQROnFailure) {
// TODO give another change to retry manually
// currently this fails because all the retry are exhausted
console.log('show qr code for manual payment')
const retry = await retryPaidAction({ variables: { invoiceId: parseInt(invoice.id) } })
response = retry.data?.retryPaidAction
Expand Down
2 changes: 2 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,8 @@ model Invoice {
comment String?
lud18Data Json?
retriable Boolean @default(false)
retriableWithFeeCredits Boolean @default(true)
retriableManually Boolean @default(true)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
invoiceForward InvoiceForward?
Expand Down

0 comments on commit e4fa21f

Please sign in to comment.