fix: preserve LnurlPay comment when navigating back from AmountKeypad#3965
fix: preserve LnurlPay comment when navigating back from AmountKeypad#3965myxmaster wants to merge 1 commit intoZeusLN:masterfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the LnurlPay component by replacing the resetState method with recalculateDisplayAmount to handle unit changes more efficiently when navigating back to the screen. The logic was simplified to only update the amount state when a non-zero satAmount exists. A review comment suggests adding a conditional check before calling setState to avoid redundant re-renders if the displayed amount remains unchanged.
| }); | ||
| } else { | ||
| this.setState(fresh); | ||
| this.setState({ amount: displayAmount }); |
There was a problem hiding this comment.
To avoid unnecessary re-renders when navigating back to this screen, consider checking if the newly calculated displayAmount is different from the current amount in the state before calling setState. This is especially useful if the user didn't change the unit or amount in the keypad, as the focus event will still trigger this recalculation.
if (displayAmount !== this.state.amount) {
this.setState({ amount: displayAmount });
}
Description
Found a minor issue, where the comment field in the Lightning Address payment screen (
LnurlPay) was cleared when you tapped the amount field and navigated back.Root cause: The amount field opens the dedicated
AmountKeypadscreen. When you return from it, React Navigation fires afocusevent onLnurlPay. The registered focus listener calledresetState(), which did a full state rebuild viastateFromProps(), including hardcodingcomment: ''. Sincecommentis not part of the route params, it was lost.Fix: the focus listener now only recalculates the displayed amount in the current unit (the one thing that can legitimately change when coming back from the keypad). All other state, including
comment, is left untouched. Also renamedresetState->recalculateDisplayAmountto reflect the narrower scope.This pull request is categorized as a:
Checklist
yarn run tscand made sure my code compiles correctlyyarn run lintand made sure my code didn’t contain any problematic patternsyarn run prettierand made sure my code is formatted correctlyyarn run testand made sure all of the tests passTesting
If you modified or added a utility file, did you add new unit tests?
I have tested this PR on the following platforms (please specify OS version and phone model/VM):
I have tested this PR with the following types of nodes (please specify node version and API version where appropriate):
On-device
Remote
Locales
Third Party Dependencies and Packages
yarnafter this PR is merged inpackage.jsonandyarn.lockhave been properly updatedOther: