Repository navigation
Fix sparkline layout gap, negative-bar color loss, and unrestricted API URL schemes - #318
Merged
chonilius merged 4 commits intoAug 25, 2026
Conversation
Sparkline returns null for data.length < 2 (can't draw a line through
one point), but StatCard's {sparkline && (...)} check only tested
truthiness/presence of the array, not its length. A one-element or
empty array is truthy, so the wrapping <div> still rendered with
Sparkline drawing nothing inside it — an empty, unexplained gap in the
card's flex row where a chart was visually expected. Currently latent
since every sparkline passed in today has 8 points, but any future
usage with a shorter history (e.g. a brand-new contributor's first
week) would trigger it.
Now checks sparkline.length >= 2 before rendering the wrapper at all.
Updated the two StatCard tests that previously documented the
empty-wrapper behavior as expected to instead assert the wrapper is
absent (closes MergeFi#207).
…zero positives Every bar's height was floored at 2% (pct = Math.max((d.value / max) * 100, 2)) so a genuine zero stayed visually present instead of collapsing to nothing. But that same floor made a negative value — e.g. a net-negative weekly spend after a large refund — render as an identical small, positive-looking indigo bar, with the sign of the underlying number completely lost visually (the hover tooltip still showed the correct signed figure, but the bar itself contradicted it). BarChart currently only receives non-negative mock data, so this was latent, but the component had no guard or visual handling for it. Bars for a negative value now render in a distinct rose color instead of the standard indigo, so the sign stays visible at a glance without needing a larger zero-baseline redesign (closes MergeFi#206).
validateApiUrl validated the API base URL purely via new URL(value) succeeding, but new URL() doesn't restrict the scheme — "javascript:alert(1)", "file:///etc/passwd", and "ftp://example.com" all construct successfully despite none being meaningful as an HTTP API base URL. A misconfigured deployment (a copy-paste error with a stray javascript:/data: prefix, or a leftover file:// from a local testing script) would pass this build-time check and only fail much later, at the actual fetch() call site, with a far less clear error than this function exists to provide. The function's own doc comment says it guards against "a well-formed URL" being wrong for this purpose — a non-http(s) scheme is exactly that. Now asserts protocol is "http:" or "https:" after the URL parses successfully, throwing the same EnvValidationError otherwise. Added env.test.ts (no prior test file existed for this module) covering the accepted http(s)/default-fallback paths and the newly-rejected javascript:/file:/ftp: schemes (closes MergeFi#204).
…_PUBLIC_API_URL CASES had four scenarios: missing STELLAR_NETWORK (fails), invalid network value (fails), invalid API URL (fails), and a valid network that relies on the default API URL (succeeds). No case set a well-formed, non-default NEXT_PUBLIC_API_URL and asserted the build succeeds — the only "success" case exercised validateApiUrl's empty/undefined -> DEFAULT_API_BASE_URL fallback path, never its actual URL-parsing success path. A regression that broke validateApiUrl for any explicitly-set, valid URL while leaving the default path untouched would have passed this entire script undetected. Added a fifth case setting NEXT_PUBLIC_API_URL=https://api.example.com alongside a valid network and asserting success, so the script proves both validateApiUrl code paths. Ran the script locally against the current build — all 5 scenarios pass (closes MergeFi#205).
|
@posimideveloper is attempting to deploy a commit to the chonilius' projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@posimideveloper Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Summary
Four fixes spanning chart components and env validation:
Empty sparkline gap (#207) —
StatCard's{sparkline && (...)}check only tested presence, not length, so a one-element or empty array (truthy) still rendered the wrapping<div>whileSparklineitself draws nothing for< 2points — an empty, unexplained gap in the card's layout. Currently latent since every sparkline passed in today has 8 points, but any future usage with a shorter history would trigger it. Now checkssparkline.length >= 2before rendering the wrapper.Negative bar values indistinguishable from near-zero (#206) — every bar's height was floored at 2% so a genuine zero stayed visible, but the same floor made a negative value (e.g. a net-negative weekly spend after a large refund) render as an identical small, positive-looking bar — the sign was completely lost visually, even though the hover tooltip still showed the correct signed figure. Bars for negative values now render in a distinct rose color instead of the standard indigo.
Unrestricted API URL scheme (#204) —
validateApiUrlvalidated purely vianew URL(value)succeeding, but that doesn't restrict the scheme —javascript:alert(1),file:///etc/passwd, andftp://example.comall parse successfully. A misconfigured deployment with a stray non-http(s) scheme would pass this build-time check and only fail much later, at the actualfetch()call site, with a far less clear error. Now assertsprotocol === "http:" || protocol === "https:"after parsing succeeds. Addedenv.test.ts(no prior test file existed for this module).Verify-env script coverage gap (#205) —
verify-env-validation.mjs's four cases never asserted a build succeeds with an explicitly-set, well-formedNEXT_PUBLIC_API_URL— the only "success" case exercised the empty/undefined-fallback path, never the actual URL-parsing success path. A regression breakingvalidateApiUrlfor any valid explicit URL would have passed undetected. Added a fifth case; ran the script locally — all 5 scenarios pass.Changes
src/components/ui/StatCard.tsx/.test.tsx— sparkline length guard.src/components/ui/BarChart.tsx— distinct color for negative bars.src/lib/env.ts/ newenv.test.ts— http(s)-only scheme validation.scripts/verify-env-validation.mjs— new valid-custom-URL success case.Test plan
npx tsc --noEmit— cleannpx eslinton all changed files — cleannpx jest(full suite) — 202/202 passing, no regressionsnode scripts/verify-env-validation.mjs— all 5 scenarios pass (ran locally against realnext build)Closes #207
Closes #206
Closes #204
Closes #205