Skip to content

Commit

Permalink
Fix too-many fetchRobots and coordinator endpoints print
Browse files Browse the repository at this point in the history
  • Loading branch information
Reckless-Satoshi committed Jan 14, 2024
1 parent c98e643 commit 27b2652
Show file tree
Hide file tree
Showing 24 changed files with 53 additions and 41 deletions.
1 change: 0 additions & 1 deletion frontend/src/basic/MainDialogs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ const MainDialogs = (): JSX.Element => {
/>
<ProfileDialog
open={open.profile}
baseUrl={hostUrl}
onClose={() => {
setOpen({ ...open, profile: false });
}}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/basic/RobotPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const RobotPage = (): JSX.Element => {

useEffect(() => {
const token = urlToken ?? garage.currentSlot;
if (token !== undefined && token !== null) {
if (token !== undefined && token !== null && page === 'robot') {
setInputToken(token);
if (window.NativeRobosats === undefined || torStatus === '"Done"') {
getGenerateRobot(token);
Expand Down
21 changes: 18 additions & 3 deletions frontend/src/components/Dialogs/Coordinator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -635,13 +635,28 @@ const CoordinatorDialog = ({ open = false, onClose, network, shortAlias }: Props
<ListItemIcon>
<Dns />
</ListItemIcon>
<ListItemText secondary={t('Coordinator domain')}>
<ListItemText
secondary={t('Coordinator domain')}
primaryTypographyProps={{
style: {
maxWidth: '20em',
wordWrap: 'break-word',
overflowWrap: 'break-word',
},
}}
>
<Link
target='_blank'
href={coordinator?.[settings.network][origin]}
href={
coordinator?.[settings.network][
settings.selfhostedClient ? 'onion' : origin
]
}
rel='noreferrer'
>
{`${coordinator?.[settings.network][origin]}`}
{`${coordinator?.[settings.network][
settings.selfhostedClient ? 'onion' : origin
]}`}
</Link>
</ListItemText>
</ListItem>
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/components/Dialogs/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ import { type Coordinator } from '../../models';
interface Props {
open: boolean;
onClose: () => void;
baseUrl: string;
}

const ProfileDialog = ({ open = false, baseUrl, onClose }: Props): JSX.Element => {
const ProfileDialog = ({ open = false, onClose }: Props): JSX.Element => {
const { federation } = useContext<UseFederationStoreType>(FederationContext);
const { garage, robotUpdatedAt } = useContext<UseGarageStoreType>(GarageContext);
const { t } = useTranslation();
Expand Down Expand Up @@ -92,7 +91,7 @@ const ProfileDialog = ({ open = false, baseUrl, onClose }: Props): JSX.Element =
</List>

<Typography>
<b>{t('Coordinators that know your robots')}</b>
<b>{t('Coordinators that know your robot:')}</b>
</Typography>

{Object.values(federation.coordinators).map((coordinator: Coordinator): JSX.Element => {
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/MakerForm/MakerForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ const MakerForm = ({
const amountSafeThresholds = [1.03, 0.98];

useEffect(() => {
const slot = garage.getSlot();
if (slot?.token) void federation.fetchRobot(garage, slot?.token);
// Why?
// const slot = garage.getSlot();
// if (slot?.token) void federation.fetchRobot(garage, slot?.token);
}, [garage.currentSlot]);

useEffect(() => {
Expand Down
18 changes: 12 additions & 6 deletions frontend/src/contexts/FederationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,22 @@ export const FederationContextProvider = ({
if (page === 'offers') void federation.updateBook();
}, [page]);

// use effects to fetchRobots on app start and network change
useEffect(() => {
const slot = garage.getSlot();
const robot = slot?.getRobot();

if (robot && garage.currentSlot) {
if (open.profile && Boolean(slot?.hashId) && slot?.token) {
void federation.fetchRobot(garage, slot?.token); // refresh/update existing robot
} else if (slot?.token && robot.encPrivKey && robot.pubKey) {
void federation.fetchRobot(garage, slot.token); // create new robot with existing token and keys (on network and coordinator change)
}
if (robot && garage.currentSlot && slot?.token && robot.encPrivKey && robot.pubKey) {
void federation.fetchRobot(garage, slot.token);
}
}, [settings.network]);
// use effects to fetchRobots on Profile open
useEffect(() => {
const slot = garage.getSlot();
const robot = slot?.getRobot();

if (open.profile && slot?.hashId && slot?.token) {
void federation.fetchRobot(garage, slot?.token); // refresh/update existing robot
}
}, [open.profile]);

Expand Down
8 changes: 0 additions & 8 deletions frontend/src/models/Coordinator.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ export interface Origins {
i2p: Origin | undefined;
}

export interface getEndpointProps {
coordinator: Coordinator;
network: 'mainnet' | 'testnet';
origin: Origin;
selfHosted: boolean;
hostUrl: string;
}

export class Coordinator {
constructor(value: any) {
this.longAlias = value.longAlias;
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/locales/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"Generate a robot avatar first. Then create your own order.": "Primer genera un avatar de robot. A continuació, crea la teva pròpia oferta.",
"You do not have a robot avatar": "No tens un avatar robot",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robots": "Coordinators that know your robots",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Your Robot": "El teu Robot",
"Your robot": "El teu robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"Generate a robot avatar first. Then create your own order.": "Generate a robot avatar first. Then create your own order.",
"You do not have a robot avatar": "Nemáš robota a avatar",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robots": "Coordinators that know your robots",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Your Robot": "Your Robot",
"Your robot": "Tvůj robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"Generate a robot avatar first. Then create your own order.": "Generate a robot avatar first. Then create your own order.",
"You do not have a robot avatar": "Du hast keinen Roboter-Avatar",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robots": "Coordinators that know your robots",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Your Robot": "Your Robot",
"Your robot": "Dein Roboter",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"Generate a robot avatar first. Then create your own order.": "Generate a robot avatar first. Then create your own order.",
"You do not have a robot avatar": "You do not have a robot avatar",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robots": "Coordinators that know your robots",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Your Robot": "Your Robot",
"Your robot": "Your robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"Generate a robot avatar first. Then create your own order.": "Primero genera un robot avatar. Después crea tu propia orden.",
"You do not have a robot avatar": "No tienes un avatar robot",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robots": "Coordinators that know your robots",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Your Robot": "Your Robot",
"Your robot": "Tu Robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/locales/eu.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"Generate a robot avatar first. Then create your own order.": "Generate a robot avatar first. Then create your own order.",
"You do not have a robot avatar": "Ez daukazu robot avatarrik",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robots": "Coordinators that know your robots",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Your Robot": "Your Robot",
"Your robot": "Zure robota",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"Generate a robot avatar first. Then create your own order.": "Créez d'abord un avatar de robot. Créez ensuite votre propre commande.",
"You do not have a robot avatar": "Vous n'avez pas d'avatar robot",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robots": "Coordinators that know your robots",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Your Robot": "Votre Robot",
"Your robot": "Votre robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"Generate a robot avatar first. Then create your own order.": "Genera prima un avatar robot. Poi crea il tuo ordine.",
"You do not have a robot avatar": "Non hai un avatar robot",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robots": "Coordinators that know your robots",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Your Robot": "Il tuo Robot",
"Your robot": "Il tuo robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"Generate a robot avatar first. Then create your own order.": "最初にロボットアバターを生成してください。次に自分のオーダーを作成してください。",
"You do not have a robot avatar": "ロボットのアバターがありません",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robots": "Coordinators that know your robots",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Your Robot": "Your Robot",
"Your robot": "あなたのロボット",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"Generate a robot avatar first. Then create your own order.": "Generate a robot avatar first. Then create your own order.",
"You do not have a robot avatar": "You do not have a robot avatar",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robots": "Coordinators that know your robots",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Your Robot": "Your Robot",
"Your robot": "Twój robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"Generate a robot avatar first. Then create your own order.": "Generate a robot avatar first. Then create your own order.",
"You do not have a robot avatar": "Você não tem um avatar de robô",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robots": "Coordinators that know your robots",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Your Robot": "Your Robot",
"Your robot": "Seu robô",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"Generate a robot avatar first. Then create your own order.": "Сначала создайте аватар робота. Затем создайте свой ордер.",
"You do not have a robot avatar": "У Вас нет аватара робота",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robots": "Coordinators that know your robots",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Your Robot": "Ваш Robot",
"Your robot": "Ваш Робот",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/locales/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"Generate a robot avatar first. Then create your own order.": "Generate a robot avatar first. Then create your own order.",
"You do not have a robot avatar": "Du har ingen robotavatar",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robots": "Coordinators that know your robots",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Your Robot": "Your Robot",
"Your robot": "Din robot",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/locales/sw.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"Generate a robot avatar first. Then create your own order.": "Zalisha picha ya mwakilishi wa roboti kwanza. Kisha tengeneza amri yako mwenyewe.",
"You do not have a robot avatar": "Huna picha ya mwakilishi wa roboti",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robots": "Coordinators that know your robots",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Your Robot": "Roboti yako",
"Your robot": "Roboti yako",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/locales/th.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"Generate a robot avatar first. Then create your own order.": "Generate a robot avatar first. Then create your own order.",
"You do not have a robot avatar": "คุณไม่มีโรบอท",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robots": "Coordinators that know your robots",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Your Robot": "Your Robot",
"Your robot": "โรบอทของคุณ",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/locales/zh-SI.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"Generate a robot avatar first. Then create your own order.": "请先生成一个机器人头像,然后创建你自己的订单。",
"You do not have a robot avatar": "你没有机器人头像",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robots": "Coordinators that know your robots",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Your Robot": "你的机器人",
"Your robot": "你的机器人",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
Expand Down
2 changes: 1 addition & 1 deletion frontend/static/locales/zh-TR.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"Generate a robot avatar first. Then create your own order.": "請先生成一個機器人頭像,然後創建你自己的訂單。",
"You do not have a robot avatar": "你沒有機器人頭像",
"#29": "Phrases in components/Dialogs/Profile.tsx",
"Coordinators that know your robots": "Coordinators that know your robots",
"Coordinators that know your robot:": "Coordinators that know your robot:",
"Your Robot": "你的機器人",
"Your robot": "你的機器人",
"#30": "Phrases in components/Dialogs/StoreToken.tsx",
Expand Down

0 comments on commit 27b2652

Please sign in to comment.