Skip to content

Commit

Permalink
eslint fixes and close all apps
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvsadana committed Aug 7, 2023
1 parent dc63eec commit c262524
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module.exports = {
'@typescript-eslint/no-shadow': 'error',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'react-hooks/exhaustive-deps': 'warn',
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
'react/require-default-props': 'off',
'no-use-before-define': 'off',
},
parserOptions: {
ecmaVersion: 2020,
Expand Down
2 changes: 0 additions & 2 deletions src/main/madara-app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable no-plusplus */
/* eslint-disable no-await-in-loop */
/* eslint-disable no-use-before-define */
import { ChildProcess, exec, execSync } from 'child_process';
import { BrowserWindow } from 'electron';
import { download } from 'electron-dl';
Expand Down
1 change: 0 additions & 1 deletion src/main/madara.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export async function setup(window: BrowserWindow, config: MadaraConfig) {

const notDownloadedFiles = getNotDownloadedFiles(config);

// eslint-disable-next-line no-plusplus
for (let i = 0; i < notDownloadedFiles.length; i++) {
const file = notDownloadedFiles[i];
const opts: {
Expand Down
1 change: 0 additions & 1 deletion src/renderer/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react-hooks/exhaustive-deps */
import axios from 'axios';
import { useEffect } from 'react';
import { Route, Routes, useLocation, useNavigate } from 'react-router-dom';
Expand Down
1 change: 0 additions & 1 deletion src/renderer/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/require-default-props */
import { styled } from 'styled-components';

const ButtonContainer = styled.button`
Expand Down
1 change: 0 additions & 1 deletion src/renderer/components/InfiniteBarLoader.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// taken from here https://csslayout.io/indeterminate-progress-bar/
/* eslint-disable react/require-default-props */

import { CSSProperties } from 'react';
import { styled } from 'styled-components';
Expand Down
1 change: 0 additions & 1 deletion src/renderer/components/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/require-default-props */
import React, { CSSProperties } from 'react';
import { styled } from 'styled-components';

Expand Down
21 changes: 18 additions & 3 deletions src/renderer/features/appsSlice.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { createSlice } from '@reduxjs/toolkit';
import { getStore } from 'renderer/store/storeRegistry';

const initialState = {
type InstalledApps = { [appId: string]: boolean };
type RunningApps = { [appId: string]: boolean };
const initialState: {
installedApps: InstalledApps;
runningApps: RunningApps;
} = {
installedApps: {},
runningApps: {},
};
Expand All @@ -22,8 +27,9 @@ export const appsSlice = createSlice({

export const { setInstalledApps, setRunningApps } = appsSlice.actions;

export const selectInstalledApps = (state: any) => state.apps.installedApps;
export const selectRunningApps = (state: any) => {
export const selectInstalledApps = (state: any): InstalledApps =>
state.apps.installedApps;
export const selectRunningApps = (state: any): RunningApps => {
return state.apps.runningApps;
};

Expand All @@ -45,6 +51,15 @@ export const setupInstalledApps = () => async (dispatch: any) => {
dispatch(setInstalledApps(installedApps));
};

export const closeAllApps = () => async (dispatch: any, getState: any) => {
const runningApps = selectRunningApps(getState());
Object.entries(runningApps).forEach(([appId, isRunning]) => {
if (isRunning) {
window.electron.ipcRenderer.madaraApp.stopApp(appId);
}
});
};

// listener to know when an app is running
window.electron.ipcRenderer.madaraApp.onAppStart(
(event: any, data: { appId: string }) =>
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/features/nodeSlice.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createSlice } from '@reduxjs/toolkit';
import { MadaraConfig } from 'main/types';
import { getStore } from 'renderer/store/storeRegistry';
import { closeAllApps } from './appsSlice';

export type configTypes =
| 'RPCCors'
Expand Down Expand Up @@ -106,6 +107,7 @@ export const stopNode = () => async (dispatch: any, getState: any) => {
export const deleteNode = () => async (dispatch: any) => {
dispatch(setIsRunning(false));
dispatch(setLogs(''));
dispatch(closeAllApps());
await window.electron.ipcRenderer.madara.delete();
};

Expand Down
1 change: 0 additions & 1 deletion src/renderer/features/walletSlice.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-use-before-define */
import { createSlice } from '@reduxjs/toolkit';
import * as starknet from 'starknet';
import erc20Abi from '../../../config/abi/erc20.json';
Expand Down
1 change: 0 additions & 1 deletion src/renderer/pages/Apps.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { faPause, faPlay } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { Progress } from 'electron-dl';
Expand Down
18 changes: 9 additions & 9 deletions src/renderer/pages/Telemetry.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { AnimatePresence, motion } from 'framer-motion';
import { useEffect, useState } from 'react';
import InfiniteBarLoader from 'renderer/components/InfiniteBarLoader';
import { selectConfig } from 'renderer/features/nodeSlice';
import { useAppSelector } from 'renderer/utils/hooks';
import { styled } from 'styled-components';

const TelemetryContainer = styled.div`
Expand Down Expand Up @@ -39,15 +41,11 @@ const BANNER_SEEN_KEY = 'banner_seen';
export default function Telemetry() {
const [loading, setLoading] = useState(true);
const [isBannerVisible, setIsBannerVisible] = useState(false);
const nodeConig = useAppSelector(selectConfig);

useEffect(() => {
const bannerSeen = sessionStorage.getItem(BANNER_SEEN_KEY);
if (bannerSeen === 'true') {
setIsBannerVisible(false);
} else {
setIsBannerVisible(true);
setTimeout(() => setIsBannerVisible(false), 5000);
}
setIsBannerVisible(true);
setTimeout(() => setIsBannerVisible(false), 5000);
}, []);

const handleLoad = () => {
Expand Down Expand Up @@ -76,8 +74,10 @@ export default function Telemetry() {
exit={{ y: '200%' }}
>
<Banner>
It can take a few minutes for your node to reflect here. Kindly
check the Logs for any errors
{nodeConig.testnet !== 'sharingan'
? `You must set the testnet to "sharingan" to see your node here.`
: `It can take a few minutes for your node to reflect here. Kindly
check the Logs for any errors`}
</Banner>
</BannerContainer>
)}
Expand Down
1 change: 0 additions & 1 deletion src/renderer/pages/Wallet.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { useEffect } from 'react';
import Button from 'renderer/components/Button';
import Input from 'renderer/components/Input';
Expand Down

0 comments on commit c262524

Please sign in to comment.