Skip to content

chore(frontend): rename savings-history.ts's private formatCurrency to stop shadowing utils.ts's #171

Description

@cristim

Summary

frontend/src/modules/savings-history.ts:332 defines a private formatCurrency(value) that shadows the shared formatCurrency exported from frontend/src/utils.ts (imported and used elsewhere in the same codebase, including in savings-history.ts's siblings via dashboard.ts).

// frontend/src/modules/savings-history.ts:332
function formatCurrency(value: number | null | undefined): string {
    if (value == null || !Number.isFinite(value)) {
        return '--';
    }
    if (value >= 1000) {
        return `$${(value / 1000).toFixed(2)}K`;
    }
    return `$${value.toFixed(2)}`;
}

Why this is worth tracking

Found during review of PR LeanerCloud/cloud-commitments-cli#1732 (locale-pinning formatCurrency/getDateParts in utils.ts, issue LeanerCloud/cloud-commitments-cli#1728). This local copy is out of scope for that PR — it uses toFixed(), not toLocaleString(), so it isn't locale-dependent and isn't part of the LeanerCloud/cloud-commitments-cli#1728 bug. But it is a second, independently-maintained "format currency for charts" helper with different behavior (K-abbreviation above $1000) living under the same name as the shared helper. That's a duplication / naming-collision risk:

  • A future edit to the shared formatCurrency (e.g. another locale/format fix) won't propagate here, and nothing signals that this file has its own copy.
  • The identical name makes it easy for a future contributor to assume savings-history.ts uses the shared helper when it doesn't.

Suggested fix

Rename the local helper to something that doesn't collide with the shared name (e.g. formatChartCurrency or formatAbbreviatedCurrency), or evaluate whether the K-abbreviation behavior belongs as an option on the shared formatCurrency in utils.ts instead of a separate copy. Low risk, mechanical rename either way.

Scope

Frontend only, frontend/src/modules/savings-history.ts. No behavior change required — this is a naming/duplication cleanup, not a bug fix.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions