Skip to content

Commit

Permalink
sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Feb 6, 2024
1 parent 5c3bcda commit c736b27
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/components/ContractAddresses/ContractAddresses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -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>
Expand All @@ -86,7 +93,7 @@ const ContractAddresses = () => {
)}
<p>
Source:&nbsp;
<a href={`${source}`} target="_blank" rel="noopener noreferrer">
<a href={source} target="_blank" rel="noopener noreferrer">
{source}
</a>
</p>
Expand Down

0 comments on commit c736b27

Please sign in to comment.