|
| 1 | +import { countBy } from 'lodash' |
1 | 2 | import { ethAddress } from 'viem' |
2 | 3 | import { Chain } from '@curvefi/prices-api' |
3 | 4 | import { recordValues } from '@curvefi/prices-api/objects.util' |
@@ -257,19 +258,13 @@ const convertMintMarket = ( |
257 | 258 |
|
258 | 259 | /** |
259 | 260 | * Creates a function that counts the number of markets for each collateral token. |
260 | | - * This is used to create unique names for markets with the same collateral token, used in the URL. |
261 | | - * The order is expected to be by market creation date, so the first market will have count 1, the second 2, etc. |
262 | | - * The backend is hardcoded to return markets in the order of creation, so this should work correctly. |
| 261 | + * Numbers are added to the first items (e.g., first ETH gets 3, second gets 2, last gets 1). |
263 | 262 | * @returns A function that takes a MintMarket and returns the count of markets for the collateral token. |
264 | 263 | */ |
265 | | -function createCountMarket() { |
266 | | - const marketCountByCollateral = new Map<string, number>() |
267 | | - return ({ collateralToken }: MintMarket) => { |
268 | | - const [symbol] = getCollateral(collateralToken) |
269 | | - const count = (marketCountByCollateral.get(symbol) ?? 0) + 1 |
270 | | - marketCountByCollateral.set(symbol, count) |
271 | | - return count |
272 | | - } |
| 264 | +function createCountMarket(data: MintMarket[] | undefined = []) { |
| 265 | + const getName = ({ collateralToken }: MintMarket) => getCollateral(collateralToken)[0] |
| 266 | + const marketCountByCollateral = countBy(data, getName) |
| 267 | + return (m: MintMarket) => marketCountByCollateral[getName(m)]-- |
273 | 268 | } |
274 | 269 |
|
275 | 270 | /** |
@@ -303,7 +298,7 @@ export const useLlamaMarkets = (userAddress?: Address, enabled = true) => |
303 | 298 | const userBorrows = new Set(recordValues(userLendingVaults.data ?? {}).flat()) |
304 | 299 | const userMints = new Set(recordValues(userMintMarkets.data ?? {}).flat()) |
305 | 300 | const userSupplied = new Set(recordValues(userSuppliedMarkets.data ?? {}).flat()) |
306 | | - const countMarket = createCountMarket() |
| 301 | + const countMarket = createCountMarket(mintMarkets.data) |
307 | 302 |
|
308 | 303 | // only render table when both lending and mint markets are ready, however show one of them if the other is in error |
309 | 304 | const showData = (lendingVaults.data && mintMarkets.data) || lendingVaults.isError || mintMarkets.isError |
|
0 commit comments