From c736b276dafec6932550304179bd0045cdc2d7b8 Mon Sep 17 00:00:00 2001 From: Denis Fadeev <denis@fadeev.org> Date: Tue, 6 Feb 2024 17:13:38 +0400 Subject: [PATCH] sorting --- .../ContractAddresses/ContractAddresses.tsx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/components/ContractAddresses/ContractAddresses.tsx b/src/components/ContractAddresses/ContractAddresses.tsx index c1cd4448..46722cd1 100644 --- a/src/components/ContractAddresses/ContractAddresses.tsx +++ b/src/components/ContractAddresses/ContractAddresses.tsx @@ -20,15 +20,22 @@ const ContractAddresses = () => { responses.map((res) => res.json()) ); - const groupByChainId = (data: any) => - data.reduce((acc: any, item: any) => { + const groupByChainId = (data) => + data.reduce((acc, item) => { (acc[item.chain_name] = acc[item.chain_name] || []).push(item); return acc; }, {}); + const sortGroupedData = (groupedData) => { + Object.keys(groupedData).forEach((chainName) => { + groupedData[chainName].sort((a, b) => a.type.localeCompare(b.type)); + }); + return groupedData; + }; + setGroupedData({ - testnet: groupByChainId(testnetData), - mainnet: groupByChainId(mainnetData), + testnet: sortGroupedData(groupByChainId(testnetData)), + mainnet: sortGroupedData(groupByChainId(mainnetData)), }); setIsLoading(false); }; @@ -72,7 +79,7 @@ const ContractAddresses = () => { </tr> </thead> <tbody> - {contracts.map((contract: any, index: any) => ( + {contracts.map((contract, index) => ( <tr key={index}> <td>{contract.type}</td> <td>{contract.symbol}</td> @@ -86,7 +93,7 @@ const ContractAddresses = () => { )} <p> Source: - <a href={`${source}`} target="_blank" rel="noopener noreferrer"> + <a href={source} target="_blank" rel="noopener noreferrer"> {source} </a> </p>