Change getRobot by getSlot (#955)

This commit is contained in:
KoalaSat 2023-11-19 13:49:10 +00:00 committed by Reckless_Satoshi
parent 48dd17b2c6
commit 937ac62c5d
20 changed files with 71 additions and 68 deletions

View File

@ -31,7 +31,7 @@ const BookPage = (): JSX.Element => {
const chartWidthEm = width - maxBookTableWidth; const chartWidthEm = width - maxBookTableWidth;
const onOrderClicked = function (id: number, shortAlias: string): void { const onOrderClicked = function (id: number, shortAlias: string): void {
if (garage.getRobot().avatarLoaded) { if (garage.getSlot().robot.avatarLoaded) {
setDelay(10000); setDelay(10000);
navigate(`/order/${shortAlias}/${id}`); navigate(`/order/${shortAlias}/${id}`);
} else { } else {

View File

@ -44,7 +44,7 @@ const Main: React.FC = () => {
<Router> <Router>
<RobotAvatar <RobotAvatar
style={{ display: 'none' }} style={{ display: 'none' }}
nickname={garage.getRobot().nickname} nickname={garage.getSlot().robot.nickname}
baseUrl={federation.getCoordinator(sortedCoordinators[0]).getBaseUrl()} baseUrl={federation.getCoordinator(sortedCoordinators[0]).getBaseUrl()}
onLoad={() => { onLoad={() => {
garage.updateRobot({ avatarLoaded: true }); garage.updateRobot({ avatarLoaded: true });
@ -55,7 +55,7 @@ const Main: React.FC = () => {
openProfile={() => { openProfile={() => {
setOpen({ ...closeAll, profile: true }); setOpen({ ...closeAll, profile: true });
}} }}
rewards={garage.getRobot().earnedRewards} rewards={garage.getSlot().robot.earnedRewards}
windowWidth={windowSize?.width} windowWidth={windowSize?.width}
/> />
{settings.network === 'testnet' ? ( {settings.network === 'testnet' ? (

View File

@ -51,7 +51,7 @@ const MakerPage = (): JSX.Element => {
]); ]);
const onOrderClicked = function (id: number): void { const onOrderClicked = function (id: number): void {
if (garage.getRobot().avatarLoaded) { if (garage.getSlot().robot.avatarLoaded) {
navigate(`/order/${id}`); navigate(`/order/${id}`);
} else { } else {
setOpenNoRobot(true); setOpenNoRobot(true);

View File

@ -42,7 +42,7 @@ const NavBar = (): JSX.Element => {
const tabSx = smallBar const tabSx = smallBar
? { ? {
position: 'relative', position: 'relative',
bottom: garage.getRobot().avatarLoaded ? '0.9em' : '0.13em', bottom: garage.getSlot().robot.avatarLoaded ? '0.9em' : '0.13em',
minWidth: '1em', minWidth: '1em',
} }
: { position: 'relative', bottom: '1em', minWidth: '2em' }; : { position: 'relative', bottom: '1em', minWidth: '2em' };
@ -118,16 +118,16 @@ const NavBar = (): JSX.Element => {
<Tab <Tab
sx={{ ...tabSx, minWidth: '2.5em', width: '2.5em', maxWidth: '4em' }} sx={{ ...tabSx, minWidth: '2.5em', width: '2.5em', maxWidth: '4em' }}
value='none' value='none'
disabled={garage.getRobot().nickname === null} disabled={garage.getSlot().robot.nickname === null}
onClick={() => { onClick={() => {
setOpen({ ...closeAll, profile: !open.profile }); setOpen({ ...closeAll, profile: !open.profile });
}} }}
icon={ icon={
garage.getRobot().nickname != null && garage.getRobot().avatarLoaded ? ( garage.getSlot().robot.nickname != null && garage.getSlot().robot.avatarLoaded ? (
<RobotAvatar <RobotAvatar
style={{ width: '2.3em', height: '2.3em', position: 'relative', top: '0.2em' }} style={{ width: '2.3em', height: '2.3em', position: 'relative', top: '0.2em' }}
avatarClass={theme.palette.mode === 'dark' ? 'navBarAvatarDark' : 'navBarAvatar'} avatarClass={theme.palette.mode === 'dark' ? 'navBarAvatarDark' : 'navBarAvatar'}
nickname={garage.getRobot().nickname} nickname={garage.getSlot().robot.nickname}
baseUrl={hostUrl} baseUrl={hostUrl}
/> />
) : ( ) : (
@ -162,7 +162,7 @@ const NavBar = (): JSX.Element => {
sx={tabSx} sx={tabSx}
label={smallBar ? undefined : t('Order')} label={smallBar ? undefined : t('Order')}
value='order' value='order'
disabled={!garage.getRobot().avatarLoaded || !garage.getSlot().activeOrderId} disabled={!garage.getSlot().robot.avatarLoaded || !garage.getSlot().activeOrderId}
icon={<Assignment />} icon={<Assignment />}
iconPosition='start' iconPosition='start'
/> />

View File

@ -45,7 +45,7 @@ const OrderPage = (): JSX.Element => {
setCurrentOrder(garage.getSlot().order); setCurrentOrder(garage.getSlot().order);
} else { } else {
coordinator coordinator
.fetchOrder(Number(params.orderId) ?? null, garage.getRobot()) .fetchOrder(Number(params.orderId) ?? null, garage.getSlot().robot)
.then((order) => { .then((order) => {
if (order?.bad_request !== undefined) { if (order?.bad_request !== undefined) {
setBadOrder(order.bad_request); setBadOrder(order.bad_request);
@ -60,7 +60,7 @@ const OrderPage = (): JSX.Element => {
} }
} else { } else {
coordinator coordinator
.fetchOrder(Number(params.orderId) ?? null, garage.getRobot()) .fetchOrder(Number(params.orderId) ?? null, garage.getSlot().robot)
.then((order) => { .then((order) => {
if (order?.bad_request !== undefined) { if (order?.bad_request !== undefined) {
setBadOrder(order.bad_request); setBadOrder(order.bad_request);
@ -107,7 +107,9 @@ const OrderPage = (): JSX.Element => {
.getCoordinator(order.shortAlias) .getCoordinator(order.shortAlias)
.getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl); .getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl);
apiClient apiClient
.post(url + basePath, '/api/make/', body, { tokenSHA256: garage.getRobot().tokenSHA256 }) .post(url + basePath, '/api/make/', body, {
tokenSHA256: garage.getSlot().robot.tokenSHA256,
})
.then((data: any) => { .then((data: any) => {
if (data.bad_request !== undefined) { if (data.bad_request !== undefined) {
setBadOrder(data.bad_request); setBadOrder(data.bad_request);
@ -175,7 +177,7 @@ const OrderPage = (): JSX.Element => {
}} }}
> >
<TradeBox <TradeBox
robot={garage.getRobot()} robot={garage.getSlot().robot}
currentOrder={currentOrder} currentOrder={currentOrder}
settings={settings} settings={settings}
setBadOrder={setBadOrder} setBadOrder={setBadOrder}
@ -222,7 +224,7 @@ const OrderPage = (): JSX.Element => {
</div> </div>
<div style={{ display: tab === 'contract' ? '' : 'none' }}> <div style={{ display: tab === 'contract' ? '' : 'none' }}>
<TradeBox <TradeBox
robot={garage.getRobot()} robot={garage.getSlot().robot}
currentOrder={currentOrder} currentOrder={currentOrder}
settings={settings} settings={settings}
setBadOrder={setBadOrder} setBadOrder={setBadOrder}

View File

@ -149,7 +149,7 @@ const Onboarding = ({
<Grid container direction='column' alignItems='center' spacing={1}> <Grid container direction='column' alignItems='center' spacing={1}>
<Grid item> <Grid item>
<Typography> <Typography>
{garage.getRobot().avatarLoaded && Boolean(garage.getRobot().nickname) ? ( {garage.getSlot().robot.avatarLoaded && Boolean(garage.getSlot().robot.nickname) ? (
t('This is your trading avatar') t('This is your trading avatar')
) : ( ) : (
<> <>
@ -162,7 +162,7 @@ const Onboarding = ({
<Grid item sx={{ width: '13.5em' }}> <Grid item sx={{ width: '13.5em' }}>
<RobotAvatar <RobotAvatar
nickname={garage.getRobot().nickname} nickname={garage.getSlot().robot.nickname}
smooth={true} smooth={true}
style={{ maxWidth: '12.5em', maxHeight: '12.5em' }} style={{ maxWidth: '12.5em', maxHeight: '12.5em' }}
placeholderType='generating' placeholderType='generating'
@ -178,7 +178,7 @@ const Onboarding = ({
/> />
</Grid> </Grid>
{garage.getRobot().avatarLoaded && Boolean(garage.getRobot().nickname) ? ( {garage.getSlot().robot.avatarLoaded && Boolean(garage.getSlot().robot.nickname) ? (
<Grid item> <Grid item>
<Typography align='center'>{t('Hi! My name is')}</Typography> <Typography align='center'>{t('Hi! My name is')}</Typography>
<Typography component='h5' variant='h5'> <Typography component='h5' variant='h5'>
@ -197,7 +197,7 @@ const Onboarding = ({
width: '1.5em', width: '1.5em',
}} }}
/> />
<b>{garage.getRobot().nickname}</b> <b>{garage.getSlot().robot.nickname}</b>
<Bolt <Bolt
sx={{ sx={{
color: '#fcba03', color: '#fcba03',
@ -211,7 +211,11 @@ const Onboarding = ({
) : null} ) : null}
<Grid item> <Grid item>
<Collapse <Collapse
in={!!(garage.getRobot().avatarLoaded && Boolean(garage.getRobot().nickname))} in={
!!(
garage.getSlot().robot.avatarLoaded && Boolean(garage.getSlot().robot.nickname)
)
}
> >
<Button <Button
onClick={() => { onClick={() => {

View File

@ -53,7 +53,7 @@ const RobotProfile = ({
const [loading, setLoading] = useState<boolean>(true); const [loading, setLoading] = useState<boolean>(true);
useEffect(() => { useEffect(() => {
if (garage.getRobot().nickname != null && garage.getRobot().avatarLoaded) { if (garage.getSlot().robot.nickname != null && garage.getSlot().robot.avatarLoaded) {
setLoading(false); setLoading(false);
} }
}, [robotUpdatedAt, loading]); }, [robotUpdatedAt, loading]);
@ -79,7 +79,7 @@ const RobotProfile = ({
sx={{ width: '100%' }} sx={{ width: '100%' }}
> >
<Grid item sx={{ height: '2.3em', position: 'relative' }}> <Grid item sx={{ height: '2.3em', position: 'relative' }}>
{garage.getRobot().avatarLoaded && garage.getRobot().nickname != null ? ( {garage.getSlot().robot.avatarLoaded && garage.getSlot().robot.nickname != null ? (
<Typography align='center' component='h5' variant='h5'> <Typography align='center' component='h5' variant='h5'>
<div <div
style={{ style={{
@ -98,7 +98,7 @@ const RobotProfile = ({
}} }}
/> />
)} )}
<b>{garage.getRobot().nickname}</b> <b>{garage.getSlot().robot.nickname}</b>
{width < 19 ? null : ( {width < 19 ? null : (
<Bolt <Bolt
sx={{ sx={{
@ -120,7 +120,7 @@ const RobotProfile = ({
<Grid item sx={{ width: `13.5em` }}> <Grid item sx={{ width: `13.5em` }}>
<RobotAvatar <RobotAvatar
nickname={garage.getRobot().nickname} nickname={garage.getSlot().robot.nickname}
smooth={true} smooth={true}
style={{ maxWidth: '12.5em', maxHeight: '12.5em' }} style={{ maxWidth: '12.5em', maxHeight: '12.5em' }}
placeholderType='generating' placeholderType='generating'
@ -135,7 +135,7 @@ const RobotProfile = ({
tooltipPosition='top' tooltipPosition='top'
baseUrl={hostUrl} baseUrl={hostUrl}
/> />
{garage.getRobot().found && Number(garage.getRobot().lastOrderId) > 0 ? ( {garage.getSlot().robot.found && Number(garage.getSlot().lastOrderId) > 0 ? (
<Typography align='center' variant='h6'> <Typography align='center' variant='h6'>
{t('Welcome back!')} {t('Welcome back!')}
</Typography> </Typography>
@ -145,8 +145,8 @@ const RobotProfile = ({
</Grid> </Grid>
{Boolean(garage.getSlot().activeOrderId) && {Boolean(garage.getSlot().activeOrderId) &&
garage.getRobot().avatarLoaded && garage.getSlot().robot.avatarLoaded &&
Boolean(garage.getRobot().nickname) ? ( Boolean(garage.getSlot().robot.nickname) ? (
<Grid item> <Grid item>
<Button <Button
onClick={() => { onClick={() => {
@ -163,8 +163,8 @@ const RobotProfile = ({
) : null} ) : null}
{Boolean(garage.getSlot().lastOrderId) && {Boolean(garage.getSlot().lastOrderId) &&
garage.getRobot().avatarLoaded && garage.getSlot().robot.avatarLoaded &&
Boolean(garage.getRobot().nickname) ? ( Boolean(garage.getSlot().robot.nickname) ? (
<Grid item container direction='column' alignItems='center'> <Grid item container direction='column' alignItems='center'>
<Grid item> <Grid item>
<Button <Button

View File

@ -67,7 +67,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.getRobot().copiedToken ? 'inherit' : 'primary'} color={garage.getSlot().robot.copiedToken ? 'inherit' : 'primary'}
onClick={() => { onClick={() => {
systemClient.copyToClipboard(inputToken); systemClient.copyToClipboard(inputToken);
setShowCopied(true); setShowCopied(true);

View File

@ -41,11 +41,11 @@ const RobotPage = ({ avatarBaseUrl }: RobotPageProps): JSX.Element => {
const [badToken, setBadToken] = useState<string>(''); const [badToken, setBadToken] = useState<string>('');
const [inputToken, setInputToken] = useState<string>(''); const [inputToken, setInputToken] = useState<string>('');
const [view, setView] = useState<'welcome' | 'onboarding' | 'recovery' | 'profile'>( const [view, setView] = useState<'welcome' | 'onboarding' | 'recovery' | 'profile'>(
garage.getRobot().token !== undefined ? 'profile' : 'welcome', garage.getSlot().robot.token !== undefined ? 'profile' : 'welcome',
); );
useEffect(() => { useEffect(() => {
const token = urlToken ?? garage.getRobot().token; const token = urlToken ?? garage.getSlot().robot.token;
if (token !== undefined) { if (token !== undefined) {
setInputToken(token); setInputToken(token);
if (window.NativeRobosats === undefined || torStatus === '"Done"') { if (window.NativeRobosats === undefined || torStatus === '"Done"') {

View File

@ -33,7 +33,7 @@ const ProfileDialog = ({ open = false, baseUrl, onClose }: Props): JSX.Element =
const [loading, setLoading] = useState<boolean>(true); const [loading, setLoading] = useState<boolean>(true);
useEffect(() => { useEffect(() => {
setLoading(garage.getRobot().loading); setLoading(garage.getSlot().robot.loading);
}, [robotUpdatedAt]); }, [robotUpdatedAt]);
return ( return (
@ -57,7 +57,7 @@ const ProfileDialog = ({ open = false, baseUrl, onClose }: Props): JSX.Element =
<ListItem className='profileNickname'> <ListItem className='profileNickname'>
<ListItemText secondary={t('Your robot')}> <ListItemText secondary={t('Your robot')}>
<Typography component='h6' variant='h6'> <Typography component='h6' variant='h6'>
{garage.getRobot().nickname !== undefined && ( {garage.getSlot().robot.nickname !== undefined && (
<div style={{ position: 'relative', left: '-7px' }}> <div style={{ position: 'relative', left: '-7px' }}>
<div <div
style={{ style={{
@ -70,7 +70,7 @@ const ProfileDialog = ({ open = false, baseUrl, onClose }: Props): JSX.Element =
> >
<BoltIcon sx={{ color: '#fcba03', height: '28px', width: '24px' }} /> <BoltIcon sx={{ color: '#fcba03', height: '28px', width: '24px' }} />
<a>{garage.getRobot().nickname}</a> <a>{garage.getSlot().robot.nickname}</a>
<BoltIcon sx={{ color: '#fcba03', height: '28px', width: '24px' }} /> <BoltIcon sx={{ color: '#fcba03', height: '28px', width: '24px' }} />
</div> </div>
@ -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 }}
nickname={garage.getRobot().nickname} nickname={garage.getSlot().robot.nickname}
baseUrl={baseUrl} baseUrl={baseUrl}
/> />
</ListItemAvatar> </ListItemAvatar>
@ -97,12 +97,12 @@ const ProfileDialog = ({ open = false, baseUrl, onClose }: Props): JSX.Element =
</Typography> </Typography>
{Object.values(federation.coordinators).map((coordinator: Coordinator): JSX.Element => { {Object.values(federation.coordinators).map((coordinator: Coordinator): JSX.Element => {
if (!garage.getRobot()?.loading) { if (!garage.getSlot().robot?.loading) {
return ( return (
<div key={coordinator.shortAlias}> <div key={coordinator.shortAlias}>
<RobotInfo <RobotInfo
coordinator={coordinator} coordinator={coordinator}
robot={garage.getRobot()} robot={garage.getSlot().robot}
slotIndex={garage.currentSlot} slotIndex={garage.currentSlot}
onClose={onClose} onClose={onClose}
/> />

View File

@ -43,7 +43,7 @@ const StoreTokenDialog = ({ open, onClose, onClickBack, onClickDone }: Props): J
sx={{ width: '100%', maxWidth: '550px' }} sx={{ width: '100%', maxWidth: '550px' }}
disabled disabled
label={t('Back it up!')} label={t('Back it up!')}
value={garage.getRobot().token} value={garage.getSlot().robot.token}
variant='filled' variant='filled'
size='small' size='small'
InputProps={{ InputProps={{
@ -51,7 +51,7 @@ const StoreTokenDialog = ({ open, onClose, onClickBack, onClickDone }: Props): J
<Tooltip disableHoverListener enterTouchDelay={0} title={t('Copied!')}> <Tooltip disableHoverListener enterTouchDelay={0} title={t('Copied!')}>
<IconButton <IconButton
onClick={() => { onClick={() => {
systemClient.copyToClipboard(garage.getRobot().token); systemClient.copyToClipboard(garage.getSlot().robot.token);
}} }}
> >
<ContentCopy color='primary' /> <ContentCopy color='primary' />

View File

@ -286,10 +286,10 @@ const MakerForm = ({
?.getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl) ?? {}; ?.getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl) ?? {};
const auth = { const auth = {
tokenSHA256: garage.getRobot().tokenSHA256, tokenSHA256: garage.getSlot().robot.tokenSHA256,
keys: { keys: {
pubKey: garage.getRobot().pubKey?.split('\n').join('\\'), pubKey: garage.getSlot().robot.pubKey?.split('\n').join('\\'),
encPrivKey: garage.getRobot().encPrivKey?.split('\n').join('\\'), encPrivKey: garage.getSlot().robot.encPrivKey?.split('\n').join('\\'),
}, },
}; };
@ -570,7 +570,7 @@ const MakerForm = ({
setOpenDialogs(false); setOpenDialogs(false);
}} }}
onClickDone={handleCreateOrder} onClickDone={handleCreateOrder}
hasRobot={garage.getRobot().avatarLoaded} hasRobot={garage.getSlot().robot.avatarLoaded}
onClickGenerateRobot={onClickGenerateRobot} onClickGenerateRobot={onClickGenerateRobot}
/> />
<F2fMapDialog <F2fMapDialog

View File

@ -328,7 +328,7 @@ const TakeButton = ({
action: 'take', action: 'take',
amount: currentOrder?.currency === 1000 ? takeAmount / 100000000 : takeAmount, amount: currentOrder?.currency === 1000 ? takeAmount / 100000000 : takeAmount,
}, },
{ tokenSHA256: garage.getRobot().tokenSHA256 }, { tokenSHA256: garage.getSlot().robot.tokenSHA256 },
) )
.then((data) => { .then((data) => {
setLoadingTake(false); setLoadingTake(false);
@ -370,7 +370,7 @@ const TakeButton = ({
setLoadingTake(true); setLoadingTake(true);
setOpen(closeAll); setOpen(closeAll);
}} }}
hasRobot={garage.getRobot().avatarLoaded} hasRobot={garage.getSlot().robot.avatarLoaded}
onClickGenerateRobot={onClickGenerateRobot} onClickGenerateRobot={onClickGenerateRobot}
/> />
<InactiveMakerDialog /> <InactiveMakerDialog />

View File

@ -85,7 +85,7 @@ const RobotInfo: React.FC<Props> = ({ robot, slotIndex, coordinator, onClose }:
setBadInvoice(''); setBadInvoice('');
setShowRewardsSpinner(true); setShowRewardsSpinner(true);
const robot = garage.getRobot(slotIndex); const robot = garage.getSlot(slotIndex).robot;
if (robot.encPrivKey != null && robot.token != null) { if (robot.encPrivKey != null && robot.token != null) {
void signCleartextMessage(rewardInvoice, robot.encPrivKey, robot.token).then( void signCleartextMessage(rewardInvoice, robot.encPrivKey, robot.token).then(
@ -110,21 +110,22 @@ const RobotInfo: React.FC<Props> = ({ robot, slotIndex, coordinator, onClose }:
<Accordion> <Accordion>
<AccordionSummary expandIcon={<ExpandMore />}> <AccordionSummary expandIcon={<ExpandMore />}>
{`${coordinator.longAlias}:`} {`${coordinator.longAlias}:`}
{garage.getRobot(slotIndex).earnedRewards > 0 && ( {garage.getSlot(slotIndex).robot.earnedRewards > 0 && (
<Typography color='success'>&nbsp;{t('Claim Sats!')} </Typography> <Typography color='success'>&nbsp;{t('Claim Sats!')} </Typography>
)} )}
{(garage.getRobot(slotIndex).activeOrderId ?? 0) > 0 && ( {(garage.getSlot(slotIndex).robot.activeOrderId ?? 0) > 0 && (
<Typography color='success'> <Typography color='success'>
&nbsp;<b>{t('Active order!')}</b> &nbsp;<b>{t('Active order!')}</b>
</Typography> </Typography>
)} )}
{(garage.getRobot(slotIndex).lastOrderId ?? 0) > 0 && robot.activeOrderId === undefined && ( {(garage.getSlot(slotIndex).robot.lastOrderId ?? 0) > 0 &&
<Typography color='warning'>&nbsp;{t('finished order')}</Typography> robot.activeOrderId === undefined && (
)} <Typography color='warning'>&nbsp;{t('finished order')}</Typography>
)}
</AccordionSummary> </AccordionSummary>
<AccordionDetails> <AccordionDetails>
<List dense disablePadding={true}> <List dense disablePadding={true}>
{(garage.getRobot(slotIndex).activeOrderId ?? 0) > 0 ? ( {(garage.getSlot(slotIndex).robot.activeOrderId ?? 0) > 0 ? (
<ListItemButton <ListItemButton
onClick={() => { onClick={() => {
navigate(`/order/${coordinator.shortAlias}/${String(robot.activeOrderId)}`); navigate(`/order/${coordinator.shortAlias}/${String(robot.activeOrderId)}`);
@ -141,7 +142,7 @@ const RobotInfo: React.FC<Props> = ({ robot, slotIndex, coordinator, onClose }:
secondary={t('Your current order')} secondary={t('Your current order')}
/> />
</ListItemButton> </ListItemButton>
) : (garage.getRobot(slotIndex).lastOrderId ?? 0) > 0 ? ( ) : (garage.getSlot(slotIndex).robot.lastOrderId ?? 0) > 0 ? (
<ListItemButton <ListItemButton
onClick={() => { onClick={() => {
navigate(`/order/${coordinator.shortAlias}/${String(robot.lastOrderId)}`); navigate(`/order/${coordinator.shortAlias}/${String(robot.lastOrderId)}`);

View File

@ -66,7 +66,7 @@ const EncryptedSocketChat: React.FC<Props> = ({
const [error, setError] = useState<string>(''); const [error, setError] = useState<string>('');
useEffect(() => { useEffect(() => {
if (!connected && garage.getRobot().avatarLoaded) { if (!connected && garage.getSlot().robot.avatarLoaded) {
connectWebsocket(); connectWebsocket();
} }
}, [connected, robot]); }, [connected, robot]);

View File

@ -231,7 +231,7 @@ const TradeBox = ({
}; };
const updateInvoice = function (invoice: string): void { const updateInvoice = function (invoice: string): void {
const robot = garage.getRobot(); const robot = garage.getSlot().robot;
if (robot?.encPrivKey != null && robot?.token != null) { if (robot?.encPrivKey != null && robot?.token != null) {
setLoadingButtons({ ...noLoadingButtons, submitInvoice: true }); setLoadingButtons({ ...noLoadingButtons, submitInvoice: true });
@ -246,7 +246,7 @@ const TradeBox = ({
}; };
const updateAddress = function (): void { const updateAddress = function (): void {
const robot = garage.getRobot(); const robot = garage.getSlot().robot;
if (robot?.encPrivKey != null && robot?.token != null) { if (robot?.encPrivKey != null && robot?.token != null) {
setLoadingButtons({ ...noLoadingButtons, submitAddress: true }); setLoadingButtons({ ...noLoadingButtons, submitAddress: true });

View File

@ -135,7 +135,7 @@ export const useFederationStore = (): UseFederationStoreType => {
}, [delay, currentOrder, page, badOrder]); }, [delay, currentOrder, page, badOrder]);
useEffect(() => { useEffect(() => {
const robot = garage.getRobot(); const robot = garage.getSlot().robot;
if (robot !== null) { if (robot !== null) {
if (open.profile && robot?.avatarLoaded) { if (open.profile && robot?.avatarLoaded) {

View File

@ -262,7 +262,7 @@ export class Coordinator {
}; };
fecthRobot = async (garage: Garage, index: number): Promise<Robot | null> => { fecthRobot = async (garage: Garage, index: number): Promise<Robot | null> => {
const robot = garage?.getRobot(index); const robot = garage?.getSlot(index).robot;
if (robot?.token == null) return null; if (robot?.token == null) return null;
@ -309,7 +309,7 @@ export class Coordinator {
index, index,
); );
return garage.getRobot(index); return garage.getSlot(index).robot;
}; };
fetchOrder = async (orderId: number, robot: Robot): Promise<Order | null> => { fetchOrder = async (orderId: number, robot: Robot): Promise<Order | null> => {
@ -343,7 +343,7 @@ export class Coordinator {
bad_invoice?: string; bad_invoice?: string;
successful_withdrawal?: boolean; successful_withdrawal?: boolean;
}> => { }> => {
const robot = garage.getRobot(index); const robot = garage.getSlot(index).robot;
if (!(robot?.token != null) || !(robot.encPrivKey != null)) return null; if (!(robot?.token != null) || !(robot.encPrivKey != null)) return null;
@ -365,7 +365,7 @@ export class Coordinator {
}; };
fetchStealth = async (wantsStealth: boolean, garage: Garage, index: number): Promise<null> => { fetchStealth = async (wantsStealth: boolean, garage: Garage, index: number): Promise<null> => {
const robot = garage?.getRobot(index); const robot = garage?.getSlot(index).robot;
if (!(robot?.token != null) || !(robot.encPrivKey != null)) return null; if (!(robot?.token != null) || !(robot.encPrivKey != null)) return null;

View File

@ -100,7 +100,7 @@ export class Federation {
if (order.shortAlias !== null) { if (order.shortAlias !== null) {
const coordinator = this.coordinators[order.shortAlias]; const coordinator = this.coordinators[order.shortAlias];
if (coordinator != null && order.id !== null) { if (coordinator != null && order.id !== null) {
const newOrder = await coordinator.fetchOrder(order.id, garage.getRobot()); const newOrder = await coordinator.fetchOrder(order.id, garage.getSlot().robot);
if (newOrder != null) { if (newOrder != null) {
garage.updateOrder(newOrder); garage.updateOrder(newOrder);
return newOrder; return newOrder;

View File

@ -113,7 +113,7 @@ class Garage {
const robot = this.getSlot(index).robot; const robot = this.getSlot(index).robot;
if (robot != null) { if (robot != null) {
robot.update(attributes); robot.update(attributes);
if (attributes.lastOrderId && attributes.lastOrderId != null) { if (attributes.lastOrderId !== undefined && attributes.lastOrderId != null) {
this.slots[index].lastOrderId = attributes.lastOrderId; this.slots[index].lastOrderId = attributes.lastOrderId;
this.slots[index].lastOrderShortAlias = attributes.shortAlias; this.slots[index].lastOrderShortAlias = attributes.shortAlias;
if (attributes.lastOrderId === this.slots[index].activeOrderId) { if (attributes.lastOrderId === this.slots[index].activeOrderId) {
@ -121,7 +121,7 @@ class Garage {
this.slots[index].activeOrderShortAlias = null; this.slots[index].activeOrderShortAlias = null;
} }
} }
if (attributes.activeOrderId && attributes.activeOrderId != null) { if (attributes.activeOrderId !== undefined && attributes.activeOrderId != null) {
this.slots[index].activeOrderId = attributes.activeOrderId; this.slots[index].activeOrderId = attributes.activeOrderId;
this.slots[index].activeOrderShortAlias = attributes.shortAlias; this.slots[index].activeOrderShortAlias = attributes.shortAlias;
this.slots[index].lastOrderId = null; this.slots[index].lastOrderId = null;
@ -132,10 +132,6 @@ class Garage {
} }
}; };
getRobot = (slot: number = this.currentSlot): Robot => {
return this.getSlot(slot).robot;
};
createRobot = (attributes: Record<any, any>): void => { createRobot = (attributes: Record<any, any>): void => {
const newSlot = defaultSlot; const newSlot = defaultSlot;
newSlot.robot.update(attributes); newSlot.robot.update(attributes);