mirror of
https://github.com/RoboSats/robosats.git
synced 2025-02-07 13:59:06 +00:00
Fix and disable strict boolean lintern
This commit is contained in:
parent
a2695ca169
commit
8884c7f187
@ -26,6 +26,7 @@
|
|||||||
"react-hooks/exhaustive-deps": "off",
|
"react-hooks/exhaustive-deps": "off",
|
||||||
"react/prop-types": "off",
|
"react/prop-types": "off",
|
||||||
"react/react-in-jsx-scope": "off",
|
"react/react-in-jsx-scope": "off",
|
||||||
|
"@typescript-eslint/strict-boolean-expressions": "off",
|
||||||
"@typescript-eslint/naming-convention": [
|
"@typescript-eslint/naming-convention": [
|
||||||
"error",
|
"error",
|
||||||
{
|
{
|
||||||
|
@ -166,7 +166,7 @@ const NavBar = (): JSX.Element => {
|
|||||||
value='order'
|
value='order'
|
||||||
disabled={
|
disabled={
|
||||||
!Boolean(slot?.hashId) ||
|
!Boolean(slot?.hashId) ||
|
||||||
!(slot?.getRobot(slot?.activeShortAlias ?? '')?.activeOrderId != null)
|
!Boolean(slot?.getRobot(slot?.activeShortAlias ?? '')?.activeOrderId)
|
||||||
}
|
}
|
||||||
icon={<Assignment />}
|
icon={<Assignment />}
|
||||||
iconPosition='start'
|
iconPosition='start'
|
||||||
|
@ -56,9 +56,9 @@ const OrderPage = (): JSX.Element => {
|
|||||||
.then((order) => {
|
.then((order) => {
|
||||||
if (order?.bad_request !== undefined) {
|
if (order?.bad_request !== undefined) {
|
||||||
setBadOrder(order.bad_request);
|
setBadOrder(order.bad_request);
|
||||||
} else if (order?.id != null) {
|
} else if (Boolean(order?.id)) {
|
||||||
setCurrentOrder(order);
|
setCurrentOrder(order);
|
||||||
if (order.is_participant) {
|
if (order?.is_participant) {
|
||||||
garage.updateOrder(order);
|
garage.updateOrder(order);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,8 +82,7 @@ const OrderPage = (): JSX.Element => {
|
|||||||
navigate('/robot');
|
navigate('/robot');
|
||||||
};
|
};
|
||||||
|
|
||||||
const orderDetailsSpace =
|
const orderDetailsSpace = currentOrder ? (
|
||||||
currentOrder != null ? (
|
|
||||||
<OrderDetails
|
<OrderDetails
|
||||||
shortAlias={String(currentOrder.shortAlias)}
|
shortAlias={String(currentOrder.shortAlias)}
|
||||||
currentOrder={currentOrder}
|
currentOrder={currentOrder}
|
||||||
@ -97,8 +96,11 @@ const OrderPage = (): JSX.Element => {
|
|||||||
<></>
|
<></>
|
||||||
);
|
);
|
||||||
|
|
||||||
const tradeBoxSpace =
|
const tradeBoxSpace = currentOrder ? (
|
||||||
currentOrder != null ? <TradeBox baseUrl={baseUrl} onStartAgain={startAgain} /> : <></>;
|
<TradeBox baseUrl={baseUrl} onStartAgain={startAgain} />
|
||||||
|
) : (
|
||||||
|
<></>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
|
@ -164,7 +164,7 @@ const Onboarding = ({
|
|||||||
|
|
||||||
<Grid item sx={{ width: '13.5em' }}>
|
<Grid item sx={{ width: '13.5em' }}>
|
||||||
<RobotAvatar
|
<RobotAvatar
|
||||||
hashId={slot?.hashId}
|
hashId={slot?.hashId ?? ''}
|
||||||
smooth={true}
|
smooth={true}
|
||||||
style={{ maxWidth: '12.5em', maxHeight: '12.5em' }}
|
style={{ maxWidth: '12.5em', maxHeight: '12.5em' }}
|
||||||
placeholderType='generating'
|
placeholderType='generating'
|
||||||
|
@ -141,7 +141,7 @@ const RobotProfile = ({
|
|||||||
tooltip={t('This is your trading avatar')}
|
tooltip={t('This is your trading avatar')}
|
||||||
tooltipPosition='top'
|
tooltipPosition='top'
|
||||||
/>
|
/>
|
||||||
{robot?.found === true && slot?.lastShortAlias != null ? (
|
{robot?.found && Boolean(slot?.lastShortAlias) ? (
|
||||||
<Typography align='center' variant='h6'>
|
<Typography align='center' variant='h6'>
|
||||||
{t('Welcome back!')}
|
{t('Welcome back!')}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
@ -71,7 +71,7 @@ const TokenInput = ({
|
|||||||
<Tooltip open={showCopied} title={t('Copied!')}>
|
<Tooltip open={showCopied} title={t('Copied!')}>
|
||||||
<IconButton
|
<IconButton
|
||||||
autoFocus={autoFocusTarget === 'copyButton'}
|
autoFocus={autoFocusTarget === 'copyButton'}
|
||||||
color={garage.getSlot()?.copiedToken === true ? 'inherit' : 'primary'}
|
color={Boolean(garage.getSlot()?.copiedToken) ? 'inherit' : 'primary'}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
systemClient.copyToClipboard(inputToken);
|
systemClient.copyToClipboard(inputToken);
|
||||||
setShowCopied(true);
|
setShowCopied(true);
|
||||||
|
@ -414,12 +414,14 @@ const CoordinatorDialog = ({ open = false, onClose, network, shortAlias }: Props
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{coordinator?.info?.notice_severity != null &&
|
{Boolean(coordinator?.info?.notice_severity) &&
|
||||||
coordinator?.info?.notice_severity !== 'none' && (
|
coordinator?.info?.notice_severity !== 'none' && (
|
||||||
<ListItem>
|
<ListItem>
|
||||||
<Alert severity={coordinator.info.notice_severity} sx={{ width: '100%' }}>
|
<Alert severity={coordinator?.info?.notice_severity} sx={{ width: '100%' }}>
|
||||||
<AlertTitle>{t('Coordinator Notice')}</AlertTitle>
|
<AlertTitle>{t('Coordinator Notice')}</AlertTitle>
|
||||||
<div dangerouslySetInnerHTML={{ __html: coordinator.info.notice_message }} />
|
<div
|
||||||
|
dangerouslySetInnerHTML={{ __html: coordinator?.info?.notice_message ?? '' }}
|
||||||
|
/>
|
||||||
</Alert>
|
</Alert>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
)}
|
)}
|
||||||
@ -478,13 +480,13 @@ const CoordinatorDialog = ({ open = false, onClose, network, shortAlias }: Props
|
|||||||
)}
|
)}
|
||||||
</List>
|
</List>
|
||||||
|
|
||||||
{coordinator?.loadingInfo ? (
|
{Boolean(coordinator?.loadingInfo) ? (
|
||||||
<Box style={{ display: 'flex', justifyContent: 'center' }}>
|
<Box style={{ display: 'flex', justifyContent: 'center' }}>
|
||||||
<CircularProgress />
|
<CircularProgress />
|
||||||
</Box>
|
</Box>
|
||||||
) : coordinator?.info !== undefined ? (
|
) : Boolean(coordinator?.info) ? (
|
||||||
<Box>
|
<Box>
|
||||||
{coordinator?.policies !== undefined && (
|
{Boolean(coordinator?.policies) && (
|
||||||
<Accordion
|
<Accordion
|
||||||
expanded={expanded === 'policies'}
|
expanded={expanded === 'policies'}
|
||||||
onChange={() => {
|
onChange={() => {
|
||||||
|
@ -83,7 +83,7 @@ const ProfileDialog = ({ open = false, baseUrl, onClose }: Props): JSX.Element =
|
|||||||
<RobotAvatar
|
<RobotAvatar
|
||||||
avatarClass='profileAvatar'
|
avatarClass='profileAvatar'
|
||||||
style={{ width: 65, height: 65 }}
|
style={{ width: 65, height: 65 }}
|
||||||
hashId={garage.getSlot()?.hashId}
|
hashId={garage.getSlot()?.hashId ?? ''}
|
||||||
/>
|
/>
|
||||||
</ListItemAvatar>
|
</ListItemAvatar>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
|
@ -93,7 +93,7 @@ const MakerForm = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const slot = garage.getSlot();
|
const slot = garage.getSlot();
|
||||||
if (slot?.token != null) void federation.fetchRobot(garage, slot?.token);
|
if (Boolean(slot?.token)) void federation.fetchRobot(garage, slot?.token);
|
||||||
}, [garage.currentSlot]);
|
}, [garage.currentSlot]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -287,7 +287,7 @@ const MakerForm = ({
|
|||||||
const handleCreateOrder = function (): void {
|
const handleCreateOrder = function (): void {
|
||||||
const slot = garage.getSlot();
|
const slot = garage.getSlot();
|
||||||
|
|
||||||
if (slot?.activeShortAlias != null) {
|
if (Boolean(slot?.activeShortAlias)) {
|
||||||
setBadRequest(t('You are already maker of an active order'));
|
setBadRequest(t('You are already maker of an active order'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,6 @@ import type Coordinator from '../../models';
|
|||||||
import { statusBadgeColor, pn, amountToString, computeSats } from '../../utils';
|
import { statusBadgeColor, pn, amountToString, computeSats } from '../../utils';
|
||||||
import TakeButton from './TakeButton';
|
import TakeButton from './TakeButton';
|
||||||
import { F2fMapDialog } from '../Dialogs';
|
import { F2fMapDialog } from '../Dialogs';
|
||||||
import { AppContext, type UseAppStoreType } from '../../contexts/AppContext';
|
|
||||||
import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext';
|
import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext';
|
||||||
import { type UseFederationStoreType, FederationContext } from '../../contexts/FederationContext';
|
import { type UseFederationStoreType, FederationContext } from '../../contexts/FederationContext';
|
||||||
import { type Order } from '../../models';
|
import { type Order } from '../../models';
|
||||||
@ -62,7 +61,6 @@ const OrderDetails = ({
|
|||||||
}: OrderDetailsProps): JSX.Element => {
|
}: OrderDetailsProps): JSX.Element => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { hostUrl } = useContext<UseAppStoreType>(AppContext);
|
|
||||||
const { federation } = useContext<UseFederationStoreType>(FederationContext);
|
const { federation } = useContext<UseFederationStoreType>(FederationContext);
|
||||||
const { orderUpdatedAt } = useContext<UseGarageStoreType>(GarageContext);
|
const { orderUpdatedAt } = useContext<UseGarageStoreType>(GarageContext);
|
||||||
const [coordinator] = useState<Coordinator | null>(federation.getCoordinator(shortAlias));
|
const [coordinator] = useState<Coordinator | null>(federation.getCoordinator(shortAlias));
|
||||||
|
@ -203,7 +203,7 @@ const RobotInfo: React.FC<Props> = ({ coordinator, onClose }: Props) => {
|
|||||||
</ListItemIcon>
|
</ListItemIcon>
|
||||||
|
|
||||||
<ListItemText>
|
<ListItemText>
|
||||||
{robot?.tgEnabled === true ? (
|
{Boolean(robot?.tgEnabled) ? (
|
||||||
<Typography color={theme.palette.success.main}>
|
<Typography color={theme.palette.success.main}>
|
||||||
<b>{t('Telegram enabled')}</b>
|
<b>{t('Telegram enabled')}</b>
|
||||||
</Typography>
|
</Typography>
|
||||||
@ -241,7 +241,7 @@ const RobotInfo: React.FC<Props> = ({ coordinator, onClose }: Props) => {
|
|||||||
<Switch
|
<Switch
|
||||||
checked={robot?.stealthInvoices}
|
checked={robot?.stealthInvoices}
|
||||||
onChange={() => {
|
onChange={() => {
|
||||||
setStealthInvoice(!(robot?.stealthInvoices === true));
|
setStealthInvoice(!Boolean(robot?.stealthInvoices));
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ const EncryptedTurtleChat: React.FC<Props> = ({
|
|||||||
const loadMessages: () => void = () => {
|
const loadMessages: () => void = () => {
|
||||||
const shortAlias = garage.getSlot()?.activeShortAlias;
|
const shortAlias = garage.getSlot()?.activeShortAlias;
|
||||||
|
|
||||||
if (!(shortAlias == null)) return;
|
if (!shortAlias) return;
|
||||||
|
|
||||||
const { url, basePath } = federation
|
const { url, basePath } = federation
|
||||||
.getCoordinator(shortAlias)
|
.getCoordinator(shortAlias)
|
||||||
@ -123,7 +123,7 @@ const EncryptedTurtleChat: React.FC<Props> = ({
|
|||||||
|
|
||||||
const onMessage = (dataFromServer: ServerMessage): void => {
|
const onMessage = (dataFromServer: ServerMessage): void => {
|
||||||
const robot = garage.getSlot();
|
const robot = garage.getSlot();
|
||||||
if (robot != null && dataFromServer != null) {
|
if (robot && dataFromServer != null) {
|
||||||
// If we receive an encrypted message
|
// If we receive an encrypted message
|
||||||
if (dataFromServer.message.substring(0, 27) === `-----BEGIN PGP MESSAGE-----`) {
|
if (dataFromServer.message.substring(0, 27) === `-----BEGIN PGP MESSAGE-----`) {
|
||||||
void decryptMessage(
|
void decryptMessage(
|
||||||
@ -178,8 +178,11 @@ const EncryptedTurtleChat: React.FC<Props> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onButtonClicked = (e: React.FormEvent<HTMLFormElement>): void => {
|
const onButtonClicked = (e: React.FormEvent<HTMLFormElement>): void => {
|
||||||
const robot = garage.getSlot();
|
const robot = garage.getSlot()?.getRobot();
|
||||||
if (robot?.token !== undefined && value.includes(robot.token)) {
|
|
||||||
|
if (!robot) return;
|
||||||
|
|
||||||
|
if (robot?.token && value.includes(robot.token)) {
|
||||||
alert(
|
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.`,
|
`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.`,
|
||||||
);
|
);
|
||||||
@ -199,7 +202,7 @@ const EncryptedTurtleChat: React.FC<Props> = ({
|
|||||||
order_id: orderId,
|
order_id: orderId,
|
||||||
offset: lastIndex,
|
offset: lastIndex,
|
||||||
},
|
},
|
||||||
{ tokenSHA256: robot?.tokenSHA256 },
|
{ tokenSHA256: robot?.tokenSHA256 ?? '' },
|
||||||
)
|
)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
@ -215,7 +218,7 @@ const EncryptedTurtleChat: React.FC<Props> = ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Else if message is not empty send message
|
// Else if message is not empty send message
|
||||||
else if (value !== '' && robot?.pubKey != null) {
|
else if (value !== '' && Boolean(robot?.pubKey)) {
|
||||||
setWaitingEcho(true);
|
setWaitingEcho(true);
|
||||||
setLastSent(value);
|
setLastSent(value);
|
||||||
encryptMessage(value, robot?.pubKey, peerPubKey ?? '', robot?.encPrivKey, robot?.token)
|
encryptMessage(value, robot?.pubKey, peerPubKey ?? '', robot?.encPrivKey, robot?.token)
|
||||||
|
@ -156,7 +156,7 @@ const TradeBox = ({ baseUrl, onStartAgain }: TradeBoxProps): JSX.Element => {
|
|||||||
|
|
||||||
const renewOrder = function (): void {
|
const renewOrder = function (): void {
|
||||||
const currentOrder = garage.getSlot()?.order;
|
const currentOrder = garage.getSlot()?.order;
|
||||||
if (currentOrder != null) {
|
if (Boolean(currentOrder)) {
|
||||||
const body = {
|
const body = {
|
||||||
type: currentOrder.type,
|
type: currentOrder.type,
|
||||||
currency: currentOrder.currency,
|
currency: currentOrder.currency,
|
||||||
@ -362,7 +362,7 @@ const TradeBox = ({ baseUrl, onStartAgain }: TradeBoxProps): JSX.Element => {
|
|||||||
// Effect on Order Status change (used for WebLN)
|
// Effect on Order Status change (used for WebLN)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const currentOrder = garage.getSlot()?.order;
|
const currentOrder = garage.getSlot()?.order;
|
||||||
if (currentOrder != null && currentOrder?.status !== lastOrderStatus) {
|
if (currentOrder && currentOrder?.status !== lastOrderStatus) {
|
||||||
setLastOrderStatus(currentOrder.status);
|
setLastOrderStatus(currentOrder.status);
|
||||||
void handleWebln(currentOrder);
|
void handleWebln(currentOrder);
|
||||||
}
|
}
|
||||||
@ -380,7 +380,7 @@ const TradeBox = ({ baseUrl, onStartAgain }: TradeBoxProps): JSX.Element => {
|
|||||||
titleIcon: () => <></>,
|
titleIcon: () => <></>,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (order == null) return baseContract;
|
if (!order) return baseContract;
|
||||||
|
|
||||||
const status = order.status;
|
const status = order.status;
|
||||||
const isBuyer = order.is_buyer;
|
const isBuyer = order.is_buyer;
|
||||||
|
@ -89,7 +89,6 @@ export const useFederationStore = (): UseFederationStoreType => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// On bitcoin network change we reset book, limits and federation info and fetch everything again
|
// On bitcoin network change we reset book, limits and federation info and fetch everything again
|
||||||
setFederation(() => {
|
|
||||||
const newFed = initialFederationContext.federation;
|
const newFed = initialFederationContext.federation;
|
||||||
newFed.registerHook('onFederationReady', () => {
|
newFed.registerHook('onFederationReady', () => {
|
||||||
setCoordinatorUpdatedAt(new Date().toISOString());
|
setCoordinatorUpdatedAt(new Date().toISOString());
|
||||||
@ -98,17 +97,16 @@ export const useFederationStore = (): UseFederationStoreType => {
|
|||||||
setFederationUpdatedAt(new Date().toISOString());
|
setFederationUpdatedAt(new Date().toISOString());
|
||||||
});
|
});
|
||||||
void newFed.start(origin, settings, hostUrl);
|
void newFed.start(origin, settings, hostUrl);
|
||||||
return newFed;
|
setFederation(newFed);
|
||||||
});
|
|
||||||
}, [settings.network, torStatus]);
|
}, [settings.network, torStatus]);
|
||||||
|
|
||||||
const onOrderReceived = (order: any): void => {
|
const onOrderReceived = (order: Order): void => {
|
||||||
if (order?.bad_request !== undefined) {
|
if (order?.bad_request) {
|
||||||
setBadOrder(order.bad_request);
|
setBadOrder(order.bad_request);
|
||||||
setDelay(99999999);
|
setDelay(99999999);
|
||||||
garage.updateOrder(undefined);
|
garage.updateOrder(null);
|
||||||
}
|
}
|
||||||
if (order?.id != null) {
|
if (order?.id) {
|
||||||
setDelay(
|
setDelay(
|
||||||
order.status >= 0 && order.status <= 18
|
order.status >= 0 && order.status <= 18
|
||||||
? page === 'order'
|
? page === 'order'
|
||||||
@ -116,7 +114,7 @@ export const useFederationStore = (): UseFederationStoreType => {
|
|||||||
: statusToDelay[order.status] * 5 // If user is not looking at "order" tab, refresh less often.
|
: statusToDelay[order.status] * 5 // If user is not looking at "order" tab, refresh less often.
|
||||||
: 99999999,
|
: 99999999,
|
||||||
);
|
);
|
||||||
garage.updateOrder(order as Order);
|
garage.updateOrder(order);
|
||||||
setBadOrder(undefined);
|
setBadOrder(undefined);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -124,12 +122,12 @@ export const useFederationStore = (): UseFederationStoreType => {
|
|||||||
const fetchCurrentOrder = (): void => {
|
const fetchCurrentOrder = (): void => {
|
||||||
const activeSlot = garage.getSlot();
|
const activeSlot = garage.getSlot();
|
||||||
const robot = activeSlot?.getRobot(activeSlot?.activeShortAlias ?? '');
|
const robot = activeSlot?.getRobot(activeSlot?.activeShortAlias ?? '');
|
||||||
if (robot != null && activeSlot?.activeShortAlias != null) {
|
if (robot?.activeOrderId && activeSlot?.activeShortAlias) {
|
||||||
const coordinator = federation.getCoordinator(activeSlot?.activeShortAlias);
|
const coordinator = federation.getCoordinator(activeSlot?.activeShortAlias ?? '');
|
||||||
coordinator
|
coordinator
|
||||||
.fetchOrder(robot.activeOrderId, robot)
|
?.fetchOrder(robot.activeOrderId, robot)
|
||||||
.then((order) => {
|
.then((order) => {
|
||||||
onOrderReceived(order);
|
onOrderReceived(order as Order);
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setTimer(setTimeout(fetchCurrentOrder, delay));
|
setTimer(setTimeout(fetchCurrentOrder, delay));
|
||||||
@ -147,18 +145,18 @@ export const useFederationStore = (): UseFederationStoreType => {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (page === 'offers') void federation.updateBook();
|
||||||
|
}, [page]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const slot = garage.getSlot();
|
const slot = garage.getSlot();
|
||||||
const robot = slot?.getRobot();
|
const robot = slot?.getRobot();
|
||||||
|
|
||||||
if (robot != null && garage.currentSlot != null) {
|
if (robot && garage.currentSlot) {
|
||||||
if (open.profile && Boolean(slot?.hashId) && slot?.token) {
|
if (open.profile && Boolean(slot?.hashId) && slot?.token) {
|
||||||
void federation.fetchRobot(garage, slot?.token); // refresh/update existing robot
|
void federation.fetchRobot(garage, slot?.token); // refresh/update existing robot
|
||||||
} else if (
|
} else if (robot.token && robot.encPrivKey && robot.pubKey) {
|
||||||
robot.token !== undefined &&
|
|
||||||
robot.encPrivKey !== undefined &&
|
|
||||||
robot.pubKey !== undefined
|
|
||||||
) {
|
|
||||||
void federation.fetchRobot(garage, robot.token); // create new robot with existing token and keys (on network and coordinator change)
|
void federation.fetchRobot(garage, robot.token); // create new robot with existing token and keys (on network and coordinator change)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,6 @@ export class Coordinator {
|
|||||||
this.url = String(this[settings.network][origin]);
|
this.url = String(this[settings.network][origin]);
|
||||||
this.basePath = '';
|
this.basePath = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
void this.update(() => {
|
void this.update(() => {
|
||||||
onStarted(this.shortAlias);
|
onStarted(this.shortAlias);
|
||||||
});
|
});
|
||||||
@ -157,14 +156,20 @@ export class Coordinator {
|
|||||||
this.loadInfo(onDataLoad);
|
this.loadInfo(onDataLoad);
|
||||||
};
|
};
|
||||||
|
|
||||||
generateAllMakerAvatars = (data: [PublicOrder]) => {
|
updateBook = async (onUpdate: (shortAlias: string) => void = () => {}): Promise<void> => {
|
||||||
|
this.loadBook(() => {
|
||||||
|
onUpdate(this.shortAlias);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
generateAllMakerAvatars = async (data: [PublicOrder]): Promise<void> => {
|
||||||
for (const order of data) {
|
for (const order of data) {
|
||||||
robohash.generate(order.maker_hash_id, 'small');
|
void robohash.generate(order.maker_hash_id, 'small');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
loadBook = (onDataLoad: () => void = () => {}): void => {
|
loadBook = (onDataLoad: () => void = () => {}): void => {
|
||||||
if (this.enabled === false) return;
|
if (!this.enabled) return;
|
||||||
if (this.loadingBook) return;
|
if (this.loadingBook) return;
|
||||||
|
|
||||||
this.loadingBook = true;
|
this.loadingBook = true;
|
||||||
@ -172,12 +177,12 @@ export class Coordinator {
|
|||||||
apiClient
|
apiClient
|
||||||
.get(this.url, `${this.basePath}/api/book/`)
|
.get(this.url, `${this.basePath}/api/book/`)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (data.not_found === undefined) {
|
if (!data?.not_found) {
|
||||||
this.book = (data as PublicOrder[]).map((order) => {
|
this.book = (data as PublicOrder[]).map((order) => {
|
||||||
order.coordinatorShortAlias = this.shortAlias;
|
order.coordinatorShortAlias = this.shortAlias;
|
||||||
return order;
|
return order;
|
||||||
});
|
});
|
||||||
this.generateAllMakerAvatars(data);
|
void this.generateAllMakerAvatars(data);
|
||||||
onDataLoad();
|
onDataLoad();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -190,7 +195,7 @@ export class Coordinator {
|
|||||||
};
|
};
|
||||||
|
|
||||||
loadLimits = (onDataLoad: () => void = () => {}): void => {
|
loadLimits = (onDataLoad: () => void = () => {}): void => {
|
||||||
if (this.enabled === false) return;
|
if (!this.enabled) return;
|
||||||
if (this.loadingLimits) return;
|
if (this.loadingLimits) return;
|
||||||
|
|
||||||
this.loadingLimits = true;
|
this.loadingLimits = true;
|
||||||
@ -218,7 +223,7 @@ export class Coordinator {
|
|||||||
};
|
};
|
||||||
|
|
||||||
loadInfo = (onDataLoad: () => void = () => {}): void => {
|
loadInfo = (onDataLoad: () => void = () => {}): void => {
|
||||||
if (this.enabled === false) return;
|
if (!this.enabled) return;
|
||||||
if (this.loadingInfo) return;
|
if (this.loadingInfo) return;
|
||||||
|
|
||||||
this.loadingInfo = true;
|
this.loadingInfo = true;
|
||||||
@ -275,7 +280,7 @@ export class Coordinator {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fecthRobot = async (garage: Garage, token: string): Promise<Robot | null> => {
|
fecthRobot = async (garage: Garage, token: string): Promise<Robot | null> => {
|
||||||
if (this.enabled === false) return null;
|
if (!this.enabled) return null;
|
||||||
|
|
||||||
const robot = garage?.getSlot(token)?.getRobot() ?? null;
|
const robot = garage?.getSlot(token)?.getRobot() ?? null;
|
||||||
|
|
||||||
@ -324,7 +329,7 @@ export class Coordinator {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fetchOrder = async (orderId: number, robot: Robot): Promise<Order | null> => {
|
fetchOrder = async (orderId: number, robot: Robot): Promise<Order | null> => {
|
||||||
if (this.enabled === false) return null;
|
if (!this.enabled) return null;
|
||||||
if (!(robot.token != null)) return null;
|
if (!(robot.token != null)) return null;
|
||||||
|
|
||||||
const authHeaders = robot.getAuthHeaders();
|
const authHeaders = robot.getAuthHeaders();
|
||||||
@ -355,7 +360,7 @@ export class Coordinator {
|
|||||||
bad_invoice?: string;
|
bad_invoice?: string;
|
||||||
successful_withdrawal?: boolean;
|
successful_withdrawal?: boolean;
|
||||||
}> => {
|
}> => {
|
||||||
if (this.enabled === false) return null;
|
if (!this.enabled) return null;
|
||||||
|
|
||||||
const robot = garage.getSlot(index)?.getRobot();
|
const robot = garage.getSlot(index)?.getRobot();
|
||||||
|
|
||||||
@ -377,7 +382,7 @@ export class Coordinator {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fetchStealth = async (wantsStealth: boolean, garage: Garage, index: string): Promise<null> => {
|
fetchStealth = async (wantsStealth: boolean, garage: Garage, index: string): Promise<null> => {
|
||||||
if (this.enabled === false) return null;
|
if (!this.enabled) return null;
|
||||||
|
|
||||||
const robot = garage?.getSlot(index)?.getRobot();
|
const robot = garage?.getSlot(index)?.getRobot();
|
||||||
|
|
||||||
|
@ -68,7 +68,6 @@ export class Federation {
|
|||||||
this.onCoordinatorSaved(shortAlias);
|
this.onCoordinatorSaved(shortAlias);
|
||||||
};
|
};
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
// Object.values(this.coordinators).forEach(async (coor) => {
|
|
||||||
for (const coor of Object.values(this.coordinators)) {
|
for (const coor of Object.values(this.coordinators)) {
|
||||||
await coor.start(origin, settings, hostUrl, onCoordinatorStarted);
|
await coor.start(origin, settings, hostUrl, onCoordinatorStarted);
|
||||||
}
|
}
|
||||||
@ -76,7 +75,6 @@ export class Federation {
|
|||||||
|
|
||||||
update = async (): Promise<void> => {
|
update = async (): Promise<void> => {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
// Object.values(this.coordinators).forEach(async (coor) => {
|
|
||||||
for (const coor of Object.values(this.coordinators)) {
|
for (const coor of Object.values(this.coordinators)) {
|
||||||
await coor.update(() => {
|
await coor.update(() => {
|
||||||
this.onCoordinatorSaved(coor.shortAlias);
|
this.onCoordinatorSaved(coor.shortAlias);
|
||||||
@ -84,6 +82,15 @@ export class Federation {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
updateBook = async (): Promise<void> => {
|
||||||
|
this.loading = false;
|
||||||
|
for (const coor of Object.values(this.coordinators)) {
|
||||||
|
await coor.updateBook(() => {
|
||||||
|
this.onCoordinatorSaved(coor.shortAlias);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
updateExchange = (): void => {
|
updateExchange = (): void => {
|
||||||
this.exchange.info = updateExchangeInfo(this);
|
this.exchange.info = updateExchangeInfo(this);
|
||||||
};
|
};
|
||||||
|
@ -58,7 +58,7 @@ class Garage {
|
|||||||
if (slotsDump !== '') {
|
if (slotsDump !== '') {
|
||||||
const rawSlots = JSON.parse(slotsDump);
|
const rawSlots = JSON.parse(slotsDump);
|
||||||
Object.values(rawSlots).forEach((rawSlot: Record<any, any>) => {
|
Object.values(rawSlots).forEach((rawSlot: Record<any, any>) => {
|
||||||
if (rawSlot?.token != null) {
|
if (rawSlot?.token) {
|
||||||
this.createSlot(rawSlot?.token);
|
this.createSlot(rawSlot?.token);
|
||||||
Object.keys(rawSlot.robots).forEach((shortAlias) => {
|
Object.keys(rawSlot.robots).forEach((shortAlias) => {
|
||||||
const rawRobot = rawSlot.robots[shortAlias];
|
const rawRobot = rawSlot.robots[shortAlias];
|
||||||
@ -76,7 +76,7 @@ class Garage {
|
|||||||
// Slots
|
// Slots
|
||||||
getSlot: (token?: string) => Slot | null = (token) => {
|
getSlot: (token?: string) => Slot | null = (token) => {
|
||||||
const currentToken = token ?? this.currentSlot;
|
const currentToken = token ?? this.currentSlot;
|
||||||
return currentToken != null ? this.slots[currentToken] ?? null : null;
|
return currentToken ? this.slots[currentToken] ?? null : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
createSlot: (token: string) => Slot | null = (token) => {
|
createSlot: (token: string) => Slot | null = (token) => {
|
||||||
@ -89,7 +89,7 @@ class Garage {
|
|||||||
|
|
||||||
deleteSlot: (token?: string) => void = (token) => {
|
deleteSlot: (token?: string) => void = (token) => {
|
||||||
const targetIndex = token ?? this.currentSlot;
|
const targetIndex = token ?? this.currentSlot;
|
||||||
if (targetIndex != null) {
|
if (targetIndex) {
|
||||||
Reflect.deleteProperty(this.slots, targetIndex);
|
Reflect.deleteProperty(this.slots, targetIndex);
|
||||||
this.currentSlot = null;
|
this.currentSlot = null;
|
||||||
this.triggerHook('onRobotUpdate');
|
this.triggerHook('onRobotUpdate');
|
||||||
@ -103,7 +103,7 @@ class Garage {
|
|||||||
token,
|
token,
|
||||||
) => {
|
) => {
|
||||||
const slot = this.getSlot(token);
|
const slot = this.getSlot(token);
|
||||||
if (attributes != null) {
|
if (attributes) {
|
||||||
if (attributes.copiedToken !== undefined) slot?.setCopiedToken(attributes.copiedToken);
|
if (attributes.copiedToken !== undefined) slot?.setCopiedToken(attributes.copiedToken);
|
||||||
this.triggerHook('onRobotUpdate');
|
this.triggerHook('onRobotUpdate');
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ class Garage {
|
|||||||
shortAlias,
|
shortAlias,
|
||||||
attributes,
|
attributes,
|
||||||
) => {
|
) => {
|
||||||
if (token === null || shortAlias === null) return;
|
if (!token || !shortAlias) return;
|
||||||
|
|
||||||
let slot = this.getSlot(token);
|
let slot = this.getSlot(token);
|
||||||
|
|
||||||
@ -132,9 +132,10 @@ class Garage {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Orders
|
// Orders
|
||||||
updateOrder: (order: Order) => void = (order) => {
|
updateOrder: (order: Order | null) => void = (order) => {
|
||||||
const slot = this.getSlot();
|
const slot = this.getSlot();
|
||||||
if (slot != null) {
|
if (slot != null) {
|
||||||
|
if (order !== null) {
|
||||||
const updatedOrder = slot.order ?? null;
|
const updatedOrder = slot.order ?? null;
|
||||||
if (updatedOrder !== null && updatedOrder.id === order.id) {
|
if (updatedOrder !== null && updatedOrder.id === order.id) {
|
||||||
Object.assign(updatedOrder, order);
|
Object.assign(updatedOrder, order);
|
||||||
@ -145,6 +146,9 @@ class Garage {
|
|||||||
if (slot.order?.is_participant) {
|
if (slot.order?.is_participant) {
|
||||||
slot.activeShortAlias = order.shortAlias;
|
slot.activeShortAlias = order.shortAlias;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
slot.order = null;
|
||||||
|
}
|
||||||
this.triggerHook('onOrderUpdate');
|
this.triggerHook('onOrderUpdate');
|
||||||
this.save();
|
this.save();
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@ class Slot {
|
|||||||
this.hashId = sha256(sha256(this.token));
|
this.hashId = sha256(sha256(this.token));
|
||||||
this.nickname = generate_roboname(this.hashId);
|
this.nickname = generate_roboname(this.hashId);
|
||||||
// trigger RoboHash avatar generation in webworker and store in RoboHash class cache.
|
// trigger RoboHash avatar generation in webworker and store in RoboHash class cache.
|
||||||
robohash.generate(this.hashId, 'small');
|
void robohash.generate(this.hashId, 'small');
|
||||||
robohash.generate(this.hashId, 'large');
|
void robohash.generate(this.hashId, 'large');
|
||||||
|
|
||||||
this.robots = {};
|
this.robots = {};
|
||||||
this.order = null;
|
this.order = null;
|
||||||
@ -35,11 +35,11 @@ class Slot {
|
|||||||
};
|
};
|
||||||
|
|
||||||
getRobot = (shortAlias?: string): Robot | null => {
|
getRobot = (shortAlias?: string): Robot | null => {
|
||||||
if (shortAlias != null) {
|
if (shortAlias) {
|
||||||
return this.robots[shortAlias];
|
return this.robots[shortAlias];
|
||||||
} else if (this.activeShortAlias !== null && this.robots[this.activeShortAlias] != null) {
|
} else if (this.activeShortAlias !== null && this.robots[this.activeShortAlias]) {
|
||||||
return this.robots[this.activeShortAlias];
|
return this.robots[this.activeShortAlias];
|
||||||
} else if (this.lastShortAlias !== null && this.robots[this.lastShortAlias] != null) {
|
} else if (this.lastShortAlias !== null && this.robots[this.lastShortAlias]) {
|
||||||
return this.robots[this.lastShortAlias];
|
return this.robots[this.lastShortAlias];
|
||||||
} else if (Object.values(this.robots).length > 0) {
|
} else if (Object.values(this.robots).length > 0) {
|
||||||
return Object.values(this.robots)[0];
|
return Object.values(this.robots)[0];
|
||||||
|
Loading…
Reference in New Issue
Block a user