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 11, 2023
1 parent 6f4ad17 commit 502cf4c
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 135 deletions.
10 changes: 9 additions & 1 deletion frontend/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@
"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
21 changes: 9 additions & 12 deletions frontend/src/components/TradeBox/Forms/LightningPayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,9 @@ export const LightningPayoutForm = ({
let internetNetwork: 'Clearnet' | 'I2P' | 'TOR' = 'Clearnet';
useEffect(() => {
bitcoinNetwork = settings?.network ?? 'mainnet';
if (settings.host && settings.host.includes('.i2p')) {
if (settings.host?.includes('.i2p') === true) {
internetNetwork = 'I2P';
} else if (
(settings.host && settings.host?.includes('.onion')) ||
window.NativeRobosats != undefined
) {
} else if (settings.host?.includes('.onion') === true || window.NativeRobosats !== undefined) {
internetNetwork = 'TOR';
}

Expand Down Expand Up @@ -192,7 +189,7 @@ export const LightningPayoutForm = ({
.then((data) => {
if (data.reason !== undefined) {
setLightning({ ...lightning, badLnproxy: data.reason });
} else if (data.proxy_invoice != undefined) {
} else if (data.proxy_invoice !== undefined) {
setLightning({ ...lightning, invoice: data.proxy_invoice, badLnproxy: '' });
} else {
setLightning({ ...lightning, badLnproxy: 'Unknown lnproxy response' });
Expand Down Expand Up @@ -385,11 +382,11 @@ export const LightningPayoutForm = ({
>
<div>
<FormControlLabel
onChange={(e) => {
onChange={(e, checked) => {
setLightning({
...lightning,
useLnproxy: e.target.checked,
invoice: e.target.checked ? '' : lightning.invoice,
useLnproxy: checked,
invoice: checked ? '' : lightning.invoice,
});
}}
checked={lightning.useLnproxy}
Expand Down Expand Up @@ -422,7 +419,7 @@ export const LightningPayoutForm = ({
spacing={1}
>
<Grid item>
<FormControl error={noMatchingLnProxies != ''}>
<FormControl error={noMatchingLnProxies !== ''}>
<InputLabel id='select-label'>{t('Server')}</InputLabel>
<Select
sx={{ width: '14em' }}
Expand Down Expand Up @@ -525,7 +522,7 @@ export const LightningPayoutForm = ({
disabled={!lightning.useLnproxy}
error={lightning.badLnproxy !== ''}
FormHelperTextProps={{ style: { wordBreak: 'break-all' } }}
helperText={lightning.badLnproxy ? t(lightning.badLnproxy) : ''}
helperText={lightning.badLnproxy !== '' ? t(lightning.badLnproxy) : ''}
label={t('Invoice to wrap')}
required
value={lightning.lnproxyInvoice}
Expand All @@ -545,7 +542,7 @@ export const LightningPayoutForm = ({
sx={lightning.useLnproxy ? { borderRadius: 0 } : {}}
disabled={lightning.useLnproxy}
error={lightning.badInvoice !== ''}
helperText={lightning.badInvoice ? t(lightning.badInvoice) : ''}
helperText={lightning.badInvoice !== '' ? t(lightning.badInvoice) : ''}
FormHelperTextProps={{ style: { wordBreak: 'break-all' } }}
label={lightning.useLnproxy ? t('Wrapped invoice') : t('Payout Lightning Invoice')}
required
Expand Down
13 changes: 5 additions & 8 deletions frontend/src/components/TradeBox/Forms/OnchainPayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,9 @@ export const OnchainPayoutForm = ({

<ListItem>
<ListItemText
primary={
pn(Math.floor(Math.max(minMiningFee, onchain.miningFee) * costPerVByte)) +
' Sats (' +
Math.max(minMiningFee, onchain.miningFee) +
' Sats/vByte)'
}
primary={`${pn(
Math.floor(Math.max(minMiningFee, onchain.miningFee) * costPerVByte),
)} Sats (${Math.max(minMiningFee, onchain.miningFee)} Sats/vByte)`}
secondary={t('Mining fee')}
/>
</ListItem>
Expand Down Expand Up @@ -112,8 +109,8 @@ export const OnchainPayoutForm = ({
<Grid container direction='row' justifyContent='center' alignItems='flex-start' spacing={0}>
<Grid item xs={7}>
<TextField
error={onchain.badAddress != ''}
helperText={onchain.badAddress ? t(onchain.badAddress) : ''}
error={onchain.badAddress !== ''}
helperText={onchain.badAddress !== '' ? t(onchain.badAddress) : ''}
label={t('Bitcoin Address')}
required
value={onchain.address}
Expand Down
24 changes: 15 additions & 9 deletions frontend/src/components/TradeBox/Prompts/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Grid, Typography, Tooltip, Collapse, IconButton } from '@mui/material';
import { Grid, Typography, Tooltip, Collapse } from '@mui/material';
import currencies from '../../../../static/assets/currencies.json';

import { type Order, type Robot } from '../../../models';
Expand Down Expand Up @@ -51,10 +51,16 @@ export const ChatPrompt = ({

const currencyCode: string = currencies[`${order.currency}`];
const amount: string = pn(
parseFloat(parseFloat(order.amount).toFixed(order.currency == 1000 ? 8 : 4)),
parseFloat(parseFloat(order.amount).toFixed(order.currency === 1000 ? 8 : 4)),
);

const disputeCountdownRenderer = function ({ hours, minutes }) {
const disputeCountdownRenderer = function ({
hours,
minutes,
}: {
hours: number;
minutes: number;
}): JSX.Element {
return (
<span>{`${t('To open a dispute you need to wait')} ${hours}h ${zeroPad(minutes)}m `}</span>
);
Expand All @@ -63,12 +69,12 @@ export const ChatPrompt = ({
useEffect(() => {
// open dispute button enables 18h before expiry
const now = Date.now();
const expires_at = new Date(order.expires_at);
expires_at.setHours(expires_at.getHours() - 18);
setEnableDisputeButton(now > expires_at);
setEnableDisputeTime(expires_at);
const expiresAt = new Date(order.expires_at);
expiresAt.setHours(expiresAt.getHours() - 18);
setEnableDisputeButton(now > expiresAt);
setEnableDisputeTime(expiresAt);

if (order.status == 9) {
if (order.status === 9) {
// No fiat sent yet
if (order.is_buyer) {
setSentButton(true);
Expand All @@ -93,7 +99,7 @@ export const ChatPrompt = ({
),
);
}
} else if (order.status == 10) {
} else if (order.status === 10) {
// Fiat has been sent already
if (order.is_buyer) {
setSentButton(false);
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/TradeBox/Prompts/Payout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ export const PayoutPrompt = ({
amountFiat: pn(
parseFloat(
parseFloat(
order.currency == 1000 ? order.amount * 100000000 : order.amount,
order.currency === 1000 ? order.amount * 100000000 : order.amount,
).toFixed(4),
),
),
currencyCode: order.currency == 1000 ? 'Sats' : currencyCode,
currencyCode: order.currency === 1000 ? 'Sats' : currencyCode,
},
)}
</Typography>
Expand Down Expand Up @@ -107,7 +107,7 @@ export const PayoutPrompt = ({
</ToggleButtonGroup>
</Grid>

<Grid item style={{ display: tab == 'lightning' ? '' : 'none' }}>
<Grid item style={{ display: tab === 'lightning' ? '' : 'none' }}>
<LightningPayoutForm
order={order}
settings={settings}
Expand All @@ -119,7 +119,7 @@ export const PayoutPrompt = ({
</Grid>

{/* ONCHAIN PAYOUT TAB */}
<Grid item style={{ display: tab == 'onchain' ? '' : 'none' }}>
<Grid item style={{ display: tab === 'onchain' ? '' : 'none' }}>
<OnchainPayoutForm
order={order}
loading={loadingOnchain}
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/TradeBox/Prompts/PublicWait.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export const PublicWaitPrompt = ({
const { t } = useTranslation();
const currencyCode = currencies[order.currency.toString()];

const depositHoursMinutes = function () {
const depositHoursMinutes = function (): {
deposit_timer_hours: number;
deposit_timer_minutes: number;
} {
const hours = Math.floor(order.escrow_duration / 3600);
const minutes = Math.floor((order.escrow_duration - hours * 3600) / 60);
const dict = { deposit_timer_hours: hours, deposit_timer_minutes: minutes };
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/components/TradeBox/Prompts/RoutingFailed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ export const RoutingFailedPrompt = ({
}: RoutingFailedPromptProps): JSX.Element => {
const { t } = useTranslation();

const countdownRenderer = function ({ minutes, seconds, completed }: CountdownRenderProps) {
const countdownRenderer = function ({
minutes,
seconds,
completed,
}: CountdownRenderProps): JSX.Element {
if (completed) {
return (
<Grid container direction='column' alignItems='center' justifyContent='center' spacing={1}>
Expand Down Expand Up @@ -87,7 +91,7 @@ export const RoutingFailedPrompt = ({
</Typography>
</Grid>

{order.failure_reason ? (
{order.failure_reason != null ? (
<Grid item>
<FailureReason failureReason={order.failure_reason} />
</Grid>
Expand Down
21 changes: 9 additions & 12 deletions frontend/src/components/TradeBox/Prompts/Successful.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const SuccessfulPrompt = ({
}}
/>
</Grid>
{rating == 5 ? (
{rating === 5 ? (
<Grid item xs={12}>
<div
style={{
Expand All @@ -92,7 +92,7 @@ export const SuccessfulPrompt = ({
)}
</Typography>
</Grid>
) : rating != undefined ? (
) : rating !== undefined ? (
<Grid>
<Typography variant='body2' align='center'>
<b>{t('Thank you for using Robosats!')}</b>
Expand All @@ -116,7 +116,7 @@ export const SuccessfulPrompt = ({
)}

{/* SHOW TXID IF USER RECEIVES ONCHAIN */}
<Collapse in={order.txid != undefined}>
<Collapse in={order.txid !== undefined}>
<Alert severity='success'>
<AlertTitle>
{t('Your TXID')}
Expand All @@ -140,7 +140,7 @@ export const SuccessfulPrompt = ({
target='_blank'
href={
'http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/' +
(order.network == 'testnet' ? 'testnet/' : '') +
(order.network === 'testnet' ? 'testnet/' : '') +
'tx/' +
order.txid
}
Expand All @@ -151,7 +151,7 @@ export const SuccessfulPrompt = ({
</Alert>
</Collapse>

<Collapse in={order.tx_queued && order.address != undefined && !order.txid}>
<Collapse in={order.tx_queued && order.address !== undefined && order.txid == null}>
<Alert severity='info'>
<AlertTitle>
<CircularProgress sx={{ maxWidth: '0.8em', maxHeight: '0.8em' }} />
Expand All @@ -175,12 +175,9 @@ export const SuccessfulPrompt = ({
>
<Link
target='_blank'
href={
'http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/' +
(order.network == 'testnet' ? 'testnet/' : '') +
'address/' +
order.address
}
href={`http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/${
order.network === 'testnet' ? 'testnet/' : ''
}address/${order.address}`}
>
{order.address}
</Link>
Expand Down Expand Up @@ -211,7 +208,7 @@ export const SuccessfulPrompt = ({
) : null}
</Grid>

{order.platform_summary ? (
{order.platform_summary != null ? (
<Grid item>
<TradeSummary
isMaker={order.is_maker}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/TradeBox/Title/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import stepXofY from '../stepXofY';
interface TakerFoundPrompProps {
order: Order;
text: string;
variables?: Object;
variables?: any;
color?: string;
icon?: () => JSX.Element;
}
Expand All @@ -25,9 +25,9 @@ export const Title = ({
const theme = useTheme();

let textColor = color;
if (color == 'warning') {
if (color === 'warning') {
textColor = theme.palette.warning.main;
} else if (color == 'success') {
} else if (color === 'success') {
textColor = theme.palette.success.main;
}

Expand Down
25 changes: 15 additions & 10 deletions frontend/src/components/TradeBox/TradeSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { pn, saveAsJson } from '../../utils';
import RobotAvatar from '../RobotAvatar';

// Icons
import { ExportIcon, FlagWithProps } from '../Icons';
import {
Schedule,
PriceChange,
Expand All @@ -29,7 +28,13 @@ import {
AccountBox,
Link,
} from '@mui/icons-material';
import { RoboSatsNoTextIcon, SendReceiveIcon, BitcoinIcon } from '../Icons';
import {
RoboSatsNoTextIcon,
SendReceiveIcon,
BitcoinIcon,
ExportIcon,
FlagWithProps,
} from '../Icons';
import { type TradeCoordinatorSummary, type TradeRobotSummary } from '../../models/Order.model';
import { systemClient } from '../../services/System';

Expand All @@ -56,18 +61,18 @@ const TradeSummary = ({
orderId,
baseUrl,
}: Props): JSX.Element => {
const { t, i18n } = useTranslation();
const { t } = useTranslation();
const theme = useTheme();

const [buttonValue, setButtonValue] = useState<number>(isMaker ? 0 : 2);
const userSummary = buttonValue == 0 ? makerSummary : takerSummary;
const userSummary = buttonValue === 0 ? makerSummary : takerSummary;
const contractTimestamp = new Date(platformSummary.contract_timestamp ?? null);
const total_time = platformSummary.contract_total_time;
const hours = parseInt(total_time / 3600);
const mins = parseInt((total_time - hours * 3600) / 60);
const secs = parseInt(total_time - hours * 3600 - mins * 60);
const totalTime = platformSummary.contract_total_time;
const hours = parseInt(totalTime / 3600);
const mins = parseInt((totalTime - hours * 3600) / 60);
const secs = parseInt(totalTime - hours * 3600 - mins * 60);

const onClickExport = function () {
const onClickExport = function (): void {
const summary = {
order_id: orderId,
currency: currencyCode,
Expand Down Expand Up @@ -272,7 +277,7 @@ const TradeSummary = ({
</List>
</div>
{/* Platform Summary */}
<div style={{ display: buttonValue == 1 ? '' : 'none' }}>
<div style={{ display: buttonValue === 1 ? '' : 'none' }}>
<List dense={true}>
<ListItem>
<ListItemIcon>
Expand Down
Loading

0 comments on commit 502cf4c

Please sign in to comment.