From 27b265220e6bda98ec7df4bca38391d98ab0667b Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Sun, 14 Jan 2024 18:20:48 +0000 Subject: [PATCH] Fix too-many fetchRobots and coordinator endpoints print --- frontend/src/basic/MainDialogs/index.tsx | 1 - frontend/src/basic/RobotPage/index.tsx | 2 +- .../src/components/Dialogs/Coordinator.tsx | 21 ++++++++++++++++--- frontend/src/components/Dialogs/Profile.tsx | 5 ++--- .../src/components/MakerForm/MakerForm.tsx | 5 +++-- frontend/src/contexts/FederationContext.tsx | 18 ++++++++++------ frontend/src/models/Coordinator.model.ts | 8 ------- frontend/static/locales/ca.json | 2 +- frontend/static/locales/cs.json | 2 +- frontend/static/locales/de.json | 2 +- frontend/static/locales/en.json | 2 +- frontend/static/locales/es.json | 2 +- frontend/static/locales/eu.json | 2 +- frontend/static/locales/fr.json | 2 +- frontend/static/locales/it.json | 2 +- frontend/static/locales/ja.json | 2 +- frontend/static/locales/pl.json | 2 +- frontend/static/locales/pt.json | 2 +- frontend/static/locales/ru.json | 2 +- frontend/static/locales/sv.json | 2 +- frontend/static/locales/sw.json | 2 +- frontend/static/locales/th.json | 2 +- frontend/static/locales/zh-SI.json | 2 +- frontend/static/locales/zh-TR.json | 2 +- 24 files changed, 53 insertions(+), 41 deletions(-) diff --git a/frontend/src/basic/MainDialogs/index.tsx b/frontend/src/basic/MainDialogs/index.tsx index 2cbfd369..a13151b6 100644 --- a/frontend/src/basic/MainDialogs/index.tsx +++ b/frontend/src/basic/MainDialogs/index.tsx @@ -83,7 +83,6 @@ const MainDialogs = (): JSX.Element => { /> { setOpen({ ...open, profile: false }); }} diff --git a/frontend/src/basic/RobotPage/index.tsx b/frontend/src/basic/RobotPage/index.tsx index 3b747dc2..bed8672a 100644 --- a/frontend/src/basic/RobotPage/index.tsx +++ b/frontend/src/basic/RobotPage/index.tsx @@ -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); diff --git a/frontend/src/components/Dialogs/Coordinator.tsx b/frontend/src/components/Dialogs/Coordinator.tsx index a098d909..9bb1db85 100644 --- a/frontend/src/components/Dialogs/Coordinator.tsx +++ b/frontend/src/components/Dialogs/Coordinator.tsx @@ -635,13 +635,28 @@ const CoordinatorDialog = ({ open = false, onClose, network, shortAlias }: Props - + - {`${coordinator?.[settings.network][origin]}`} + {`${coordinator?.[settings.network][ + settings.selfhostedClient ? 'onion' : origin + ]}`} diff --git a/frontend/src/components/Dialogs/Profile.tsx b/frontend/src/components/Dialogs/Profile.tsx index e7af58c3..c0ad64bb 100644 --- a/frontend/src/components/Dialogs/Profile.tsx +++ b/frontend/src/components/Dialogs/Profile.tsx @@ -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(FederationContext); const { garage, robotUpdatedAt } = useContext(GarageContext); const { t } = useTranslation(); @@ -92,7 +91,7 @@ const ProfileDialog = ({ open = false, baseUrl, onClose }: Props): JSX.Element = - {t('Coordinators that know your robots')} + {t('Coordinators that know your robot:')} {Object.values(federation.coordinators).map((coordinator: Coordinator): JSX.Element => { diff --git a/frontend/src/components/MakerForm/MakerForm.tsx b/frontend/src/components/MakerForm/MakerForm.tsx index 37d25f61..3a6e367f 100644 --- a/frontend/src/components/MakerForm/MakerForm.tsx +++ b/frontend/src/components/MakerForm/MakerForm.tsx @@ -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(() => { diff --git a/frontend/src/contexts/FederationContext.tsx b/frontend/src/contexts/FederationContext.tsx index 09434541..0260ad0b 100644 --- a/frontend/src/contexts/FederationContext.tsx +++ b/frontend/src/contexts/FederationContext.tsx @@ -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]); diff --git a/frontend/src/models/Coordinator.model.ts b/frontend/src/models/Coordinator.model.ts index d929dc5d..3950d69d 100644 --- a/frontend/src/models/Coordinator.model.ts +++ b/frontend/src/models/Coordinator.model.ts @@ -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; diff --git a/frontend/static/locales/ca.json b/frontend/static/locales/ca.json index 9ebd3009..a718a6c5 100644 --- a/frontend/static/locales/ca.json +++ b/frontend/static/locales/ca.json @@ -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", diff --git a/frontend/static/locales/cs.json b/frontend/static/locales/cs.json index abba51d9..c3dd8dd6 100644 --- a/frontend/static/locales/cs.json +++ b/frontend/static/locales/cs.json @@ -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", diff --git a/frontend/static/locales/de.json b/frontend/static/locales/de.json index e79600c2..b2bd1a4f 100644 --- a/frontend/static/locales/de.json +++ b/frontend/static/locales/de.json @@ -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", diff --git a/frontend/static/locales/en.json b/frontend/static/locales/en.json index c67af58b..d9e99f14 100644 --- a/frontend/static/locales/en.json +++ b/frontend/static/locales/en.json @@ -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", diff --git a/frontend/static/locales/es.json b/frontend/static/locales/es.json index 879722ef..65cb3161 100644 --- a/frontend/static/locales/es.json +++ b/frontend/static/locales/es.json @@ -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", diff --git a/frontend/static/locales/eu.json b/frontend/static/locales/eu.json index 33bbee53..abf60ef4 100644 --- a/frontend/static/locales/eu.json +++ b/frontend/static/locales/eu.json @@ -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", diff --git a/frontend/static/locales/fr.json b/frontend/static/locales/fr.json index af7a62b3..12e92ee4 100644 --- a/frontend/static/locales/fr.json +++ b/frontend/static/locales/fr.json @@ -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", diff --git a/frontend/static/locales/it.json b/frontend/static/locales/it.json index 2dd92354..08a80bd7 100644 --- a/frontend/static/locales/it.json +++ b/frontend/static/locales/it.json @@ -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", diff --git a/frontend/static/locales/ja.json b/frontend/static/locales/ja.json index 9e4b8d7f..2735edb6 100644 --- a/frontend/static/locales/ja.json +++ b/frontend/static/locales/ja.json @@ -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", diff --git a/frontend/static/locales/pl.json b/frontend/static/locales/pl.json index d35ce58b..6f04eeeb 100644 --- a/frontend/static/locales/pl.json +++ b/frontend/static/locales/pl.json @@ -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", diff --git a/frontend/static/locales/pt.json b/frontend/static/locales/pt.json index 96216ca5..5704d45c 100644 --- a/frontend/static/locales/pt.json +++ b/frontend/static/locales/pt.json @@ -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", diff --git a/frontend/static/locales/ru.json b/frontend/static/locales/ru.json index 9f027aad..2d6bc2a3 100644 --- a/frontend/static/locales/ru.json +++ b/frontend/static/locales/ru.json @@ -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", diff --git a/frontend/static/locales/sv.json b/frontend/static/locales/sv.json index b75f0c09..74dd3334 100644 --- a/frontend/static/locales/sv.json +++ b/frontend/static/locales/sv.json @@ -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", diff --git a/frontend/static/locales/sw.json b/frontend/static/locales/sw.json index 447453ac..4ee81379 100644 --- a/frontend/static/locales/sw.json +++ b/frontend/static/locales/sw.json @@ -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", diff --git a/frontend/static/locales/th.json b/frontend/static/locales/th.json index 544caf7a..41328c0c 100644 --- a/frontend/static/locales/th.json +++ b/frontend/static/locales/th.json @@ -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", diff --git a/frontend/static/locales/zh-SI.json b/frontend/static/locales/zh-SI.json index f0d8de48..4112a016 100644 --- a/frontend/static/locales/zh-SI.json +++ b/frontend/static/locales/zh-SI.json @@ -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", diff --git a/frontend/static/locales/zh-TR.json b/frontend/static/locales/zh-TR.json index 5271e64d..5394b6e9 100644 --- a/frontend/static/locales/zh-TR.json +++ b/frontend/static/locales/zh-TR.json @@ -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",