fix: repair stale invoice expiry display ("3600 hours") for upgraded users#4128
Open
kaloudis wants to merge 2 commits into
Open
fix: repair stale invoice expiry display ("3600 hours") for upgraded users#4128kaloudis wants to merge 2 commits into
kaloudis wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a helper function displayFromExpirySeconds to convert raw expiry seconds into the largest evenly-divisible time unit, along with corresponding unit tests. It also adds a migration step in MigrationUtils to repair out-of-sync invoice expiry display settings. The review feedback points out a potential race condition in the migration block where settingsStore.setSettings is called without await, and suggests awaiting this asynchronous call to prevent concurrent write issues.
Each migration block in legacySettingsMigrations writes mutations to the shared newSettings object and persists them via setSettings. The calls were fire-and-forget, so two unawaited writes could complete out of order — clobbering a later migration's changes — while the MOD_KEY flag was already set, preventing the migration from re-running.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a stale-settings display bug in the Receive screen: affected users saw the default invoice expiration rendered as "3600 hours" even though invoices actually expired in 1 hour.
Root cause
views/Receive.tsxstores three loosely-coupled invoice fields in saved settings:expirySeconds— the authoritative value passed to the backend (Receive.tsx:596-598→backends/LND.ts:341).expiry+timePeriod— used only bygetFormattedDuration(Receive.tsx:1214-1225) to render the duration label.A historical regression (commit
e4339e137, March 2023) initialized the defaultinvoices.expiryto'3600'instead of'1'. The default instores/SettingsStore.ts:1516is now correct (expiry: '1'), but users who installed during the affected window still carry the buggy value in their saved settings, and there was no migration to repair it.Invoices themselves were unaffected because the backend reads
expirySeconds(still'3600'→ 1 hour). Only the displayed label was wrong.This is not backend-specific — it affects any user with the stale value, regardless of node implementation.
Fix
utils/ExpiryUtils.ts— adddisplayFromExpirySeconds(expirySeconds), the inverse ofexpirySecondsFromInput. Picks the largest evenly-dividing unit (604800 → 1 Weeks,86400 → 1 Days,3600 → 1 Hours,600 → 10 Minutes), falls back toSecondsfor non-divisible values, and to1 Hoursfor empty/invalid input.utils/MigrationUtils.ts— new one-shot migrationMOD_KEY9 = 'invoices-expiry-display-fix'inlegacySettingsMigrations. WhenexpirySecondsFromInput(expiry, timePeriod) !== expirySeconds, recomputeexpiry+timePeriodfrom the authoritativeexpirySeconds. Follows the existingMOD_KEYpattern and runs once per install.utils/ExpiryUtils.test.ts— new test cases covering the largest-divisor preference, the Seconds fallback, and invalid input.utils/MigrationUtils.test.ts— new test cases asserting that the documented buggy state (expiry: '3600',timePeriod: 'Hours',expirySeconds: '3600') is repaired to(expiry: '1', timePeriod: 'Hours', expirySeconds: '3600')and that already-consistent state passes through untouched.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: