Skip to content

[Bug] PriceChart duplicate React key warning when ≤2 trade records #401

@realproject7

Description

@realproject7

Summary

PriceChart renders 3 x-axis time labels (first, mid, last) using idx as the React key. When a token has only 1 or 2 trade records, lastIdx is 0 or 1, causing multiple labels to share idx: 0 — triggering React's duplicate key warning.

Steps to Reproduce

  1. Buy tokens for a storyline that has no prior trades
  2. After trade completes, observe browser console
  3. Warning: Encountered two children with the same key, 'xl-0' at PriceChart.tsx:168

Root Cause

src/components/PriceChart.tsx:124-128:

const xLabels = [
  { idx: 0, label: formatTime(points[0].time) },
  { idx: Math.floor(lastIdx / 2), label: formatTime(points[Math.floor(lastIdx / 2)].time) },
  { idx: lastIdx, label: formatTime(points[lastIdx].time) },
];

When lastIdx = 0 (1 data point): all three entries have idx: 0.
When lastIdx = 1 (2 data points): first and mid both have idx: 0.

Fix

Deduplicate the label array by idx before rendering:

const xLabelCandidates = [
  { idx: 0, label: formatTime(points[0].time) },
  { idx: Math.floor(lastIdx / 2), label: formatTime(points[Math.floor(lastIdx / 2)].time) },
  { idx: lastIdx, label: formatTime(points[lastIdx].time) },
];
const xLabels = xLabelCandidates.filter(
  (item, i, arr) => arr.findIndex((a) => a.idx === item.idx) === i,
);

Files to Change

File Change
src/components/PriceChart.tsx Deduplicate xLabels array by idx

Acceptance Criteria

  • No duplicate key warning in console when viewing a token with 1 or 2 trades
  • Chart renders correctly with 1, 2, and 3+ data points
  • npm run typecheck passes
  • npm run lint passes

Branch

task/{issue-number}-pricechart-dedup-keys

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/T3Assigned to T3 builder agentbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions