Skip to content

Commit

Permalink
Fix more linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Reckless-Satoshi committed Aug 10, 2023
1 parent 3aa03f0 commit 6f4ad17
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 159 deletions.
19 changes: 13 additions & 6 deletions frontend/src/components/SettingsForm/SelectLanguage.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { Select, MenuItem, useTheme, Grid, Typography } from '@mui/material';
import type Language from '../../models/Language.model';
import {
Select,
MenuItem,
useTheme,
Grid,
Typography,
type SelectChangeEvent,
} from '@mui/material';

import Flags from 'country-flag-icons/react/3x2';
import { CataloniaFlag, BasqueCountryFlag } from '../Icons';
import type { Language } from '../../models';

const menuLanuguages = [
{ name: 'English', i18nCode: 'en', flag: Flags.US },
Expand All @@ -30,18 +37,18 @@ interface SelectLanguageProps {
setLanguage: (lang: Language) => void;
}

const SelectLanguage = ({ language, setLanguage }: SelectLanguageProps): JSX.Element => {
const SelectLanguage: React.FC<SelectLanguageProps> = ({ language, setLanguage }) => {
const theme = useTheme();
const { t, i18n } = useTranslation();
const { i18n } = useTranslation();

const flagProps = {
width: 1.5 * theme.typography.fontSize,
height: 1.5 * theme.typography.fontSize,
};

const handleChangeLang = function (e: any) {
const handleChangeLang = function (e: SelectChangeEvent): void {
setLanguage(e.target.value);
i18n.changeLanguage(e.target.value);
void i18n.changeLanguage(e.target.value);
};

return (
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/SettingsForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ const SettingsForm = ({ dense = false }: SettingsFormProps): JSX.Element => {
</ListItemIcon>
<Slider
value={settings.fontSize}
min={settings.frontend == 'basic' ? 12 : 10}
max={settings.frontend == 'basic' ? 16 : 14}
min={settings.frontend === 'basic' ? 12 : 10}
max={settings.frontend === 'basic' ? 16 : 14}
step={1}
onChange={(e) => {
const fontSize = e.target.value;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/TradeBox/BondStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const BondStatus = ({ status, isMaker }: BondStatusProps): JSX.Element => {
let color = 'primary';
if (status === 'unlocked') {
Icon = LockOpen;
color = theme.palette.mode == 'dark' ? 'lightgreen' : 'green';
color = theme.palette.mode === 'dark' ? 'lightgreen' : 'green';
} else if (status === 'settled') {
Icon = Balance;
color = theme.palette.mode == 'dark' ? 'lightred' : 'red';
color = theme.palette.mode === 'dark' ? 'lightred' : 'red';
}

if (status === 'hide') {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/TradeBox/CollabCancelAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const CollabCancelAlert = ({ order }: CollabCancelAlertProps): JSX.Element => {
text = t('You asked for a collaborative cancellation');
}

return text != '' ? (
return text !== '' ? (
<Alert severity='warning' style={{ width: '100%' }}>
{text}
</Alert>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const ConfirmFiatReceivedDialog = ({
}: ConfirmFiatReceivedDialogProps): JSX.Element => {
const { t } = useTranslation();
const currencyCode = currencies[order.currency.toString()];
const amount = pn(parseFloat(parseFloat(order.amount).toFixed(order.currency == 1000 ? 8 : 4)));
const amount = pn(parseFloat(parseFloat(order.amount).toFixed(order.currency === 1000 ? 8 : 4)));

return (
<Dialog open={open} onClose={onClose}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const ConfirmFiatSentDialog = ({
}: ConfirmFiatSentDialogProps): JSX.Element => {
const { t } = useTranslation();
const currencyCode = currencies[order.currency.toString()];
const amount = pn(parseFloat(parseFloat(order.amount).toFixed(order.currency == 1000 ? 8 : 4)));
const amount = pn(parseFloat(parseFloat(order.amount).toFixed(order.currency === 1000 ? 8 : 4)));

return (
<Dialog open={open} onClose={onClose}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const ConfirmUndoFiatSentDialog = ({
}
}, [time, open]);

const onClick = () => {
const onClick = (): void => {
onConfirmClick();
setTime(300);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { Grid, useTheme, Tooltip, Button } from '@mui/material';
import React from 'react';
import { Grid, Tooltip, Button } from '@mui/material';
import { ExportIcon } from '../../../Icons';
import KeyIcon from '@mui/icons-material/Key';
import { useTranslation } from 'react-i18next';
Expand All @@ -15,7 +15,6 @@ interface Props {

const ChatBottom: React.FC<Props> = ({ orderId, setAudit, audit, createJsonFile }) => {
const { t } = useTranslation();
const theme = useTheme();

return (
<Grid
Expand Down Expand Up @@ -62,7 +61,7 @@ const ChatBottom: React.FC<Props> = ({ orderId, setAudit, audit, createJsonFile
color='primary'
variant='outlined'
onClick={() => {
saveAsJson('complete_log_chat_' + orderId + '.json', createJsonFile());
saveAsJson(`complete_log_chat_${orderId}.json`, createJsonFile());
}}
>
<div style={{ width: '1.4em', height: '1.4em' }}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useLayoutEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Button, Tooltip, TextField, Grid, Paper, Typography } from '@mui/material';
import { Button, TextField, Grid, Paper, Typography } from '@mui/material';
import { encryptMessage, decryptMessage } from '../../../../pgp';
import { AuditPGPDialog } from '../../../Dialogs';
import { websocketClient, type WebsocketConnection } from '../../../../services/Websocket';
Expand Down Expand Up @@ -87,18 +87,18 @@ const EncryptedSocketChat: React.FC<Props> = ({

useEffect(() => {
if (messages.length > messageCount) {
audio.play();
void audio.play();
setMessageCount(messages.length);
}
}, [messages, messageCount]);

useEffect(() => {
if (serverMessages) {
if (serverMessages.length > 0) {
serverMessages.forEach(onMessage);
}
}, [serverMessages]);

const connectWebsocket = () => {
const connectWebsocket = (): void => {
websocketClient
.open(
`ws://${window.location.host}/ws/chat/${orderId}/?token_sha256_hex=${sha256(robot.token)}`,
Expand All @@ -121,6 +121,9 @@ const EncryptedSocketChat: React.FC<Props> = ({
connection.onError(() => {
setConnected(false);
});
})
.catch(() => {
setConnected(false);
});
};

Expand All @@ -139,14 +142,14 @@ const EncryptedSocketChat: React.FC<Props> = ({
const onMessage: (message: any) => void = (message) => {
const dataFromServer = JSON.parse(message.data);

if (dataFromServer && !receivedIndexes.includes(dataFromServer.index)) {
if (dataFromServer != null && !receivedIndexes.includes(dataFromServer.index)) {
setReceivedIndexes((prev) => [...prev, dataFromServer.index]);
setPeerConnected(dataFromServer.peer_connected);
// If we receive a public key other than ours (our peer key!)
if (
connection != null &&
dataFromServer.message.substring(0, 36) == `-----BEGIN PGP PUBLIC KEY BLOCK-----` &&
dataFromServer.message != robot.pubKey
dataFromServer.message.substring(0, 36) === `-----BEGIN PGP PUBLIC KEY BLOCK-----` &&
dataFromServer.message !== robot.pubKey
) {
setPeerPubKey(dataFromServer.message);
connection.send({
Expand All @@ -155,71 +158,67 @@ const EncryptedSocketChat: React.FC<Props> = ({
});
}
// If we receive an encrypted message
else if (dataFromServer.message.substring(0, 27) == `-----BEGIN PGP MESSAGE-----`) {
decryptMessage(
else if (dataFromServer.message.substring(0, 27) === `-----BEGIN PGP MESSAGE-----`) {
void decryptMessage(
dataFromServer.message.split('\\').join('\n'),
dataFromServer.user_nick == userNick ? robot.pubKey : peerPubKey,
dataFromServer.user_nick === userNick ? robot.pubKey : peerPubKey,
robot.encPrivKey,
robot.token,
).then((decryptedData) => {
setWaitingEcho(waitingEcho ? decryptedData.decryptedMessage !== lastSent : false);
setLastSent(decryptedData.decryptedMessage === lastSent ? '----BLANK----' : lastSent);
setMessages((prev) => {
const existingMessage = prev.find((item) => item.index === dataFromServer.index);
if (existingMessage) {
if (existingMessage != null) {
return prev;
} else {
return [
...prev,
{
index: dataFromServer.index,
encryptedMessage: dataFromServer.message.split('\\').join('\n'),
plainTextMessage: decryptedData.decryptedMessage,
validSignature: decryptedData.validSignature,
userNick: dataFromServer.user_nick,
time: dataFromServer.time,
} as EncryptedChatMessage,
].sort((a, b) => a.index - b.index);
const x: EncryptedChatMessage = {
index: dataFromServer.index,
encryptedMessage: dataFromServer.message.split('\\').join('\n'),
plainTextMessage: String(decryptedData.decryptedMessage),
validSignature: decryptedData.validSignature,
userNick: dataFromServer.user_nick,
time: dataFromServer.time,
};
return [...prev, x].sort((a, b) => a.index - b.index);
}
});
});
}
// We allow plaintext communication. The user must write # to start
// If we receive an plaintext message
else if (dataFromServer.message.substring(0, 1) == '#') {
else if (dataFromServer.message.substring(0, 1) === '#') {
setMessages((prev: EncryptedChatMessage[]) => {
const existingMessage = prev.find(
(item) => item.plainTextMessage === dataFromServer.message,
);
if (existingMessage != null) {
return prev;
} else {
return [
...prev,
{
index: prev.length + 0.001,
encryptedMessage: dataFromServer.message,
plainTextMessage: dataFromServer.message,
validSignature: false,
userNick: dataFromServer.user_nick,
time: new Date().toString(),
} as EncryptedChatMessage,
].sort((a, b) => a.index - b.index);
const x: EncryptedChatMessage = {
index: prev.length + 0.001,
encryptedMessage: dataFromServer.message,
plainTextMessage: dataFromServer.message,
validSignature: false,
userNick: dataFromServer.user_nick,
time: new Date().toString(),
};
return [...prev, x].sort((a, b) => a.index - b.index);
}
});
}
}
};

const onButtonClicked = (e: any) => {
if (robot.token && value.includes(robot.token)) {
const onButtonClicked = (e: React.FormEvent<HTMLFormElement>): void => {
if (robot.token !== undefined && value.includes(robot.token)) {
alert(
`Aye! You just sent your own robot robot.token to your peer in chat, that's a catastrophic idea! So bad your message was blocked.`,
);
setValue('');
}
// If input string contains '#' send unencrypted and unlogged message
else if (connection != null && value.substring(0, 1) == '#') {
else if (connection != null && value.substring(0, 1) === '#') {
connection.send({
message: value,
nick: userNick,
Expand All @@ -228,15 +227,15 @@ const EncryptedSocketChat: React.FC<Props> = ({
}

// Else if message is not empty send message
else if (value != '') {
else if (value !== '') {
setValue('');
setWaitingEcho(true);
setLastSent(value);
encryptMessage(value, robot.pubKey, peerPubKey, robot.encPrivKey, robot.token)
.then((encryptedMessage) => {
if (connection != null) {
connection.send({
message: encryptedMessage.toString().split('\n').join('\\'),
message: String(encryptedMessage).split('\n').join('\\'),
nick: userNick,
});
}
Expand All @@ -263,17 +262,17 @@ const EncryptedSocketChat: React.FC<Props> = ({
}}
orderId={Number(orderId)}
messages={messages}
ownPubKey={robot.pubKey || ''}
ownEncPrivKey={robot.encPrivKey || ''}
peerPubKey={peerPubKey || 'Not received yet'}
passphrase={robot.token || ''}
ownPubKey={robot.pubKey ?? ''}
ownEncPrivKey={robot.encPrivKey ?? ''}
peerPubKey={peerPubKey ?? 'Not received yet'}
passphrase={robot.token ?? ''}
onClickBack={() => {
setAudit(false);
}}
/>
<Grid item>
<ChatHeader
connected={connected && !!peerPubKey}
connected={connected && Boolean(peerPubKey)}
peerConnected={peerConnected}
turtleMode={turtleMode}
setTurtleMode={setTurtleMode}
Expand Down Expand Up @@ -326,7 +325,7 @@ const EncryptedSocketChat: React.FC<Props> = ({
}}
helperText={
connected
? peerPubKey
? peerPubKey !== undefined
? null
: t('Waiting for peer public key...')
: t('Connecting...')
Expand All @@ -341,7 +340,7 @@ const EncryptedSocketChat: React.FC<Props> = ({
<Grid item alignItems='stretch' style={{ display: 'flex' }} xs={3}>
<Button
fullWidth={true}
disabled={!connected || waitingEcho || !peerPubKey}
disabled={!connected || waitingEcho || peerPubKey === undefined}
type='submit'
variant='contained'
color='primary'
Expand Down
Loading

0 comments on commit 6f4ad17

Please sign in to comment.