Skip to content

Commit

Permalink
sort channels subpages
Browse files Browse the repository at this point in the history
  • Loading branch information
mjadach-iv committed Dec 2, 2024
1 parent 7fe7f2a commit 1f4eb88
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
28 changes: 26 additions & 2 deletions src/pages/node/channelsIncoming.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { truncateEthereumAddress } from '../../utils/blockchain';
function ChannelsPage() {
const dispatch = useAppDispatch();
const channels = useAppSelector((store) => store.node.channels.data);
const channelsIncoming = useAppSelector((store) => store.node.channels.data?.incoming);
const channelsIncomingObject = useAppSelector((store) => store.node.channels.parsed.incoming);
const channelsFetching = useAppSelector((store) => store.node.channels.isFetching);
const aliases = useAppSelector((store) => store.node.aliases.data);
Expand Down Expand Up @@ -195,8 +196,31 @@ function ChannelsPage() {
});
};

const parsedTableData = Object.keys(channelsIncomingObject)
.map((id, index) => {
const peersWithAliases = (channelsIncoming || []).filter(peer => aliases && peer.peerAddress && getAliasByPeerAddress(peer.peerAddress) !== peer.peerAddress) ;
const peersWithAliasesSorted = peersWithAliases.sort((a, b) => {
if (getAliasByPeerAddress(b.peerAddress).toLowerCase() > getAliasByPeerAddress(a.peerAddress).toLowerCase()) {
return -1;
}
if (getAliasByPeerAddress(b.peerAddress).toLowerCase() < getAliasByPeerAddress(a.peerAddress).toLowerCase()) {
return 1;
}
return 0
});
const peersWithoutAliases = (channelsIncoming || []).filter(peer => aliases && peer.peerAddress && getAliasByPeerAddress(peer.peerAddress) === peer.peerAddress) ;
const peersWithoutAliasesSorted = peersWithoutAliases.sort((a, b) => {
if (b.peerAddress > a.peerAddress) {
return -1;
}
if (b.peerAddress < a.peerAddress) {
return 1;
}
return 0
});

const peersSorted = [...peersWithAliasesSorted, ...peersWithoutAliasesSorted]

const parsedTableData = peersSorted.map((channel, index) => {
const id = channel.id;
if (
!channelsIncomingObject[id].peerAddress ||
!channelsIncomingObject[id].balance ||
Expand Down
28 changes: 26 additions & 2 deletions src/pages/node/channelsOutgoing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function ChannelsPage() {
const dispatch = useAppDispatch();
const channels = useAppSelector((store) => store.node.channels.data);
const channelsOutgoingObject = useAppSelector((store) => store.node.channels.parsed.outgoing);
const channelsOutgoing = useAppSelector((store) => store.node.channels.data?.outgoing);
const channelsFetching = useAppSelector((store) => store.node.channels.isFetching);
const aliases = useAppSelector((store) => store.node.aliases.data);
const loginData = useAppSelector((store) => store.auth.loginData);
Expand Down Expand Up @@ -188,8 +189,31 @@ function ChannelsPage() {
},
];

const parsedTableData = Object.keys(channelsOutgoingObject)
.map((id, index) => {
const peersWithAliases = (channelsOutgoing || []).filter(peer => aliases && peer.peerAddress && getAliasByPeerAddress(peer.peerAddress) !== peer.peerAddress) ;
const peersWithAliasesSorted = peersWithAliases.sort((a, b) => {
if (getAliasByPeerAddress(b.peerAddress).toLowerCase() > getAliasByPeerAddress(a.peerAddress).toLowerCase()) {
return -1;
}
if (getAliasByPeerAddress(b.peerAddress).toLowerCase() < getAliasByPeerAddress(a.peerAddress).toLowerCase()) {
return 1;
}
return 0
});
const peersWithoutAliases = (channelsOutgoing || []).filter(peer => aliases && peer.peerAddress && getAliasByPeerAddress(peer.peerAddress) === peer.peerAddress) ;
const peersWithoutAliasesSorted = peersWithoutAliases.sort((a, b) => {
if (b.peerAddress > a.peerAddress) {
return -1;
}
if (b.peerAddress < a.peerAddress) {
return 1;
}
return 0
});

const peersSorted = [...peersWithAliasesSorted, ...peersWithoutAliasesSorted]

const parsedTableData = peersSorted.map((channel, index) => {
const id = channel.id;
if (
!channelsOutgoingObject[id].peerAddress ||
!channelsOutgoingObject[id].balance ||
Expand Down

0 comments on commit 1f4eb88

Please sign in to comment.