Skip to content

Commit

Permalink
Fetch robot profile from coordinator
Browse files Browse the repository at this point in the history
  • Loading branch information
Reckless-Satoshi committed Sep 8, 2023
1 parent 3ab6331 commit 79d5d9a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
31 changes: 27 additions & 4 deletions frontend/src/basic/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import React, { useContext } from 'react';
import React, { useContext, useEffect, useState } from 'react';
import { MemoryRouter, BrowserRouter, Routes, Route } from 'react-router-dom';
import { Box, Slide, Typography, styled } from '@mui/material';
import { type UseAppStoreType, AppContext, closeAll, hostUrl } from '../contexts/AppContext';
import {
type UseAppStoreType,
AppContext,
closeAll,
hostUrl,
origin,
} from '../contexts/AppContext';

import { RobotPage, MakerPage, BookPage, OrderPage, SettingsPage, NavBar, MainDialogs } from './';
import RobotAvatar from '../components/RobotAvatar';
import Notifications from '../components/Notifications';

import { useTranslation } from 'react-i18next';
import { getEndpoint } from '../models/Coordinator.model';

const Router = window.NativeRobosats === undefined ? BrowserRouter : MemoryRouter;

Expand Down Expand Up @@ -35,17 +42,33 @@ const Main: React.FC = () => {
order,
page,
slideDirection,
federation,
sortedCoordinators,
setOpen,
windowSize,
navbarHeight,
} = useContext<UseAppStoreType>(AppContext);

const [avatarBaseUrl, setAvatarBaseUrl] = useState<string>(hostUrl);

useEffect(() => {
const { url, basePath } = getEndpoint({
network: settings.network,
coordinator: federation[sortedCoordinators[0]],
origin,
selfHosted: settings.selfhostedClient,
hostUrl,
});
setAvatarBaseUrl(url + basePath);
console.log(url + basePath);
}, [settings.network, settings.selfhostedClient, federation, sortedCoordinators]);

return (
<Router>
<RobotAvatar
style={{ display: 'none' }}
nickname={robot.nickname}
baseUrl={hostUrl}
baseUrl={avatarBaseUrl}
onLoad={() => {
setRobot((robot) => {
return { ...robot, avatarLoaded: true };
Expand Down Expand Up @@ -82,7 +105,7 @@ const Main: React.FC = () => {
appear={slideDirection.in !== undefined}
>
<div>
<RobotPage />
<RobotPage avatarBaseUrl={avatarBaseUrl} />
</div>
</Slide>
}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/basic/RobotPage/RobotProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface RobotProfileProps {
logoutRobot: () => void;
setInputToken: (state: string) => void;
width: number;
baseUrl: string;
}

const RobotProfile = ({
Expand All @@ -42,6 +43,7 @@ const RobotProfile = ({
logoutRobot,
setView,
width,
baseUrl,
}: RobotProfileProps): JSX.Element => {
const { currentSlot, garage, setCurrentSlot, windowSize, currentOrder } =
useContext<UseAppStoreType>(AppContext);
Expand Down
13 changes: 8 additions & 5 deletions frontend/src/basic/RobotPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ import RobotProfile from './RobotProfile';
import Recovery from './Recovery';
import { TorIcon } from '../../components/Icons';
import { genKey } from '../../pgp';
import { AppContext, hostUrl, type UseAppStoreType } from '../../contexts/AppContext';
import { AppContext, type UseAppStoreType } from '../../contexts/AppContext';
import { validateTokenEntropy } from '../../utils';

const RobotPage = (): JSX.Element => {
interface RobotPageProps {
avatarBaseUrl: string;
}

const RobotPage = ({ avatarBaseUrl }: RobotPageProps): JSX.Element => {
const { robot, setRobot, fetchFederationRobot, torStatus, windowSize, settings } =
useContext<UseAppStoreType>(AppContext);
const { t } = useTranslation();
Expand Down Expand Up @@ -156,7 +160,7 @@ const RobotPage = (): JSX.Element => {
inputToken={inputToken}
setInputToken={setInputToken}
getGenerateRobot={getGenerateRobot}
baseUrl={hostUrl}
avatarBaseUrl={avatarBaseUrl}
/>
) : null}

Expand All @@ -170,7 +174,7 @@ const RobotPage = (): JSX.Element => {
inputToken={inputToken}
setInputToken={setInputToken}
getGenerateRobot={getGenerateRobot}
baseUrl={hostUrl}
avatarBaseUrl={avatarBaseUrl}
/>
) : null}

Expand All @@ -183,7 +187,6 @@ const RobotPage = (): JSX.Element => {
inputToken={inputToken}
setInputToken={setInputToken}
getGenerateRobot={getGenerateRobot}
baseUrl={hostUrl}
/>
) : null}
</Paper>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/RobotAvatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const RobotAvatar: React.FC<Props> = ({
setNicknameReady(false);
setActiveBackground(true);
}
console.log(avatarSrc);
}, [nickname]);

const statusBadge = (
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/contexts/AppContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export const useAppStore = (): UseAppStoreType => {
return sortedCoordinators;
}, []);

const [focusedCoordinator, setFocusedCoordinator] = useState<string>('');
const [focusedCoordinator, setFocusedCoordinator] = useState<string>(sortedCoordinators[0]);
const [fav, setFav] = useState<Favorites>({ type: null, currency: 0, mode: 'fiat' });

const [delay, setDelay] = useState<number>(60000);
Expand Down

0 comments on commit 79d5d9a

Please sign in to comment.