Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/pool.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { XMR_PORT } from "./constants.js";
import { isFiniteNumber } from "./format.js";

const coinSymbolCountsCache = new WeakMap();

function byPort(values, port) {
if (!values || typeof values !== "object") return undefined;
if (Object.hasOwn(values, port)) return values[port];
Expand Down Expand Up @@ -93,13 +95,26 @@ export function coinRouteId(poolStats = {}, port) {

function hasDuplicateCoinSymbol(poolStats = {}, symbol) {
const wanted = coinRouteSlug(symbol);
let count = 0;
if (!wanted) return false;
return getCoinSymbolCounts(poolStats).get(wanted) > 1;
}

function getCoinSymbolCounts(poolStats = {}) {
const coinsRef = poolStats?.coins;
if (!coinsRef || typeof coinsRef !== "object") return new Map();

const cached = coinSymbolCountsCache.get(poolStats);
if (cached?.coinsRef === coinsRef) return cached.counts;

const counts = new Map();
for (const coin of coinStatsRows(poolStats)) {
const metadata = coinMetadata(poolStats, coin.p) || {};
if (coinRouteSlug(metadata.symbol || coin.s) === wanted) count += 1;
if (count > 1) return true;
const key = coinRouteSlug(metadata.symbol || coin.s);
if (!key) continue;
counts.set(key, (counts.get(key) || 0) + 1);
}
return false;
coinSymbolCountsCache.set(poolStats, { coinsRef, counts });
return counts;
}

function routeLabel(value) {
Expand Down