Skip to content

Commit

Permalink
Merge pull request #16 from Chia-Network/develop
Browse files Browse the repository at this point in the history
release: 1.3.2
  • Loading branch information
TheLastCicada authored Oct 5, 2023
2 parents 4f94946 + 29aca01 commit 5c3f52c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "core-registry-cadt-ui",
"version": "1.3.1",
"version": "1.3.2",
"private": true,
"author": "Chia Network Inc. <[email protected]>",
"homepage": "./",
Expand Down
8 changes: 4 additions & 4 deletions src/components/blocks/LeftNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const StyledTitleContainer = styled('div')`
margin: 46px 0px 1.3125rem 1.3rem;
`;

const LeftNav = withTheme(({ children }) => {
const LeftNav = withTheme(({ children, theme }) => {
const location = useLocation();
const [confirmCreateOrgIsVisible, setConfirmCreateOrgIsVisible] =
useState(false);
Expand Down Expand Up @@ -110,8 +110,8 @@ const LeftNav = withTheme(({ children }) => {
<NavContainer>
<StyledTitleContainer>
<WarehouseIcon height={24} width={24} color="#6e7d7f" />
<ButtonText>
<FormattedMessage id="warehouse" />
<ButtonText color={theme.colors.default.primary}>
<FormattedMessage id="cadt" />
</ButtonText>
</StyledTitleContainer>
<MenuItem selected={isProjectsPage && !isMyRegistryPage} to="/projects">
Expand All @@ -133,7 +133,7 @@ const LeftNav = withTheme(({ children }) => {
<StyledTitleContainer disabled={!isMyOrgCreated || isMyOrgPending}>
{isMyOrgPending && <CircularProgress size={20} thickness={5} />}
{!isMyOrgPending && <RegistryIcon height={20} width={20} />}
<ButtonText>
<ButtonText color={theme.colors.default.primary}>
<FormattedMessage id="my-registry" />
</ButtonText>
</StyledTitleContainer>
Expand Down
34 changes: 28 additions & 6 deletions src/store/actions/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const SOCKET_STATUS = keyMirror(
let socket;
let interval;
let reconnectInterval = 1000;
let reconnectAttempts = 0;

const notifyRefresh = _.debounce(dispatch => {
NotificationManager.info(
Expand All @@ -33,7 +34,7 @@ const notifyRefresh = _.debounce(dispatch => {
() => dispatch(refreshApp(true)),
true,
);
}, 100);
}, 1000);

const initListenersForEachMessageType = dispatch => {
Object.keys(messageTypes).forEach(key => {
Expand Down Expand Up @@ -84,20 +85,35 @@ export const emitAction = actionCreator => {
};

const reconnectSocket = _.debounce(dispatch => {
if (!socket || (socket && !socket.connected)) {
if (reconnectAttempts <= 10 && (!socket || !socket.connected)) {
console.log(
'Attempting to reconnect to socket server...',
reconnectAttempts,
);
dispatch(initiateSocket());
setTimeout(() => {
if (!socket || (socket && !socket.connected)) {
if (!socket || !socket.connected) {
reconnectSocket(dispatch);
}
reconnectInterval = reconnectInterval * 2;
reconnectInterval *= 2;
}, reconnectInterval);
} else if (reconnectAttempts > 10) {
console.log("Couldn't connect to socket server. Max attempts reached.");
dispatch(setSocketStatus(SOCKET_STATUS.OFFLINE));

clearInterval(interval);
}
}, 100);
}, 1000);

export const initiateSocket = remoteHost => {
disconnectSocket();

if (reconnectAttempts > 10) {
return;
}

reconnectAttempts++;

const WS_HOST = `${remoteHost || constants.API_HOST}/ws`;
const transports = ['websocket'];

Expand Down Expand Up @@ -158,16 +174,22 @@ export const initiateSocket = remoteHost => {
console.log('Attempting to connect to socket_id: ', socket.id);
console.log('### Socket Connected ###');
dispatch(setSocketStatus(SOCKET_STATUS.CONNECTED));
reconnectAttempts = 0;
socket.emit('authentication');
});

initListenersForEachMessageType(dispatch);

interval = setInterval(() => {
if (!socket || (socket && !socket.connected)) {
if (reconnectAttempts <= 10 && (!socket || !socket.connected)) {
dispatch(setSocketStatus(SOCKET_STATUS.OFFLINE));
clearInterval(interval);
reconnectSocket(dispatch);
} else if (reconnectAttempts > 10) {
console.log("Couldn't connect to socket server. Max attempts reached.");
dispatch(setSocketStatus(SOCKET_STATUS.OFFLINE));
clearInterval(interval);
disconnectSocket();
}
}, 5000);
};
Expand Down
1 change: 1 addition & 0 deletions src/translations/tokens/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
"no-failed": "No failed data at this time",
"projects": "Projects",
"warehouse": "Warehouse",
"cadt": "CAD Trust",
"units": "Units",
"storybook": "Storybook",
"current-registry": "Current Registry",
Expand Down

0 comments on commit 5c3f52c

Please sign in to comment.