Skip to content

Commit

Permalink
Fix linting errors on federation-layer (#776)
Browse files Browse the repository at this point in the history
* Fix lint errors

* Fix more linting issues

* Fix more linting issues

* Fix more linting issues

* Fix more linting issues

* Fix more linting issues

* Fix more linting issues

* Fix more linting issues

* Fix more linting issues

* Fix more linting issues

* Fix more linting issues

* Fix more linting issues, only 1 left

* Last fix
  • Loading branch information
Reckless-Satoshi committed Aug 13, 2023
1 parent 65b1e2c commit 68bb2de
Show file tree
Hide file tree
Showing 129 changed files with 1,537 additions and 1,234 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/js-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
pull_request:
branches:
- main
- the-federation-layer-v0.5.0
paths:
- frontend

Expand Down Expand Up @@ -41,7 +42,5 @@ jobs:
with:
prettier: true
prettier_dir: frontend

## Disabled due to error
# eslint: true
# eslint_dir: frontend
eslint: true
eslint_dir: frontend
11 changes: 10 additions & 1 deletion frontend/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@
"sourceType": "module",
"project": "./tsconfig.json"
},
"ignorePatterns": ["index.js", "**/PaymentMethods/Icons/code/code.js"],
"plugins": ["react", "react-hooks", "@typescript-eslint", "prettier"],
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"react/prop-types": "off",
"react/react-in-jsx-scope": "off"
"react/react-in-jsx-scope": "off",
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "variableLike",
"format": ["camelCase", "snake_case", "PascalCase", "UPPER_CASE"],
"leadingUnderscore": "allow"
}
]
},
"settings": {
"import/resolver": {
Expand Down
4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"dev": "webpack --watch --progress --mode development",
"test": "jest",
"build": "webpack --mode production",
"lint": "eslint src/**/*.{js,ts,tsx}",
"lint:fix": "eslint --fix 'src/**/*.{js,ts,tsx}'",
"lint": "eslint src/**/*.{js,ts,tsx} --quiet",
"lint:fix": "eslint --fix 'src/**/*.{js,ts,tsx}' --quiet",
"format": "prettier --write '**/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc"
},
"keywords": [],
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const App = (): JSX.Element => {
);
};

const loadApp = () => {
const loadApp = (): void => {
// waits until the environment is ready for the Android WebView app
if (systemClient.loading) {
setTimeout(loadApp, 200);
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/basic/BookPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const BookPage = (): JSX.Element => {
fetchFederationBook();
}, []);

const onOrderClicked = function (id: number, shortAlias: string) {
const onOrderClicked = function (id: number, shortAlias: string): void {
if (robot.avatarLoaded) {
clearOrder();
setDelay(10000);
Expand All @@ -40,7 +40,7 @@ const BookPage = (): JSX.Element => {
}
};

const NavButtons = function () {
const NavButtons = function (): JSX.Element {
return (
<ButtonGroup variant='contained' color='inherit'>
<Button
Expand All @@ -59,7 +59,7 @@ const BookPage = (): JSX.Element => {
setView(view === 'depth' ? 'list' : 'depth');
}}
>
{view == 'depth' ? (
{view === 'depth' ? (
<>
<FormatListBulleted /> {t('List')}
</>
Expand Down Expand Up @@ -95,7 +95,7 @@ const BookPage = (): JSX.Element => {
<Box sx={{ maxWidth: '18em', padding: '0.5em' }}>
<MakerForm
onOrderCreated={(id) => {
navigate('/order/' + id);
navigate(`/order/${id}`);
}}
onClickGenerateRobot={() => {
navigate('/robot');
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/basic/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const Main: React.FC = () => {
<Slide
direction={page === 'robot' ? slideDirection.in : slideDirection.out}
in={page === 'robot'}
appear={slideDirection.in != undefined}
appear={slideDirection.in !== undefined}
>
<div>
<RobotPage />
Expand All @@ -97,7 +97,7 @@ const Main: React.FC = () => {
<Slide
direction={page === 'offers' ? slideDirection.in : slideDirection.out}
in={page === 'offers'}
appear={slideDirection.in != undefined}
appear={slideDirection.in !== undefined}
>
<div>
<BookPage />
Expand All @@ -112,7 +112,7 @@ const Main: React.FC = () => {
<Slide
direction={page === 'create' ? slideDirection.in : slideDirection.out}
in={page === 'create'}
appear={slideDirection.in != undefined}
appear={slideDirection.in !== undefined}
>
<div>
<MakerPage />
Expand All @@ -127,7 +127,7 @@ const Main: React.FC = () => {
<Slide
direction={page === 'order' ? slideDirection.in : slideDirection.out}
in={page === 'order'}
appear={slideDirection.in != undefined}
appear={slideDirection.in !== undefined}
>
<div>
<OrderPage />
Expand All @@ -142,7 +142,7 @@ const Main: React.FC = () => {
<Slide
direction={page === 'settings' ? slideDirection.in : slideDirection.out}
in={page === 'settings'}
appear={slideDirection.in != undefined}
appear={slideDirection.in !== undefined}
>
<div>
<SettingsPage />
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/basic/MainDialogs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const MainDialogs = (): JSX.Element => {
limits,
robot,
setRobot,
setCurrentOrder,
settings,
federation,
clientVersion,
Expand All @@ -42,7 +41,7 @@ const MainDialogs = (): JSX.Element => {
const [maxAmount, setMaxAmount] = useState<string>('...loading...');

useEffect(() => {
if (limits.list[1000]) {
if (limits.list[1000] !== undefined) {
setMaxAmount(pn(limits.list[1000].max_amount * 100000000));
}
}, [limits.list]);
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/basic/MakerPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ const MakerPage = (): JSX.Element => {
maker.paymentMethods,
]);

const onViewOrder = function () {
const onViewOrder = function (): void {
setOrder(undefined);
setDelay(10000);
};

const onOrderClicked = function (id: number) {
const onOrderClicked = function (id: number): void {
if (robot.avatarLoaded) {
navigate('/order/' + id);
navigate(`/order/${id}`);
onViewOrder();
} else {
setOpenNoRobot(true);
Expand Down Expand Up @@ -105,7 +105,7 @@ const MakerPage = (): JSX.Element => {
>
<MakerForm
onOrderCreated={(id) => {
navigate('/order/' + id);
navigate(`/order/${id}`);
}}
disableRequest={matches.length > 0 && !showMatches}
collapseAll={showMatches}
Expand Down
26 changes: 14 additions & 12 deletions frontend/src/basic/NavBar/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useLocation, useNavigate } from 'react-router-dom';
import { Tabs, Tab, Paper, useTheme } from '@mui/material';
import MoreTooltip from './MoreTooltip';

import { type Page } from '.';
import { type Page, isPage } from '.';

import {
SettingsApplications,
Expand Down Expand Up @@ -52,32 +52,32 @@ const NavBar = (): JSX.Element => {

useEffect(() => {
// change tab (page) into the current route
const pathPage: Page = location.pathname.split('/')[1];
if (pathPage == 'index.html') {
const pathPage: Page | string = location.pathname.split('/')[1];
if (pathPage === 'index.html') {
navigate('/robot');
setPage('robot');
}
if (pathPage) {
if (isPage(pathPage)) {
setPage(pathPage);
}
}, [location]);
}, [location, navigate, setPage]);

const handleSlideDirection = function (oldPage: Page, newPage: Page) {
const handleSlideDirection = function (oldPage: Page, newPage: Page): void {
const oldPos: number = pagesPosition[oldPage];
const newPos: number = pagesPosition[newPage];
setSlideDirection(
newPos > oldPos ? { in: 'left', out: 'right' } : { in: 'right', out: 'left' },
);
};

const changePage = function (mouseEvent: any, newPage: Page) {
const changePage = function (mouseEvent: any, newPage: Page): void {
if (newPage === 'none') {
return null;
} else {
handleSlideDirection(page, newPage);
setPage(newPage);
const param =
newPage === 'order' ? `${currentOrder.shortAlias}/${currentOrder.id}` ?? '' : '';
newPage === 'order' ? `${String(currentOrder.shortAlias)}/${String(currentOrder.id)}` : '';
setTimeout(() => {
navigate(`/${newPage}/${param}`);
}, theme.transitions.duration.leavingScreen * 3);
Expand All @@ -86,7 +86,7 @@ const NavBar = (): JSX.Element => {

useEffect(() => {
setOpen(closeAll);
}, [page]);
}, [page, setOpen]);

return (
<Paper
Expand Down Expand Up @@ -115,7 +115,7 @@ const NavBar = (): JSX.Element => {
setOpen({ ...closeAll, profile: !open.profile });
}}
icon={
robot.nickname && robot.avatarLoaded ? (
robot.nickname !== undefined && robot.avatarLoaded ? (
<RobotAvatar
style={{ width: '2.3em', height: '2.3em', position: 'relative', top: '0.2em' }}
avatarClass={theme.palette.mode === 'dark' ? 'navBarAvatarDark' : 'navBarAvatar'}
Expand Down Expand Up @@ -170,8 +170,10 @@ const NavBar = (): JSX.Element => {
sx={tabSx}
label={smallBar ? undefined : t('More')}
value='none'
onClick={(e) => {
open.more ? null : setOpen({ ...open, more: true });
onClick={() => {
setOpen((open) => {
return { ...open, more: !open.more };
});
}}
icon={
<MoreTooltip>
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/basic/NavBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ import NavBar from './NavBar';

export type Page = 'robot' | 'order' | 'create' | 'offers' | 'settings' | 'none';
export default NavBar;

export function isPage(page: string): page is Page {
return ['robot', 'order', 'create', 'offers', 'settings', 'none'].includes(page);
}
27 changes: 15 additions & 12 deletions frontend/src/basic/OrderPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ const OrderPage = (): JSX.Element => {

useEffect(() => {
const newOrder = { shortAlias: params.shortAlias, id: Number(params.orderId) };
if (currentOrder != newOrder) {
if (currentOrder !== newOrder) {
clearOrder();
setCurrentOrder(newOrder);
}
}, [params.orderId]);

const renewOrder = function () {
if (order != undefined) {
const renewOrder = function (): void {
if (order !== undefined) {
const body = {
type: order.type,
currency: order.currency,
Expand All @@ -61,28 +61,31 @@ const OrderPage = (): JSX.Element => {
apiClient
.post(hostUrl, '/api/make/', body, { tokenSHA256: robot.tokenSHA256 })
.then((data: any) => {
if (data.bad_request) {
if (data.bad_request !== undefined) {
setBadOrder(data.bad_request);
} else if (data.id) {
navigate('/order/' + data.id);
} else if (data.id !== undefined) {
navigate(`/order/${String(data.id)}`);
}
})
.catch(() => {
setBadOrder('Request error');
});
}
};

const startAgain = () => {
const startAgain = (): void => {
navigate('/robot');
};

return (
<Box>
{order == undefined && badOrder == undefined ? <CircularProgress /> : null}
{badOrder != undefined ? (
{order === undefined && badOrder === undefined && <CircularProgress />}
{badOrder !== undefined ? (
<Typography align='center' variant='subtitle2' color='secondary'>
{t(badOrder)}
</Typography>
) : null}
{order != undefined && badOrder == undefined ? (
{order !== undefined && badOrder === undefined ? (
order.is_participant ? (
windowSize.width > doublePageWidth ? (
// DOUBLE PAPER VIEW
Expand Down Expand Up @@ -160,7 +163,7 @@ const OrderPage = (): JSX.Element => {
overflow: 'auto',
}}
>
<div style={{ display: tab == 'order' ? '' : 'none' }}>
<div style={{ display: tab === 'order' ? '' : 'none' }}>
<OrderDetails
order={order}
setOrder={setOrder}
Expand All @@ -172,7 +175,7 @@ const OrderPage = (): JSX.Element => {
}}
/>
</div>
<div style={{ display: tab == 'contract' ? '' : 'none' }}>
<div style={{ display: tab === 'contract' ? '' : 'none' }}>
<TradeBox
order={order}
robot={robot}
Expand Down
Loading

0 comments on commit 68bb2de

Please sign in to comment.