Skip to content

Fix sparkline layout gap, negative-bar color loss, and unrestricted API URL schemes - #318

Merged
chonilius merged 4 commits into
MergeFi:mainfrom
posimideveloper:fix/sparkline-gap-barchart-negative-api-url-scheme-verify-script
Aug 25, 2026
Merged

chonilius merged 4 commits into
MergeFi:mainfrom
posimideveloper:fix/sparkline-gap-barchart-negative-api-url-scheme-verify-script

Conversation

@posimideveloper

Copy link
Copy Markdown
Contributor

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> while Sparkline itself draws nothing for < 2 points — 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 checks sparkline.length >= 2 before 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) — validateApiUrl validated purely via new URL(value) succeeding, but that doesn't restrict the scheme — javascript:alert(1), file:///etc/passwd, and ftp://example.com all 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 actual fetch() call site, with a far less clear error. Now asserts protocol === "http:" || protocol === "https:" after parsing succeeds. Added env.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-formed NEXT_PUBLIC_API_URL — the only "success" case exercised the empty/undefined-fallback path, never the actual URL-parsing success path. A regression breaking validateApiUrl for 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 / new env.test.ts — http(s)-only scheme validation.
  • scripts/verify-env-validation.mjs — new valid-custom-URL success case.

Test plan

  • npx tsc --noEmit — clean
  • npx eslint on all changed files — clean
  • npx jest (full suite) — 202/202 passing, no regressions
  • node scripts/verify-env-validation.mjs — all 5 scenarios pass (ran locally against real next build)

Closes #207
Closes #206
Closes #204
Closes #205

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).
@vercel

vercel Bot commented Aug 25, 2026

Copy link
Copy Markdown

@posimideveloper is attempting to deploy a commit to the chonilius' projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Aug 25, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@chonilius
chonilius merged commit 52a1a26 into MergeFi:main Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment