Skip to content

Commit

Permalink
Small fixes and lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Reckless-Satoshi committed Jan 7, 2024
1 parent 53037a3 commit a4b2327
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 72 deletions.
2 changes: 1 addition & 1 deletion frontend/src/basic/BookPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const BookPage = (): JSX.Element => {
const chartWidthEm = width - maxBookTableWidth;

const onOrderClicked = function (id: number, shortAlias: string): void {
if (Boolean(garage.getSlot()?.hashId)) {
if (garage.getSlot()?.hashId) {
setDelay(10000);
navigate(`/order/${shortAlias}/${id}`);
} else {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/basic/MakerPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const MakerPage = (): JSX.Element => {
]);

const onOrderClicked = function (id: number): void {
if (Boolean(garage.getSlot()?.hashId)) {
if (garage.getSlot()?.hashId) {
navigate(`/order/${id}`);
} else {
setOpenNoRobot(true);
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/basic/NavBar/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const NavBar = (): JSX.Element => {
const tabSx = smallBar
? {
position: 'relative',
bottom: Boolean(garage.getSlot()?.hashId) ? '0.9em' : '0.13em',
bottom: garage.getSlot()?.hashId ? '0.9em' : '0.13em',
minWidth: '1em',
}
: { position: 'relative', bottom: '1em', minWidth: '2em' };
Expand Down Expand Up @@ -155,10 +155,7 @@ const NavBar = (): JSX.Element => {
sx={tabSx}
label={smallBar ? undefined : t('Order')}
value='order'
disabled={
!Boolean(slot?.hashId) ||
!Boolean(slot?.getRobot(slot?.activeShortAlias ?? '')?.activeOrderId)
}
disabled={!slot?.hashId || !slot?.getRobot(slot?.activeShortAlias ?? '')?.activeOrderId}
icon={<Assignment />}
iconPosition='start'
/>
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/basic/OrderPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const OrderPage = (): JSX.Element => {
updateCurrentOrder();
}, [currentOrderId]);

const updateCurrentOrder = () => {
const updateCurrentOrder = (): void => {
if (currentOrderId !== null) {
const coordinator = federation.getCoordinator(params.shortAlias ?? '');
const slot = garage.getSlot();
Expand All @@ -71,7 +71,7 @@ const OrderPage = (): JSX.Element => {
.then((order) => {
if (order?.bad_request !== undefined) {
setBadOrder(order.bad_request);
} else if (Boolean(order?.id)) {
} else if (order?.id) {
setCurrentOrder(order);
if (order?.is_participant) {
garage.updateOrder(order);
Expand Down Expand Up @@ -122,7 +122,8 @@ const OrderPage = (): JSX.Element => {
<WarningDialog
open={open.warning}
onClose={() => {
setOpen(closeAll), setAcknowledgedWarning(true);
setOpen(closeAll);
setAcknowledgedWarning(true);
}}
longAlias={federation.getCoordinator(params.shortAlias ?? '').longAlias}
/>
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/basic/RobotPage/Onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ const Onboarding = ({
};

const slot = garage.getSlot();
const robot = slot?.getRobot();

return (
<Box>
Expand Down Expand Up @@ -151,7 +150,7 @@ const Onboarding = ({
<Grid container direction='column' alignItems='center' spacing={1}>
<Grid item>
<Typography>
{Boolean(slot?.hashId) ? (
{slot?.hashId ? (
t('This is your trading avatar')
) : (
<>
Expand Down Expand Up @@ -179,7 +178,7 @@ const Onboarding = ({
/>
</Grid>

{Boolean(slot?.hashId) ? (
{slot?.hashId ? (
<Grid item>
<Typography align='center'>{t('Hi! My name is')}</Typography>
<Typography component='h5' variant='h5'>
Expand Down Expand Up @@ -211,7 +210,7 @@ const Onboarding = ({
</Grid>
) : null}
<Grid item>
<Collapse in={!!Boolean(slot?.hashId)}>
<Collapse in={!!slot?.hashId}>
<Button
onClick={() => {
setStep('3');
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/basic/RobotPage/RobotProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { AppContext, type UseAppStoreType } from '../../contexts/AppContext';
import { genBase62Token } from '../../utils';
import { LoadingButton } from '@mui/lab';
import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext';
import { type UseFederationStoreType, FederationContext } from '../../contexts/FederationContext';

interface RobotProfileProps {
robot: Robot;
Expand All @@ -46,7 +45,6 @@ const RobotProfile = ({
}: RobotProfileProps): JSX.Element => {
const { windowSize } = useContext<UseAppStoreType>(AppContext);
const { garage, robotUpdatedAt, orderUpdatedAt } = useContext<UseGarageStoreType>(GarageContext);
const { sortedCoordinators } = useContext<UseFederationStoreType>(FederationContext);

const { t } = useTranslation();
const theme = useTheme();
Expand All @@ -56,8 +54,7 @@ const RobotProfile = ({

useEffect(() => {
const slot = garage.getSlot();
const robot = slot?.getRobot(sortedCoordinators[0]);
if (Boolean(slot?.hashId)) {
if (slot?.hashId) {
setLoading(false);
}
}, [orderUpdatedAt, robotUpdatedAt, loading]);
Expand Down Expand Up @@ -87,7 +84,7 @@ const RobotProfile = ({
sx={{ width: '100%' }}
>
<Grid item sx={{ height: '2.3em', position: 'relative' }}>
{Boolean(slot?.hashId) ? (
{slot?.hashId ? (
<Typography align='center' component='h5' variant='h5'>
<div
style={{
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/basic/RobotPage/TokenInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const TokenInput = ({
<Tooltip open={showCopied} title={t('Copied!')}>
<IconButton
autoFocus={autoFocusTarget === 'copyButton'}
color={Boolean(garage.getSlot()?.copiedToken) ? 'inherit' : 'primary'}
color={garage.getSlot()?.copiedToken ? 'inherit' : 'primary'}
onClick={() => {
systemClient.copyToClipboard(inputToken);
setShowCopied(true);
Expand Down
13 changes: 1 addition & 12 deletions frontend/src/components/BookTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ const BookTable = ({
showNoResults = true,
onOrderClicked = () => null,
}: BookTableProps): JSX.Element => {
const { fav, setFav, settings, setOpen, hostUrl, origin } =
useContext<UseAppStoreType>(AppContext);
const { fav, setFav, setOpen } = useContext<UseAppStoreType>(AppContext);
const { federation, coordinatorUpdatedAt } =
useContext<UseFederationStoreType>(FederationContext);

Expand Down Expand Up @@ -206,11 +205,6 @@ const BookTable = ({
headerName: t('Robot'),
width: width * fontSize,
renderCell: (params: any) => {
const { url, basePath } =
federation
.getCoordinator(params.row.coordinatorShortAlias)
?.getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl) ?? {};

return (
<ListItemButton
style={{ cursor: 'pointer', position: 'relative', left: '-1.3em' }}
Expand Down Expand Up @@ -243,11 +237,6 @@ const BookTable = ({
headerName: t('Robot'),
width: width * fontSize,
renderCell: (params: any) => {
const { url, basePath } =
federation
.getCoordinator(params.row.coordinatorShortAlias)
?.getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl) ?? {};

return (
<div
style={{ position: 'relative', left: '-0.34em', cursor: 'pointer' }}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/Dialogs/Coordinator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ const BadgesHall = ({ badges }: BadgesProps): JSX.Element => {

const CoordinatorDialog = ({ open = false, onClose, network, shortAlias }: Props): JSX.Element => {
const { t } = useTranslation();
const { clientVersion, page, hostUrl } = useContext(AppContext);
const { clientVersion, page } = useContext(AppContext);
const { federation } = useContext<UseFederationStoreType>(FederationContext);
const coordinator = federation.getCoordinator(shortAlias);

Expand Down Expand Up @@ -480,11 +480,11 @@ const CoordinatorDialog = ({ open = false, onClose, network, shortAlias }: Props
)}
</List>

{Boolean(coordinator?.loadingInfo) ? (
{coordinator?.loadingInfo ? (
<Box style={{ display: 'flex', justifyContent: 'center' }}>
<CircularProgress />
</Box>
) : Boolean(coordinator?.info) ? (
) : coordinator?.info ? (
<Box>
{Boolean(coordinator?.policies) && (
<Accordion
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Dialogs/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const ProfileDialog = ({ open = false, baseUrl, onClose }: Props): JSX.Element =
const [loading, setLoading] = useState<boolean>(true);

useEffect(() => {
setLoading(!Boolean(garage.getSlot()?.hashId));
setLoading(!garage.getSlot()?.hashId);
}, [robotUpdatedAt]);

return (
Expand Down Expand Up @@ -96,7 +96,7 @@ const ProfileDialog = ({ open = false, baseUrl, onClose }: Props): JSX.Element =
</Typography>

{Object.values(federation.coordinators).map((coordinator: Coordinator): JSX.Element => {
if (Boolean(garage.getSlot()?.hashId)) {
if (garage.getSlot()?.hashId) {
return (
<div key={coordinator.shortAlias}>
<RobotInfo coordinator={coordinator} onClose={onClose} />
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/MakerForm/MakerForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const MakerForm = ({

useEffect(() => {
const slot = garage.getSlot();
if (Boolean(slot?.token)) void federation.fetchRobot(garage, slot?.token);
if (slot?.token) void federation.fetchRobot(garage, slot?.token);
}, [garage.currentSlot]);

useEffect(() => {
Expand All @@ -104,7 +104,7 @@ const MakerForm = ({
updateCoordinatorInfo();
}, [maker.coordinator]);

const updateCoordinatorInfo = () => {
const updateCoordinatorInfo = (): void => {
if (maker.coordinator != null) {
const newLimits = federation.getCoordinator(maker.coordinator).limits;
if (Object.keys(newLimits).length !== 0) {
Expand Down Expand Up @@ -294,7 +294,7 @@ const MakerForm = ({
const handleCreateOrder = function (): void {
const slot = garage.getSlot();

if (Boolean(slot?.activeShortAlias)) {
if (slot?.activeShortAlias) {
setBadRequest(t('You are already maker of an active order'));
return;
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/MakerForm/SelectCoordinator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface SelectCoordinatorProps {
}

const SelectCoordinator: React.FC<SelectCoordinatorProps> = ({ coordinator, setCoordinator }) => {
const { setOpen, hostUrl } = useContext<UseAppStoreType>(AppContext);
const { setOpen } = useContext<UseAppStoreType>(AppContext);
const { federation, sortedCoordinators } = useContext<UseFederationStoreType>(FederationContext);
const theme = useTheme();
const { t } = useTranslation();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/OrderDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const OrderDetails = ({
currentOrder.amount > 0 ? false : currentOrder.has_range,
currentOrder.min_amount,
currentOrder.max_amount,
) + ` ${currencyCode}`
) + ` ${String(currencyCode)}`
);
}
}, [orderUpdatedAt, currencyCode]);
Expand Down
20 changes: 12 additions & 8 deletions frontend/src/components/RobotAvatar/RobohashGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
interface Task {
robohash: Robohash;
resolves: ((result: string) => void)[];
rejects: ((reason?: Error) => void)[];
resolves: Array<(result: string) => void>;
rejects: Array<(reason?: Error) => void>;
}

interface Robohash {
Expand Down Expand Up @@ -32,7 +32,7 @@ class RoboGenerator {
}
}

private assignTasksToWorkers() {
private assignTasksToWorkers(): void {
const availableWorker = this.workers.find((w) => !w.busy);

if (availableWorker) {
Expand All @@ -42,13 +42,13 @@ class RoboGenerator {
availableWorker.worker.postMessage(task.robohash);

// Clean up the event listener and free the worker after receiving the result
const cleanup = () => {
const cleanup = (): void => {
availableWorker.worker.removeEventListener('message', completionCallback);
availableWorker.busy = false;
};

// Resolve the promise when the task is completed
const completionCallback = (event: MessageEvent) => {
const completionCallback = (event: MessageEvent): void => {
if (event.data.cacheKey === task.robohash.cacheKey) {
const { cacheKey, imageUrl } = event.data;

Expand All @@ -57,7 +57,9 @@ class RoboGenerator {

cleanup();

task.resolves.forEach((f) => f(imageUrl));
task.resolves.forEach((f) => {
f(imageUrl);
});
}
};

Expand All @@ -67,7 +69,9 @@ class RoboGenerator {
availableWorker.worker.addEventListener('error', (error) => {
cleanup();

task.rejects.forEach((f) => f(new Error(error.message)));
task.rejects.forEach((f) => {
f(new Error(error.message));
});
});
}
}
Expand All @@ -81,7 +85,7 @@ class RoboGenerator {
if (this.assetsCache[cacheKey]) {
return this.assetsCache[cacheKey];
} else {
return new Promise((resolve, reject) => {
return await new Promise((resolve, reject) => {
let task = this.queue.find((t) => t.robohash.cacheKey === cacheKey);

if (!task) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/RobotAvatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Avatar, Badge, Tooltip } from '@mui/material';
import { SendReceiveIcon } from '../Icons';
import placeholder from './placeholder.json';
import { robohash } from './RobohashGenerator';
import { AppContext, UseAppStoreType } from '../../contexts/AppContext';
import { AppContext, type UseAppStoreType } from '../../contexts/AppContext';

interface Props {
shortAlias?: string | undefined;
Expand Down
22 changes: 12 additions & 10 deletions frontend/src/components/RobotAvatar/robohash.worker.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { async_generate_robohash } from 'robo-identities-wasm';

// Listen for messages from the main thread
self.addEventListener('message', async (event) => {
const { hash, size, cacheKey, workerIndex } = event.data;
self.addEventListener('message', (event) => {
void (async () => {
const { hash, size, cacheKey } = event.data;

// Generate the image using async_image_base
const t0 = performance.now();
const avatarB64 = await async_generate_robohash(hash, size == 'small' ? 80 : 256);
const imageUrl = `data:image/png;base64,${avatarB64}`;
const t1 = performance.now();
console.log(`Avatar generated in: ${t1 - t0} ms`);
// Send the result back to the main thread
self.postMessage({ cacheKey, imageUrl });
// Generate the image using async_image_base
const t0 = performance.now();
const avatarB64: string = await async_generate_robohash(hash, size === 'small' ? 80 : 256);
const imageUrl = `data:image/png;base64,${avatarB64}`;
const t1 = performance.now();
console.log(`Avatar generated in: ${t1 - t0} ms`);
// Send the result back to the main thread
self.postMessage({ cacheKey, imageUrl });
})();
});
4 changes: 2 additions & 2 deletions frontend/src/components/RobotInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ const RobotInfo: React.FC<Props> = ({ coordinator, onClose }: Props) => {
</ListItemIcon>

<ListItemText>
{Boolean(robot?.tgEnabled) ? (
{robot?.tgEnabled ? (
<Typography color={theme.palette.success.main}>
<b>{t('Telegram enabled')}</b>
</Typography>
Expand Down Expand Up @@ -241,7 +241,7 @@ const RobotInfo: React.FC<Props> = ({ coordinator, onClose }: Props) => {
<Switch
checked={robot?.stealthInvoices}
onChange={() => {
setStealthInvoice(!Boolean(robot?.stealthInvoices));
setStealthInvoice(!robot?.stealthInvoices);
}}
/>
}
Expand Down
Loading

0 comments on commit a4b2327

Please sign in to comment.