Skip to content

refactor: extract handlePaymentReceived helper in subscribeInvoice#3822

Merged
kaloudis merged 1 commit intoZeusLN:masterfrom
myxmaster:refactor-handle-payment-received
Apr 4, 2026
Merged

refactor: extract handlePaymentReceived helper in subscribeInvoice#3822
kaloudis merged 1 commit intoZeusLN:masterfrom
myxmaster:refactor-handle-payment-received

Conversation

@myxmaster
Copy link
Copy Markdown
Collaborator

Description

Based on #3793.

Extracts a handlePaymentReceived helper that centralizes the post-payment actions shared across all 5 backend implementations in subscribeInvoice (setWatchedInvoicePaid, getCombinedBalance, getChannels, POS recording).

Bug fix:

  • lndhub was not calling getCombinedBalance after receiving a payment, so the displayed balance never refreshed.
  • getChannels was being called after on-chain payments, but channels are unaffected by received on-chain payments, so it now only refreshes after LN payments.

Question:
I noticed embedded-lnd uses > while lightning-node-connect and lnd use >= to check on-chain confirmations:
embedded-lnd: transaction.num_confirmations > numConfPreference
lightning-node-connect: result.num_confirmations >= numConfPreference
lnd: result.num_confirmations >= numConfPreference

With numConfPreference being 0 (0 conf) or 1 (1 conf), the > in embedded-lnd would mean 0 conf mode still requires at least 1 confirmation, and 1 conf mode requires 2. Is this intentional, or should it be >= to match the other implementations?

This pull request is categorized as a:

  • New feature
  • Bug fix
  • Code refactor
  • Configuration change
  • Locales update
  • Quality assurance
  • Other

Checklist

  • I’ve run yarn run tsc and made sure my code compiles correctly
  • I’ve run yarn run lint and made sure my code didn’t contain any problematic patterns
  • I’ve run yarn run prettier and made sure my code is formatted correctly
  • I’ve run yarn run test and made sure all of the tests pass

Testing

If you modified or added a utility file, did you add new unit tests?

  • No, I’m a fool
  • Yes
  • N/A

I have tested this PR on the following platforms (please specify OS version and phone model/VM):

  • Android
  • iOS

I have tested this PR with the following types of nodes (please specify node version and API version where appropriate):

  • Embedded LND
  • LND (REST)
  • LND (Lightning Node Connect)
  • Core Lightning (CLNRest)
  • Nostr Wallet Connect
  • LndHub

Locales

  • I’ve added new locale text that requires translations
  • I’m aware that new translations should be made on the ZEUS Transfix page and not directly to this repo

Third Party Dependencies and Packages

  • Contributors will need to run yarn after this PR is merged in
  • 3rd party dependencies have been modified:
    • verify that package.json and yarn.lock have been properly updated
    • verify that dependencies are installed for both iOS and Android platforms

Other:

  • Changes were made that require an update to the README
  • Changes were made that require an update to onboarding

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the payment handling logic within the subscribeInvoice function by introducing a new handlePaymentReceived helper. This change centralizes common post-payment actions, improving code maintainability and consistency across different backend implementations. It also addresses a critical bug in lndhub where the combined balance was not updated after a payment, and optimizes channel refreshing by limiting it to Lightning Network payments.

Highlights

  • Code Refactoring: Extracted a handlePaymentReceived helper function in subscribeInvoice to centralize post-payment actions, improving code reusability and maintainability.
  • Bug Fix: Addressed a bug where lndhub did not refresh the combined balance after receiving a payment, ensuring accurate balance display.
  • Performance Optimization: Optimized channel refreshing to occur only after Lightning Network payments, as on-chain payments do not affect channel states.
  • Consolidated Logic: Centralized various post-payment tasks, including marking invoices as paid, updating balances, and recording Point-of-Sale (POS) payments, into a single helper function.
Changelog
  • views/Receive.tsx
    • Introduced a new handlePaymentReceived method to encapsulate common post-payment logic.
    • Replaced multiple instances of duplicated payment processing code with calls to the new handlePaymentReceived helper.
    • Added ChannelsStore to the component's props for channel management.
  • views/SendingLightning.tsx
    • Injected ChannelsStore into the component's props.
    • Added a call to ChannelsStore.getChannels() to refresh channel data after a successful Lightning Network payment, contingent on backend support for channel management.
Activity
  • myxmaster initiated the pull request with a detailed description, referencing a previous PR for context.
  • The author completed all required checklist items, including TypeScript compilation, linting, formatting, and test execution.
  • Testing was performed on Android and with LND (REST) node types.
  • A specific question was raised by the author regarding the discrepancy in on-chain confirmation checks (> vs >=) across different backend implementations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively refactors the subscribeInvoice method by extracting a handlePaymentReceived helper, which centralizes post-payment actions and improves code clarity. This change also correctly addresses a bug where lndhub payments didn't trigger a balance refresh. Additionally, channel data is now correctly refreshed only after Lightning payments, and this logic has been consistently applied to SendingLightning.tsx as well. My only suggestion is to remove some debugging console.log statements from the new helper function.

Note: Security Review did not run due to the size of the PR.

Comment thread views/Receive.tsx
@myxmaster myxmaster force-pushed the refactor-handle-payment-received branch from 0e8f57e to 5bff34f Compare March 10, 2026 19:48
@kaloudis kaloudis added Refactor Code that needs to be refactored Payments labels Mar 11, 2026
Copy link
Copy Markdown
Contributor

@ajaysehwal ajaysehwal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK

Copy link
Copy Markdown
Contributor

@shubhamkmr04 shubhamkmr04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK

@kaloudis kaloudis added this to the v13.0.0 milestone Apr 4, 2026
@kaloudis kaloudis merged commit 50fe1fe into ZeusLN:master Apr 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Payments Refactor Code that needs to be refactored

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants