Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.1.13 #651

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/components/ConnectNode/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect, useRef } from 'react';
import styled from '@emotion/styled';
import { Link, useNavigate } from 'react-router-dom';

Check warning on line 3 in src/components/ConnectNode/index.tsx

View workflow job for this annotation

GitHub Actions / Build (20.x)

'Link' is defined but never used

Check warning on line 3 in src/components/ConnectNode/index.tsx

View workflow job for this annotation

GitHub Actions / Build (22.x)

'Link' is defined but never used
import { toHexMD5, generateBase64Jazz } from '../../utils/functions';

// Components
Expand All @@ -23,7 +23,7 @@
display: flex;
flex-direction: row;
gap: 10px;
height: 59px;
height: 54px;
width: 240px;
border-radius: 0;
div {
Expand Down
5 changes: 3 additions & 2 deletions src/components/Modal/node/PingModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const PingModal = (props: PingModalProps) => {
const dispatch = useAppDispatch();
const loginData = useAppSelector((selector) => selector.auth.loginData);
const aliases = useAppSelector((store) => store.node.aliases.data);
const pinging = useAppSelector((store) => store.node.pinging);
const peerIdToAliasLink = useAppSelector((store) => store.node.links.peerIdToAlias);
const [peerId, set_peerId] = useState<string>(props.peerId ? props.peerId : '');
const [openModal, set_OpenModal] = useState(false);
Expand Down Expand Up @@ -123,8 +124,8 @@ export const PingModal = (props: PingModalProps) => {
)
}
onClick={peerId ? handlePing : handleOpenModal}
disabled={props.disabled}
pending={disableButton}
disabled={props.disabled || pinging[peerId]}
pending={disableButton || pinging[peerId] }
/>
<SDialog
open={openModal}
Expand Down
4 changes: 2 additions & 2 deletions src/components/NotificationBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { useAppDispatch, useAppSelector } from '../../store';
import { appActions } from '../../store/slices/app';

const Container = styled.div`
height: 59px;
width: 59px;
height: 54px;
width: 54px;
border-left: 1px lightgray solid;
border-right: 1px lightgray solid;
`;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Overlays/LoadingOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const css = `

@media screen and (min-width: 500px) {
.drawerOpen .Overlay {
margin-left: 240px;
margin-left: 220px;
width: calc( 100% - 240px - 32px);
Comment on lines +45 to 46
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix inconsistent width calculation

There's an inconsistency in the dimensions:

  • margin-left is set to 220px
  • But the width calculation still uses 240px: calc(100% - 240px - 32px)

This mismatch could cause layout issues. The width calculation should be updated to match the new margin.

  .drawerOpen .Overlay {
    margin-left: 220px;
-   width: calc( 100% - 240px - 32px);
+   width: calc( 100% - 220px - 32px);
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
margin-left: 220px;
width: calc( 100% - 240px - 32px);
margin-left: 220px;
width: calc( 100% - 220px - 32px);

}

Expand Down
39 changes: 28 additions & 11 deletions src/future-hopr-lib-components/Layout/drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import { ApplicationMapType } from '../../router';
import Details from '../../components/InfoBar/details';
import { rounder2 } from '../../utils/functions';

const drawerWidth = 240;
const minDrawerWidth = 56;
export const drawerWidth = 190;
export const minDrawerWidth = 46;

const StyledDrawer = styled(MuiDrawer)`
.MuiDrawer-paper {
box-sizing: border-box;
padding-top: 59px;
padding-top: 54px;
transition: width 0.4s ease-out;
overflow-x: hidden;
scrollbar-width: none;
Expand Down Expand Up @@ -81,24 +81,38 @@ const StyledDrawer = styled(MuiDrawer)`
const StyledListSubheader = styled(ListSubheader)`
align-items: center;
display: flex;
height: 64px;
height: 42px;
letter-spacing: 0.2px;
font-size: 13px;
user-select: none;
color: #777;
justify-content: center;
.MuiListItemIcon-root {
min-width: 34px;
&.NavigationDrawerClosed{
padding-left: 10px;
}
}

`;

const StyledListItemButton = styled(ListItemButton)`
height: 48px;
height: 38px;
fill: rgba(0, 0, 0, 0.54);
width: 100%;
padding-right: 10px;
padding-left: 12px;
.MuiListItemIcon-root {
min-width: 48px;
min-width: 40px;
svg {
width: 24px;
height: 24px;
width: 22px;
height: 22px;
}
}
.MuiTypography-root {
font-size: 12.5px;
white-space: nowrap;
}
&.Mui-selected {
color: #0000b4;
fill: #0000b4;
Expand All @@ -125,7 +139,7 @@ const SListItemIcon = styled(ListItemIcon)`
`;

const Numbers = styled.div`
font-size: 11px;
font-size: 10px;
background-color: #ddeaff;
padding: 3px;
`;
Expand Down Expand Up @@ -201,14 +215,17 @@ const Drawer = ({
<List
subheader={
openedNavigationDrawer ? (
<StyledListSubheader className="StyledListSubheader">{group.groupName}</StyledListSubheader>
<StyledListSubheader className="StyledListSubheader">
<SListItemIcon className="SListItemIcon GroupIcon">{group.icon}</SListItemIcon>
{group.groupName}
</StyledListSubheader>
) : (
<Tooltip
title={`Group: ${group.groupName.toLowerCase()}`}
placement="right"
>
<StyledListSubheader className="StyledListSubheader">
<SListItemIcon className="SListItemIcon GroupIcon">{group.icon}</SListItemIcon>
<SListItemIcon className={`SListItemIcon GroupIcon NavigationDrawerClosed`}>{group.icon}</SListItemIcon>
</StyledListSubheader>
</Tooltip>
)
Expand Down
6 changes: 4 additions & 2 deletions src/future-hopr-lib-components/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { ApplicationMapType } from '../../router';
import { useAppSelector } from '../../store';
import { loadStateFromLocalStorage, saveStateToLocalStorage } from '../../utils/localStorage';

import { drawerWidth, minDrawerWidth } from './drawer';

const SLayout = styled.div`
&.webapp {
.Section.full-height-min {
Expand All @@ -32,12 +34,12 @@ type ContentType = {
};

const Content = styled.div<ContentType>`
margin-top: 60px;
margin-top: 55px;
margin-left: 0;

transition: margin-left 0.4s ease-out;
@media (min-width: 500px) {
margin-left: ${(props) => (props.openedNavigationDrawer ? '240px' : '56px')};
margin-left: ${(props) => (props.openedNavigationDrawer ? `${drawerWidth}px` : `${minDrawerWidth}px`)};
}

${(props) =>
Expand Down
2 changes: 1 addition & 1 deletion src/future-hopr-lib-components/Navbar/navBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface AppBarProps extends MuiAppBarProps {

const AppBar = styled(({ tallerNavBarOnMobile, webapp, ...rest }: AppBarProps) => <MuiAppBar {...rest} />)`
background: white;
height: 60px;
height: 55px;
border-bottom: 1px lightgray solid;
box-shadow: unset;
z-index: 1201;
Expand Down
1 change: 0 additions & 1 deletion src/future-hopr-lib-components/Section/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const SSection = styled.section`
`;

const Content = styled.div`
max-width: 1098px;
margin: auto;
display: flex;
flex-direction: column;
Expand Down
1 change: 1 addition & 0 deletions src/pages/node/info/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ function InfoPage() {
const w = window.open(externalUrl, '_blank');
w && w.focus();
}}
style={{paddingTop: '2px'}}
/>
</>
}
Expand Down
110 changes: 0 additions & 110 deletions src/pages/node/ping.tsx

This file was deleted.

37 changes: 21 additions & 16 deletions src/store/slices/node/actionsAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1444,24 +1444,29 @@ export const createAsyncReducer = (builder: ActionReducerMapBuilder<typeof initi
state.messages.isDeleting = false;
});
// pingNode
builder.addCase(pingNodeThunk.pending, (state, action) => {
if (action.meta.arg.apiEndpoint !== state.apiEndpoint) return;
const peerId = action.meta.arg.peerId
if(peerId && !state.pinging[peerId]){
state.pinging[peerId] = true;
}
});
builder.addCase(pingNodeThunk.fulfilled, (state, action) => {
if (action.meta.arg.apiEndpoint !== state.apiEndpoint) return;
if (action.payload) {
const pingExists = state.pings.findIndex((ping) => ping.peerId === action.payload?.peerId);

if (pingExists) {
state.pings[pingExists] = {
latency: action.payload.latency,
peerId: action.payload.peerId,
reportedVersion: action.payload.reportedVersion,
};
} else {
state.pings.push({
latency: action.payload.latency,
peerId: action.payload.peerId,
reportedVersion: action.payload.reportedVersion,
});
}
const peerId = action.meta.arg.peerId;
if(peerId && state.pinging[peerId]){
const next = {...state.pinging}
delete next[peerId]
state.pinging = next;
}
});
builder.addCase(pingNodeThunk.rejected, (state, action) => {
if (action.meta.arg.apiEndpoint !== state.apiEndpoint) return;
const peerId = action.meta.arg.peerId;
if(peerId && state.pinging[peerId]){
const next = {...state.pinging}
delete next[peerId]
state.pinging = next;
}
Comment on lines 1455 to 1470
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Reduce code duplication in ping state management

The fulfilled and rejected cases contain identical code for removing the ping status. Consider extracting this logic into a helper function.

+  const removePingStatus = (state: typeof initialState, peerId: string) => {
+    if (peerId && state.pinging[peerId]) {
+      delete state.pinging[peerId];
+    }
+  };

   builder.addCase(pingNodeThunk.fulfilled, (state, action) => {
     if (action.meta.arg.apiEndpoint !== state.apiEndpoint) return;
     const peerId = action.meta.arg.peerId;
-    if(peerId && state.pinging[peerId]){
-      const next = {...state.pinging}
-      delete next[peerId]
-      state.pinging = next;
-    }
+    removePingStatus(state, peerId);
   });

   builder.addCase(pingNodeThunk.rejected, (state, action) => {
     if (action.meta.arg.apiEndpoint !== state.apiEndpoint) return;
     const peerId = action.meta.arg.peerId;
-    if(peerId && state.pinging[peerId]){
-      const next = {...state.pinging}
-      delete next[peerId]
-      state.pinging = next;
-    }
+    removePingStatus(state, peerId);
   });

Additionally, the object spread operation is unnecessary since we can directly modify the state object in Redux Toolkit.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (action.meta.arg.apiEndpoint !== state.apiEndpoint) return;
if (action.payload) {
const pingExists = state.pings.findIndex((ping) => ping.peerId === action.payload?.peerId);
if (pingExists) {
state.pings[pingExists] = {
latency: action.payload.latency,
peerId: action.payload.peerId,
reportedVersion: action.payload.reportedVersion,
};
} else {
state.pings.push({
latency: action.payload.latency,
peerId: action.payload.peerId,
reportedVersion: action.payload.reportedVersion,
});
}
const peerId = action.meta.arg.peerId;
if(peerId && state.pinging[peerId]){
const next = {...state.pinging}
delete next[peerId]
state.pinging = next;
}
});
builder.addCase(pingNodeThunk.rejected, (state, action) => {
if (action.meta.arg.apiEndpoint !== state.apiEndpoint) return;
const peerId = action.meta.arg.peerId;
if(peerId && state.pinging[peerId]){
const next = {...state.pinging}
delete next[peerId]
state.pinging = next;
}
const removePingStatus = (state: typeof initialState, peerId: string) => {
if (peerId && state.pinging[peerId]) {
delete state.pinging[peerId];
}
};
builder.addCase(pingNodeThunk.fulfilled, (state, action) => {
if (action.meta.arg.apiEndpoint !== state.apiEndpoint) return;
const peerId = action.meta.arg.peerId;
removePingStatus(state, peerId);
});
builder.addCase(pingNodeThunk.rejected, (state, action) => {
if (action.meta.arg.apiEndpoint !== state.apiEndpoint) return;
const peerId = action.meta.arg.peerId;
removePingStatus(state, peerId);
});

});
// deleteToken
Expand Down
6 changes: 4 additions & 2 deletions src/store/slices/node/initialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ type InitialState = {
tokens: { data: GetTokenResponseType[]; isFetching: boolean };
version: { data: string | null; isFetching: boolean };
transactions: { data: string[]; isFetching: boolean };
pings: (PingPeerResponseType & { peerId: string })[];
pinging: {
[peerId: string]: true
};
metrics: {
data: {
raw: string | null;
Expand Down Expand Up @@ -342,7 +344,7 @@ export const initialState: InitialState = {
data: [],
isFetching: false,
},
pings: [],
pinging: {},
metrics: {
data: {
raw: null,
Expand Down
Loading