Skip to content

Custom memo for Credit/Debit flows. - #4162

Merged
motorina0 merged 7 commits into
lnbits:devfrom
DoktorShift:dev
Sep 14, 2026
Merged

motorina0 merged 7 commits into
lnbits:devfrom
DoktorShift:dev

Conversation

@DoktorShift

Copy link
Copy Markdown
Collaborator

Closes #4155

Custom memo for superuser credit/debit

Superusers could not set a custom memo when crediting or debiting a wallet —
the memo was hardcoded to "Admin credit" / "Admin debit", and users had no
way of knowing why their balance changed.

API

PUT /users/api/v1/balance now accepts an optional memo
(max 640 chars, same cap as invoice memos):

{ "id": "wallet_id", "amount": 1000, "memo": "Beer for the Horde" }

Omitting memo keeps a sensible default, so existing calls work unchanged.

Recognition in the user's wallet

Admin credit/debit payments are now tagged (extra.tag = "admin"), so the
payment list shows the familiar yellow #admin badge — the same mechanism
extensions use. Since the badge carries the provenance, the default memos are
now simply "Credit" / "Debit" instead of repeating it; with a custom memo the
row reads #admin Beer for the Horde. The tag is searchable and included in
CSV exports and extra.tag for API consumers.

Bildschirmfoto 2026-09-08 um 12 29 06

UI

The credit/debit popup (users area + wallet page) now has a memo field, plus
some small UX fixes:

  • opens below its button with a soft transition instead of covering it
  • visible action button that shows Credit and flips to a red Debit
    when the amount is negative — Enter still submits
  • amount field starts empty instead of a prefilled 0 that had to be
    deleted before typing a negative value; empty/zero submits are blocked
  • removed the decorative pencil icon, numeric input on both popup variants
  • the wallets table in the users area refreshes after a credit/debit
Bildschirmfoto 2026-09-08 um 12 28 40

The admin notification for balance updates now includes the memo as well.

Tests cover default and custom memos on both credit and debit, the admin
tag, and memo length validation.

@codecov

codecov Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.08%. Comparing base (8c7e5c2) to head (aef97d0).
⚠️ Report is 267 commits behind head on dev.

Additional details and impacted files
@@             Coverage Diff             @@
##              dev    #4162       +/-   ##
===========================================
+ Coverage   56.50%   67.08%   +10.57%     
===========================================
  Files         123      164       +41     
  Lines       16914    25551     +8637     
===========================================
+ Hits         9557    17140     +7583     
- Misses       7357     8411     +1054     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@motorina0

Copy link
Copy Markdown
Collaborator

LGTM, but unit test fails.

The superuser endpoint PUT /users/api/v1/balance always created the
internal payment with a hardcoded "Admin credit" or "Admin debit" memo,
leaving no way to tell the affected user why their balance changed.

- add an optional memo field to UpdateBalance (max 640 chars, same cap
  as invoice memos) and pass it through update_wallet_balance for both
  the credit and the debit path
- tag these payments with extra.tag = "admin" so the payment list shows
  the #admin badge, exactly like extension payments; provenance is
  carried by the tag, so the default memos slim down to "Credit" and
  "Debit" instead of duplicating the badge
- include the memo in the balance_update admin notification
Extend the superuser credit/debit popup with an optional memo input and
polish the interaction:

- popup opens below its trigger button with a soft jump-down transition
  instead of covering it
- visible sign-aware action button: shows Credit (primary) and flips to
  Debit (negative) when the amount is negative, with Enter kept as the
  keyboard shortcut; submission is guarded against empty and zero
  amounts
- amount field starts empty instead of a prefilled 0 that had to be
  deleted before typing a negative value, and both popup variants use a
  numeric input
- remove the decorative pencil icon that suggested an action it did not
  have
- emit credit-value on success so the users page refreshes the wallets
  table, and show the parsed amount in the success notification
- limit memos to 639 bytes, the bolt11 description limit; a 640
  character or multibyte memo crashed invoice encoding with a cryptic
  error at the previously advertised maximum
- trim whitespace-only memos before falling back to the default
- report the post-update balance in the admin notification instead of
  the pre-update snapshot
- guard against a second submit while a request is in flight and show
  the loading state on the action button
- clear the memo when the popup closes without submitting so it cannot
  attach to a later balance update
- declare the credit-value emit and listen for it on the wallet page,
  replacing an unused callback prop, so the displayed balance also
  refreshes after a debit
@motorina0
motorina0 merged commit 6fb8b97 into lnbits:dev Sep 14, 2026
31 checks passed
@motorina0 motorina0 added this to the 1.6.2 milestone Sep 21, 2026
motorina0 added a commit to dsbaars/lnbits that referenced this pull request Oct 16, 2026
UniSyncInc2212 added a commit to UniSyncInc2212/lnbits that referenced this pull request Nov 6, 2026
* Remove a user wallet on the second delete instead of returning 404 (lnbits#4150)

* Custom memo for Credit/Debit flows. (lnbits#4162)

Co-authored-by: Vlad Stan <[email protected]>

* Merge commit from fork

* Delete cliche (lnbits#4118)

* feat: asset refactor, phoenixd/sparkl2 included, add dmg (lnbits#4167)

* fix: posgres export (lnbits#4187)

* chore(deps): bump nanoid from 3.3.16 to 3.3.19 (lnbits#4181)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix: paid install QR code never shown for WASM extensions with permissions (lnbits#4195)

Co-authored-by: bitkarrot <[email protected]>

* feat: support sending to BOLT12 offers (lnbits#2581)

Pay lno1 offers through the existing /api/v1/payments path. Offers are
validated fail-closed, require an explicit sat amount, and reuse the
BOLT11 external-payment lock/fee-reserve/timeout flow instead of a
parallel pay path.

CLN and CLN REST fetch an invoice then pay it; Phoenixd and Eclair use
payoffer. Unsupported funding sources are rejected before a payment row
is created.

Co-authored-by: UniSyncInc2212 <[email protected]>

* test: start app fixture for BOLT12 payment tests

Request the session app fixture so isolated pytest runs migrate the
database before paying offers.

Co-authored-by: UniSyncInc2212 <[email protected]>

* fix: address BOLT12 send review notes

Move EclairWallet private helpers to the bottom of the class, document
the unique placeholder payment hash for reusable offers, add Feature.bolt12
and pay_offer on LNbitsWallet, disable Pay when offer amount is 0, and
name supported BOLT12 funding sources in the error and docs.

Co-authored-by: UniSyncInc2212 <[email protected]>

* fix: disable BOLT12 Pay using the amount field directly

Bind q-btn disable to parse.data.amount so a zero offer amount cannot
submit, and skip payInvoice when the offer amount is missing.

Co-authored-by: UniSyncInc2212 <[email protected]>

* fix: render a statically disabled Pay button when offer amount is 0

Use a separate always-disabled q-btn when bolt12AmountMissing so the
control cannot submit, instead of binding disable with a greater-than
expression in the in-DOM template.

Co-authored-by: UniSyncInc2212 <[email protected]>

* Squashed commit of the following:

commit d2a4e66
Author: Vlad Stan <[email protected]>
Date:   Wed Sep 16 13:21:35 2026 +0300

    refactor: extract check

commit d3423c3
Author: Vlad Stan <[email protected]>
Date:   Wed Sep 16 13:00:01 2026 +0300

    refactor: extract `_pay_from_wallet`

commit 1a868bb
Author: Vlad Stan <[email protected]>
Date:   Wed Sep 16 12:41:08 2026 +0300

    fix: param name

commit 96568e3
Author: Vlad Stan <[email protected]>
Date:   Wed Sep 16 12:25:53 2026 +0300

    refactor: extract validation

* refactor: move bolt12 logic to utils

* refactor: use payment_request for invoice and offer inputs

* test: add bot12 regtest

commit 4cb82a6
Author: alan <[email protected]>
Date:   Thu Sep 17 07:45:01 2026 +0000

    chore: make bundle [skip ci]

commit 010ef37
Author: Vlad Stan <[email protected]>
Date:   Thu Sep 17 10:35:34 2026 +0300

    fix: more fee rate fixes

commit b7f40d6
Author: Vlad Stan <[email protected]>
Date:   Thu Sep 17 10:30:38 2026 +0300

    test: fix feerate

commit 63066f8
Author: Vlad Stan <[email protected]>
Date:   Thu Sep 17 10:24:05 2026 +0300

    test: partial eclair regtest fix

commit fdbcd98
Author: Vlad Stan <[email protected]>
Date:   Thu Sep 17 09:54:33 2026 +0300

    test: fix test filter

commit 01ff9df
Author: Vlad Stan <[email protected]>
Date:   Wed Sep 16 19:37:05 2026 +0300

    test: add bolt12 regtest

* feat: add bolt12 payer_note (memo)

commit 3f80ecd
Author: Vlad Stan <[email protected]>
Date:   Fri Sep 18 11:01:28 2026 +0300

    chore: clean-up

commit af9b7ab
Author: Vlad Stan <[email protected]>
Date:   Thu Sep 17 15:30:40 2026 +0300

    feat: show offer memo and amount if present

commit b237802
Author: Vlad Stan <[email protected]>
Date:   Thu Sep 17 15:09:22 2026 +0300

    chore: make bundle

commit 5fe3cc8
Author: Vlad Stan <[email protected]>
Date:   Thu Sep 17 14:56:43 2026 +0300

    feat: show offer on ui

commit f7c7c93
Author: Vlad Stan <[email protected]>
Date:   Thu Sep 17 14:47:22 2026 +0300

    test: fix tests

commit 4f49729
Author: Vlad Stan <[email protected]>
Date:   Thu Sep 17 14:18:22 2026 +0300

    refactor: use `memo` for public api

commit 2307dfe
Author: alan <[email protected]>
Date:   Thu Sep 17 11:08:54 2026 +0000

    chore: make bundle [skip ci]

commit 5ef286b
Author: Vlad Stan <[email protected]>
Date:   Thu Sep 17 13:56:57 2026 +0300

    test: payer_note regtest

commit 3551e85
Author: Vlad Stan <[email protected]>
Date:   Thu Sep 17 13:25:29 2026 +0300

    fix: optional payer_note for eclair

commit a803991
Author: Vlad Stan <[email protected]>
Date:   Thu Sep 17 13:23:09 2026 +0300

    feat: payer_note first

* feat: save the bolt12 invoice when available

commit c4f9601
Author: Vlad Stan <[email protected]>
Date:   Fri Sep 18 12:55:16 2026 +0300

    refactor: remove un-necessary type

commit b60f43f
Author: Vlad Stan <[email protected]>
Date:   Fri Sep 18 12:02:11 2026 +0300

    doc: clean-up

commit 6f40071
Author: Vlad Stan <[email protected]>
Date:   Thu Sep 17 19:15:28 2026 +0300

    feat: save `payment_request` for bolt12 invoices

commit 422332a
Author: Vlad Stan <[email protected]>
Date:   Thu Sep 17 15:38:13 2026 +0300

    Squashed commit of the following:

    commit af9b7ab
    Author: Vlad Stan <[email protected]>
    Date:   Thu Sep 17 15:30:40 2026 +0300

        feat: show offer memo and amount if present

    commit b237802
    Author: Vlad Stan <[email protected]>
    Date:   Thu Sep 17 15:09:22 2026 +0300

        chore: make bundle

    commit 5fe3cc8
    Author: Vlad Stan <[email protected]>
    Date:   Thu Sep 17 14:56:43 2026 +0300

        feat: show offer on ui

    commit f7c7c93
    Author: Vlad Stan <[email protected]>
    Date:   Thu Sep 17 14:47:22 2026 +0300

        test: fix tests

    commit 4f49729
    Author: Vlad Stan <[email protected]>
    Date:   Thu Sep 17 14:18:22 2026 +0300

        refactor: use `memo` for public api

    commit 2307dfe
    Author: alan <[email protected]>
    Date:   Thu Sep 17 11:08:54 2026 +0000

        chore: make bundle [skip ci]

    commit 5ef286b
    Author: Vlad Stan <[email protected]>
    Date:   Thu Sep 17 13:56:57 2026 +0300

        test: payer_note regtest

    commit 3551e85
    Author: Vlad Stan <[email protected]>
    Date:   Thu Sep 17 13:25:29 2026 +0300

        fix: optional payer_note for eclair

    commit a803991
    Author: Vlad Stan <[email protected]>
    Date:   Thu Sep 17 13:23:09 2026 +0300

        feat: payer_note first

* fix: cln amount change

* fix: prevent BOLT12 payments from being refunded after timeout

* fix: keep ambiguous CLNRest offer payments pending

* fix: wallet fees and fake wallet

commit d12c0fe
Author: Vlad Stan <[email protected]>
Date:   Mon Sep 21 16:09:10 2026 +0300

    feat: create fake bolt12 invoice

commit 393ab9d
Author: Vlad Stan <[email protected]>
Date:   Mon Sep 21 15:45:55 2026 +0300

    feat: add `lnbits_funding_source_pay_offer_wait_seconds` settings

commit 04ebf30
Author: Vlad Stan <[email protected]>
Date:   Mon Sep 21 13:34:06 2026 +0300

    fix: safer phoenixd status check

commit 88b3072
Author: Vlad Stan <[email protected]>
Date:   Mon Sep 21 13:15:36 2026 +0300

    fix: eclair fee

* chore: make bundle

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: monasco <[email protected]>
Co-authored-by: DrShift <[email protected]>
Co-authored-by: Vlad Stan <[email protected]>
Co-authored-by: Arc <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Bitkarrot <[email protected]>
Co-authored-by: bitkarrot <[email protected]>
Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: UniSyncInc2212 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature request] Allow custom memo for wallet balance updates

2 participants