Skip to content

Commit 0939d16

Browse files
committed
fix: use raw addresses as Plotly labels key to prevent slice merging
Plotly merges pie slices with duplicate labels and sums their values, which would silently misrepresent LP concentration when two addresses share the same custom label (e.g. both labelled 'Team Wallet'). Fix: use raw addresses as the key (guaranteed unique) and put the resolved human names in (shown in legend) and (shown in hover). Also: - Remove duplicated truncateAddress, import from shared @/lib/format - Narrow getLabel prop type to (string) => string; call site wraps adapter - Update unit tests: rename _ params to _addr to pass ESLint no-unused-vars, add duplicate-label collision test documenting the labels/text split
1 parent e5ceeae commit 0939d16

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

ui-dashboard/src/components/__tests__/lp-concentration-chart.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ describe("resolvePieLabel", () => {
1111
});
1212

1313
it("returns named label when getLabel resolves a real name", () => {
14-
expect(resolvePieLabel(ADDR, () => "Team Wallet")).toBe("Team Wallet");
14+
const getLabel = (_address: string) => "Team Wallet";
15+
expect(resolvePieLabel(ADDR, getLabel)).toBe("Team Wallet");
1516
});
1617

1718
it("returns truncated address when getLabel returns the truncated form", () => {
@@ -20,7 +21,8 @@ describe("resolvePieLabel", () => {
2021
});
2122

2223
it("does not include raw address when a named label exists", () => {
23-
const result = resolvePieLabel(ADDR, () => "Team Wallet");
24+
const getLabel = (_address: string) => "Team Wallet";
25+
const result = resolvePieLabel(ADDR, getLabel);
2426
expect(result).not.toContain("0x1015");
2527
expect(result).toBe("Team Wallet");
2628
});
@@ -33,7 +35,8 @@ describe("resolvePieLabel", () => {
3335
});
3436

3537
it("allows multiple addresses to resolve to the same human label", () => {
36-
expect(resolvePieLabel(ADDR, () => "Shared Label")).toBe("Shared Label");
37-
expect(resolvePieLabel(ADDR2, () => "Shared Label")).toBe("Shared Label");
38+
const getLabel = (_address: string) => "Shared Label";
39+
expect(resolvePieLabel(ADDR, getLabel)).toBe("Shared Label");
40+
expect(resolvePieLabel(ADDR2, getLabel)).toBe("Shared Label");
3841
});
3942
});

ui-dashboard/src/components/lp-concentration-chart.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use client";
22

33
import dynamic from "next/dynamic";
4-
import { PLOTLY_BASE_LAYOUT, PLOTLY_CONFIG } from "@/lib/plot";
54
import { truncateAddress } from "@/lib/format";
5+
import { PLOTLY_BASE_LAYOUT, PLOTLY_CONFIG } from "@/lib/plot";
66
import { USDM_SYMBOLS } from "@/lib/tokens";
77
import type { Pool } from "@/lib/types";
88

@@ -57,7 +57,13 @@ export function LpConcentrationChart({
5757

5858
const resolveLabel = (addr: string) => resolvePieLabel(addr, getLabel);
5959

60+
// Use raw addresses as labels — Plotly merges slices with duplicate labels,
61+
// so human names must not be the label key. Display names go in `text`.
6062
const labels = [
63+
...top.map((p) => p.address),
64+
...(otherTotal > BigInt(0) ? ["other"] : []),
65+
];
66+
const text = [
6167
...top.map((p) => resolveLabel(p.address)),
6268
...(otherTotal > BigInt(0) ? ["Other"] : []),
6369
];
@@ -81,6 +87,7 @@ export function LpConcentrationChart({
8187
type: "pie" as const,
8288
hole: 0.4,
8389
labels,
90+
text,
8491
values,
8592
customdata,
8693
hovertemplate,

0 commit comments

Comments
 (0)