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