Skip to content

Persist pending melt invoice for startup recovery metadata #69

@Forte11Cuba

Description

@Forte11Cuba

Problem

When finalizePendingMelts() completes a Lightning withdrawal at startup (after an app crash mid-melt), the transaction is saved correctly but without its invoice metadata. This happens because _pendingMeltInvoice is stored in memory only and is lost on app restart.

As a result, recovered melts appear as "Cashu send" instead of "Lightning withdrawal" in the transaction history.

Current behavior

1. User starts melt → _pendingMeltInvoice = invoice (in memory)
2. App crashes mid-melt
3. App restarts → _pendingMeltInvoice = null (memory cleared)
4. finalizePendingMelts() completes the melt successfully
5. _saveMeltMetadata() is never called (no invoice to save)
6. Transaction shows as "Cashu send" in history instead of "Lightning withdrawal"

Expected behavior

Recovered melts should show as "Lightning withdrawal" in history with the correct invoice, same as melts that complete normally.

Proposed solution

Persist pending melt data to SharedPreferences (similar to how _savePendingMintInvoice works for mint quotes), then reconcile after finalizePendingMelts()`:

  1. In getMeltQuote(): save {quoteId, invoice, mintUrl, unit, amount} to SharedPreferences
  2. In melt(): remove the entry on success (normal flow, no change needed)
  3. At startup after finalizePendingMelts(): run a reconciliation that matches outgoing transactions without metadata to persisted melt entries and saves the correct TransactionType.lightning metadata

Impact

Cosmetic only — no fund loss. Transactions are completed correctly, just mislabeled in history.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions