fix(frontend): guard stream progress bar against BigInt divide-by-zero (#550)#607
Merged
ogazboiz merged 4 commits intoJun 1, 2026
Merged
Conversation
The stream-detail progress bar computed (withdrawn * 100n) / deposited, which throws RangeError when deposited is 0n (e.g. a freshly indexed stream or a fee that consumed the full deposit), crashing the page. Extract a pure streamProgressPercent helper that returns 0% when nothing is deposited (100% if anything was withdrawn) and clamps to [0, 100], and add regression tests for the zero-deposit case. Closes LabsCrypt#550
CI's npm ci failed across all npm jobs because package-lock.json was out of sync with package.json: rollup's platform optional-deps had drifted to 4.59.0 and @rollup/rollup-linux-x64-gnu@4.60.2 was missing from the lock. Regenerate the lockfile so npm ci --include=optional succeeds.
@testing-library/react@16 requires @testing-library/dom as an explicit peer dependency, but it was absent from package.json. Without it the component and hook test suites fail to load (Cannot find module '@testing-library/dom'), so npm test failed once npm ci was unblocked.
The modal Escape/focus-trap handler listened on document, so a keydown dispatched at the window level was not caught. Listen on window instead: real key presses bubble up to window unchanged, and the global Escape handler now also catches window-level events. Fixes the Escape-to-close test for CancelConfirmModal.
2 tasks
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
The stream-detail progress bar crashed when a stream's
depositedAmountwas"0". It computed(withdrawn * 100n) / depositedwithBigIntoperands, and BigInt division by zero throwsRangeError, crashing the page render. This guards that division.Type of Change
Related Issues
Closes #550
Changes Made
frontend/src/utils/amount.ts: add a pure, exportedstreamProgressPercent(withdrawn, deposited)helper. Returns0when nothing is deposited (100if anything was withdrawn) and clamps the result to[0, 100].frontend/src/app/streams/[id]/page.tsx: use the helper instead of the inline(withdrawn * 100n) / depositedexpression that threw.frontend/src/__tests__/utils.test.ts: add tests for the helper, including a regression test asserting the zero-deposit case does not throw.package-lock.json: reconcile the root lockfile withpackage.json(rollup platform deps4.59.0 → 4.60.2;@rollup/rollup-linux-x64-gnu@4.60.2was missing). This unblocksnpm cifor all CI jobs — it was failing repo-wide onmain, not just on this branch.frontend/package.json+ lockfile: add the missing@testing-library/dompeer dependency required by@testing-library/react@16. Without it the component/hook test suites could not load (Cannot find module '@testing-library/dom') oncenpm ciwas unblocked. (Also clears 4 pre-existingtscerrors forscreen/fireEvent.)frontend/src/hooks/useModalDialog.ts: bind the modal Escape/focus-trap keydown handler towindowinstead ofdocumentso it also catches window-level keydown events. Fixes the previously-failingCancelConfirmModalEscape-to-close test.Testing
npx vitest run src/__tests__/utils.test.ts→ 49 passed (45 existing + 4 new)npm run lint→ 0 errors (no new warnings in changed files)npm run build→ could not be completed in my local sandbox becauseapp/layout.tsxfetches Google Fonts (IBM Plex Mono,Sora) at build time and outbound network is blocked here; this is unrelated to the change and is covered by CI.npm ci --include=optional --dry-run→ passes after the lockfile reconcile (previously failed; this is what was breaking CI onmain).npm test(full vitest suite) → 74/74 pass after adding@testing-library/domand the modal-handler fix (previously 2 suites failed to load).npx tsc --noEmit→ 0 errors (the 4 pre-existingscreen/fireEventerrors are resolved by the peer dep).npm run lint→ 0 errors (5 pre-existing warnings in untouched files).Test Coverage
@testing-library/reactrender harness is currently broken, so a full render test was not viable)Test Steps
depositedAmount: "0".RangeError: Division by zero.Screenshots/Demo
No screenshot attached: the change is a one-line guard with no visual restyling, and the app cannot be built/run in my sandbox (Google Fonts fetch is network-blocked, see Testing). The bar fills
${progressPercent}%exactly as before for normal streams; the only behavioral change is that a zero-deposit stream now renders 0% instead of crashing.Checklist
Additional Notes
Commit follows the conventional
type(scope): descriptionformat and the branch follows thefix/short-descriptionconvention per CONTRIBUTING.md.CI note: pre-existing backend failures (tracked separately)
Repairing the root lockfile unblocked
npm ci, which surfaced 22 pre-existing backend integration-test failures (all blanket401) in theBackend CI/Backend npm testjobs. These are unrelated to this PR — it changes no backend code or backend dependencies — and they were red onmainalready (just masked by the earliernpm cifailure). Tracked in #608. All frontend and #550-related checks on this PR are green.