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 2cbfd3691..a13151b6c 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 3b747dc25..bed8672a8 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 a098d9092..9bb1db856 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 e7af58c3a..c0ad64bb1 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 37d25f610..3a6e367fb 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 09434541e..0260ad0b2 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 d929dc5dc..3950d69d1 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 9ebd30096..a718a6c5a 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 abba51d97..c3dd8dd6e 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 e79600c2b..b2bd1a4f2 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 c67af58b2..d9e99f149 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 879722ef1..65cb31615 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 33bbee536..abf60ef43 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 af7a62b31..12e92ee4e 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 2dd923548..08a80bd7c 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 9e4b8d7fc..2735edb67 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 d35ce58bb..6f04eeebc 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 96216ca5c..5704d45c0 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 9f027aadf..2d6bc2a3c 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 b75f0c09d..74dd3334c 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 447453ac7..4ee813792 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 544caf7a4..41328c0c4 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 f0d8de48b..4112a0160 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 5271e64d4..5394b6e99 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",