mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-31 02:21:35 +00:00
Small fixes and lint fixes
This commit is contained in:
parent
53037a3b18
commit
a4b2327ff4
@ -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 {
|
||||
|
@ -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);
|
||||
|
@ -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' };
|
||||
@ -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'
|
||||
/>
|
||||
|
@ -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();
|
||||
@ -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);
|
||||
@ -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}
|
||||
/>
|
||||
|
@ -62,7 +62,6 @@ const Onboarding = ({
|
||||
};
|
||||
|
||||
const slot = garage.getSlot();
|
||||
const robot = slot?.getRobot();
|
||||
|
||||
return (
|
||||
<Box>
|
||||
@ -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')
|
||||
) : (
|
||||
<>
|
||||
@ -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'>
|
||||
@ -211,7 +210,7 @@ const Onboarding = ({
|
||||
</Grid>
|
||||
) : null}
|
||||
<Grid item>
|
||||
<Collapse in={!!Boolean(slot?.hashId)}>
|
||||
<Collapse in={!!slot?.hashId}>
|
||||
<Button
|
||||
onClick={() => {
|
||||
setStep('3');
|
||||
|
@ -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;
|
||||
@ -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();
|
||||
@ -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]);
|
||||
@ -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={{
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
@ -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' }}
|
||||
@ -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' }}
|
||||
|
@ -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);
|
||||
|
||||
@ -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
|
||||
|
@ -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 (
|
||||
@ -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} />
|
||||
|
@ -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(() => {
|
||||
@ -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) {
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -94,7 +94,7 @@ const OrderDetails = ({
|
||||
currentOrder.amount > 0 ? false : currentOrder.has_range,
|
||||
currentOrder.min_amount,
|
||||
currentOrder.max_amount,
|
||||
) + ` ${currencyCode}`
|
||||
) + ` ${String(currencyCode)}`
|
||||
);
|
||||
}
|
||||
}, [orderUpdatedAt, currencyCode]);
|
||||
|
@ -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 {
|
||||
@ -32,7 +32,7 @@ class RoboGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private assignTasksToWorkers() {
|
||||
private assignTasksToWorkers(): void {
|
||||
const availableWorker = this.workers.find((w) => !w.busy);
|
||||
|
||||
if (availableWorker) {
|
||||
@ -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;
|
||||
|
||||
@ -57,7 +57,9 @@ class RoboGenerator {
|
||||
|
||||
cleanup();
|
||||
|
||||
task.resolves.forEach((f) => f(imageUrl));
|
||||
task.resolves.forEach((f) => {
|
||||
f(imageUrl);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -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));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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 });
|
||||
})();
|
||||
});
|
||||
|
@ -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>
|
||||
@ -241,7 +241,7 @@ const RobotInfo: React.FC<Props> = ({ coordinator, onClose }: Props) => {
|
||||
<Switch
|
||||
checked={robot?.stealthInvoices}
|
||||
onChange={() => {
|
||||
setStealthInvoice(!Boolean(robot?.stealthInvoices));
|
||||
setStealthInvoice(!robot?.stealthInvoices);
|
||||
}}
|
||||
/>
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import {
|
||||
} from '@mui/icons-material';
|
||||
import { systemClient } from '../../services/System';
|
||||
import SwapCalls from '@mui/icons-material/SwapCalls';
|
||||
import { FederationContext, UseFederationStoreType } from '../../contexts/FederationContext';
|
||||
import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext';
|
||||
|
||||
interface SettingsFormProps {
|
||||
dense?: boolean;
|
||||
@ -226,7 +226,7 @@ const SettingsForm = ({ dense = false }: SettingsFormProps): JSX.Element => {
|
||||
value={settings.network}
|
||||
onChange={(e, network) => {
|
||||
setSettings({ ...settings, network });
|
||||
federation.updateUrls(origin, { ...settings, network }, hostUrl);
|
||||
void federation.updateUrls(origin, { ...settings, network }, hostUrl);
|
||||
systemClient.setItem('settings_network', network);
|
||||
}}
|
||||
>
|
||||
|
@ -15,9 +15,12 @@ import ChatHeader from '../ChatHeader';
|
||||
import { type EncryptedChatMessage, type ServerMessage } from '..';
|
||||
import ChatBottom from '../ChatBottom';
|
||||
import { sha256 } from 'js-sha256';
|
||||
import { Order } from '../../../../models';
|
||||
import { UseFederationStoreType, FederationContext } from '../../../../contexts/FederationContext';
|
||||
import { UseAppStoreType, AppContext } from '../../../../contexts/AppContext';
|
||||
import { type Order } from '../../../../models';
|
||||
import {
|
||||
type UseFederationStoreType,
|
||||
FederationContext,
|
||||
} from '../../../../contexts/FederationContext';
|
||||
import { type UseAppStoreType, AppContext } from '../../../../contexts/AppContext';
|
||||
|
||||
const audioPath =
|
||||
window.NativeRobosats === undefined
|
||||
|
@ -19,7 +19,7 @@ import {
|
||||
FederationContext,
|
||||
} from '../../../../contexts/FederationContext';
|
||||
import { type UseGarageStoreType, GarageContext } from '../../../../contexts/GarageContext';
|
||||
import { Order } from '../../../../models';
|
||||
import { type Order } from '../../../../models';
|
||||
|
||||
interface Props {
|
||||
order: Order;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Order, type Robot } from '../../../models';
|
||||
import { type Order, type Robot } from '../../../models';
|
||||
import EncryptedSocketChat from './EncryptedSocketChat';
|
||||
import EncryptedTurtleChat from './EncryptedTurtleChat';
|
||||
|
||||
|
@ -20,7 +20,10 @@ import { LoadingButton } from '@mui/lab';
|
||||
|
||||
import { type Order } from '../../../models';
|
||||
import { systemClient } from '../../../services/System';
|
||||
import { FederationContext, UseFederationStoreType } from '../../../contexts/FederationContext';
|
||||
import {
|
||||
FederationContext,
|
||||
type UseFederationStoreType,
|
||||
} from '../../../contexts/FederationContext';
|
||||
|
||||
interface SuccessfulPromptProps {
|
||||
order: Order;
|
||||
|
@ -156,7 +156,7 @@ const TradeBox = ({ baseUrl, onStartAgain }: TradeBoxProps): JSX.Element => {
|
||||
|
||||
const renewOrder = function (): void {
|
||||
const currentOrder = garage.getSlot()?.order;
|
||||
if (Boolean(currentOrder)) {
|
||||
if (currentOrder) {
|
||||
const body = {
|
||||
type: currentOrder.type,
|
||||
currency: currentOrder.currency,
|
||||
|
Loading…
Reference in New Issue
Block a user