Skip to content

Conversation

@shubhamkmr04
Copy link
Contributor

@shubhamkmr04 shubhamkmr04 commented Jan 27, 2026

Description

  1. Fix amounts clearing on QR scan: Add isNavigatingToQRScanner flag to skip resetFields() when navigating to scanner
  2. Preserve amounts for address-only QR: Only pass initialAmountSats when present, handle address-only params without overwriting existing amounts
  • 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
Contributor

Summary of Changes

Hello @shubhamkmr04, 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 resolves a bug related to scanning QR codes for swap operations. Previously, the application failed to correctly process and display swap amounts embedded in QR codes, or would reset the swap form upon returning from the scanner. The changes ensure that scanned amounts are accurately captured, passed, and displayed on the Swaps screen, and that the swap state is preserved during the QR scanning process.

Highlights

  • QR Code Scanning for Swaps: Fixed an issue where swap amounts were not correctly passed or preserved when scanning QR codes that included an amount, leading to incorrect display or loss of the amount.
  • Conditional Amount Passing: The HandleAnythingQRScanner now conditionally passes the initialAmountSats parameter to the Swaps screen only if a valid amount is detected in the QR code, preventing undefined values from being sent.
  • State Preservation on Swaps Screen: Introduced a mechanism in the Swaps component to prevent the form fields from resetting when returning from the QR scanner, ensuring that the scanned invoice and amount (if present) are retained.
  • Improved Amount Display Logic: Updated the Swaps component's logic to correctly calculate and display initial swap amounts in various units (fiat, BTC, sats) when an amount is provided via a scanned QR code.
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
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 addresses the bug where swap amounts were not preserved when scanning QR codes. The changes correctly handle cases where initialAmountSats might be undefined, ensuring that the invoice and reverse swap settings are still applied. Additionally, the logic for displaying fiat and BTC amounts has been improved to correctly format values based on the selected unit. The introduction of isNavigatingToQRScanner for state management also enhances the user experience by preventing unintended field resets when returning from the QR scanner.

Comment on lines +336 to +433
if (initialInvoice !== undefined && initialReverse !== undefined) {
if (initialAmountSats === undefined) {
this.setState(
{
paramsProcessed: true,
invoice: initialInvoice,
reverse: initialReverse,
outputSats: newOutputSats,
outputFiat:
units === 'fiat'
? newOutputFiat
: this.state.outputFiat,
inputSats: newInputSats,
inputFiat:
units === 'fiat'
? newInputFiat
: this.state.inputFiat,
serviceFeeSats: newServiceFeeSats
reverse: initialReverse
},
() => this.checkIsValid()
);
});
} else {
this.setState({ paramsProcessed: true }, async () => {
// Use callback to ensure paramsProcessed is set before further calcs
const { units } = UnitsStore;
const { fiatRates } = FiatStore;
const { fiat } = settings;
const fiatEntry =
fiat && fiatRates
? fiatRates.filter(
(entry: any) => entry.code === fiat
)[0]
: null;
const rate =
fiat && fiatRates && fiatEntry ? fiatEntry.rate : 0;

const info: any = initialReverse
? SwapStore.reverseInfo
: SwapStore.subInfo;
const serviceFeePct = info?.fees?.percentage || 0;
const networkFeeBigNum = initialReverse
? new BigNumber(
info?.fees?.minerFees?.claim || 0
).plus(info?.fees?.minerFees?.lockup || 0)
: new BigNumber(info?.fees?.minerFees || 0);
const networkFee = networkFeeBigNum.toNumber();

const newOutputSats = new BigNumber(
initialAmountSats || 0
);
let newOutputFiat = '';
if (newOutputSats.isGreaterThan(0)) {
if (units === 'fiat' && rate > 0) {
newOutputFiat = newOutputSats
.div(SATS_PER_BTC)
.times(rate)
.toFixed(2);
} else if (units === 'BTC') {
newOutputFiat = newOutputSats
.div(SATS_PER_BTC)
.toFixed(8);
} else if (units === 'sats') {
newOutputFiat = newOutputSats.toFixed(0);
}
}

const newInputSats = calculateSendAmount(
newOutputSats,
serviceFeePct,
networkFee,
this.state.reverse
);
let newInputFiat = '';
if (newInputSats.isGreaterThan(0)) {
if (units === 'fiat' && rate > 0) {
newInputFiat = newInputSats
.div(SATS_PER_BTC)
.times(rate)
.toFixed(2);
} else if (units === 'BTC') {
newInputFiat = newInputSats
.div(SATS_PER_BTC)
.toFixed(8);
} else if (units === 'sats') {
newInputFiat = newInputSats.toFixed(0);
}
}

const newServiceFeeSats = calculateServiceFeeOnSend(
newInputSats,
serviceFeePct,
networkFee,
this.state.reverse
);

this.setState(
{
invoice: initialInvoice,
reverse: initialReverse,
outputSats: newOutputSats,
outputFiat: newOutputFiat,
inputSats: newInputSats,
inputFiat: newInputFiat,
serviceFeeSats: newServiceFeeSats
},
() => this.checkIsValid()
);
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This refactoring correctly handles the scenario where initialAmountSats might be undefined when scanning a QR code. By separating the logic, it ensures that the invoice and reverse status are set even without an amount, and only proceeds with amount calculations when initialAmountSats is present. The enhanced newOutputFiat and newInputFiat calculations also correctly handle different unit displays (fiat, BTC, sats), improving the accuracy of displayed amounts.

            if (initialInvoice !== undefined && initialReverse !== undefined) {
                if (initialAmountSats === undefined) {
                    this.setState(
                        {
                            paramsProcessed: true,
                            invoice: initialInvoice,
                            reverse: initialReverse
                        },
                        () => this.checkIsValid()
                    );
                } else {
                    this.setState({ paramsProcessed: true }, async () => {
                        // Use callback to ensure paramsProcessed is set before further calcs
                        const { units } = UnitsStore;
                        const { fiatRates } = FiatStore;
                        const { fiat } = settings;
                        const fiatEntry =
                            fiat && fiatRates
                                ? fiatRates.filter(
                                      (entry: any) => entry.code === fiat
                                  )[0]
                                : null;
                        const rate =
                            fiat && fiatRates && fiatEntry ? fiatEntry.rate : 0;

                        const info: any = initialReverse
                            ? SwapStore.reverseInfo
                            : SwapStore.subInfo;
                        const serviceFeePct = info?.fees?.percentage || 0;
                        const networkFeeBigNum = initialReverse
                            ? new BigNumber(
                                  info?.fees?.minerFees?.claim || 0
                              ).plus(info?.fees?.minerFees?.lockup || 0)
                            : new BigNumber(info?.fees?.minerFees || 0);
                        const networkFee = networkFeeBigNum.toNumber();

                        const newOutputSats = new BigNumber(
                            initialAmountSats || 0
                        );
                        let newOutputFiat = '';
                        if (newOutputSats.isGreaterThan(0)) {
                            if (units === 'fiat' && rate > 0) {
                                newOutputFiat = newOutputSats
                                    .div(SATS_PER_BTC)
                                    .times(rate)
                                    .toFixed(2);
                            } else if (units === 'BTC') {
                                newOutputFiat = newOutputSats
                                    .div(SATS_PER_BTC)
                                    .toFixed(8);
                            } else if (units === 'sats') {
                                newOutputFiat = newOutputSats.toFixed(0);
                            }
                        }

                        const newInputSats = calculateSendAmount(
                            newOutputSats,
                            serviceFeePct,
                            networkFee,
                            this.state.reverse
                        );
                        let newInputFiat = '';
                        if (newInputSats.isGreaterThan(0)) {
                            if (units === 'fiat' && rate > 0) {
                                newInputFiat = newInputSats
                                    .div(SATS_PER_BTC)
                                    .times(rate)
                                    .toFixed(2);
                            } else if (units === 'BTC') {
                                newInputFiat = newInputSats
                                    .div(SATS_PER_BTC)
                                    .toFixed(8);
                            }
                            else if (units === 'sats') {
                                newInputFiat = newInputSats.toFixed(0);
                            }
                        }

                        const newServiceFeeSats = calculateServiceFeeOnSend(
                            newInputSats,
                            serviceFeePct,
                            networkFee,
                            this.state.reverse
                        );

                        this.setState(
                            {
                                invoice: initialInvoice,
                                reverse: initialReverse,
                                outputSats: newOutputSats,
                                outputFiat: newOutputFiat,
                                inputSats: newInputSats,
                                inputFiat: newInputFiat,
                                serviceFeeSats: newServiceFeeSats
                            },
                            () => this.checkIsValid()
                        );
                    });
                }
            }

@kaloudis kaloudis added this to the v0.13.0 milestone Jan 27, 2026
@kaloudis kaloudis added Bug Something isn't working Swaps On-chain <-> LN labels Jan 27, 2026
@kaloudis
Copy link
Contributor

Previously outputFiat/inputFiat were only updated when units === 'fiat'. Now they're always set regardless of unit type. Is that intentional? If so, might be better renaming the variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Swaps On-chain <-> LN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants