diff --git a/frontend/src/basic/Main.tsx b/frontend/src/basic/Main.tsx index eee99fc8..cd51dbbf 100644 --- a/frontend/src/basic/Main.tsx +++ b/frontend/src/basic/Main.tsx @@ -1,4 +1,4 @@ -import React, { useContext } from 'react'; +import React, { useContext, useEffect, useState } from 'react'; import { MemoryRouter, HashRouter, BrowserRouter, BrowserRouterProps } from 'react-router-dom'; import { Box, Typography, styled } from '@mui/material'; import { type UseAppStoreType, AppContext } from '../contexts/AppContext'; @@ -43,10 +43,13 @@ const MainBox = styled(Box)((props) => ({ const Main: React.FC = () => { const { t } = useTranslation(); const { settings, navbarHeight } = useContext(AppContext); + const [show, setShow] = useState(false); + + useEffect(() => setShow(settings.network === 'testnet'), [settings.network]); return ( - {settings.network === 'testnet' ? ( + {show ? ( {t('Using Testnet Bitcoin')} diff --git a/frontend/src/basic/RobotPage/RobotProfile.tsx b/frontend/src/basic/RobotPage/RobotProfile.tsx index 1211b7b5..a20f13e6 100644 --- a/frontend/src/basic/RobotPage/RobotProfile.tsx +++ b/frontend/src/basic/RobotPage/RobotProfile.tsx @@ -202,22 +202,38 @@ const RobotProfile = ({ ) : null} - {!slot?.activeOrder && slot?.lastOrder ? ( - - - + + {!slot?.activeOrder && slot?.lastOrder ? ( + + + + - - ) : null} + ) : null} + + {slot?.availableRewards !== null && ( + + + + + + )} + {!slot?.activeOrder && !slot?.lastOrder && !federation.loading ? ( {t('No existing orders found')} diff --git a/frontend/src/components/Dialogs/Profile.tsx b/frontend/src/components/Dialogs/Profile.tsx index 208b66e9..44b37ae0 100644 --- a/frontend/src/components/Dialogs/Profile.tsx +++ b/frontend/src/components/Dialogs/Profile.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useEffect, useState } from 'react'; +import React, { useContext, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { @@ -32,10 +32,6 @@ const ProfileDialog = ({ open = false, onClose }: Props): React.JSX.Element => { const { t } = useTranslation(); const [audit, setAudit] = useState(false); - useEffect(() => { - loadRobot(garage.currentSlot ?? ''); - }, []); - const loadRobot = (token: string) => { garage.setCurrentSlot(token); garage.fetchRobot(federation, garage.getSlot()?.token ?? ''); diff --git a/frontend/src/components/RobotInfo/index.tsx b/frontend/src/components/RobotInfo/index.tsx index 0c883167..d915bd96 100644 --- a/frontend/src/components/RobotInfo/index.tsx +++ b/frontend/src/components/RobotInfo/index.tsx @@ -117,6 +117,11 @@ const RobotInfo: React.FC = ({ coordinator, onClose }: Props) => { ) } /> + {(robot?.earnedRewards ?? 0) > 0 && ( + + + + )} setOpenOptions(false)}> diff --git a/frontend/src/components/SettingsForm/index.tsx b/frontend/src/components/SettingsForm/index.tsx index a49b33f6..6ade10d5 100644 --- a/frontend/src/components/SettingsForm/index.tsx +++ b/frontend/src/components/SettingsForm/index.tsx @@ -29,12 +29,14 @@ import { } from '@mui/icons-material'; import { systemClient } from '../../services/System'; import Tor from '../Icons/Tor'; +import { UseFederationStoreType, FederationContext } from '../../contexts/FederationContext'; interface SettingsFormProps { dense?: boolean; } const SettingsForm = ({ dense = false }: SettingsFormProps): React.JSX.Element => { + const { updateConnection } = useContext(FederationContext); const { settings, setSettings, client } = useContext(AppContext); const theme = useTheme(); const { t } = useTranslation(); @@ -227,6 +229,8 @@ const SettingsForm = ({ dense = false }: SettingsFormProps): React.JSX.Element = exclusive={true} value={settings.network} onChange={(_e, network) => { + const newSetting = { ...settings, network }; + updateConnection(newSetting); setSettings({ ...settings, network }); systemClient.setItem('settings_network', network); }} diff --git a/frontend/src/components/TradeBox/Forms/LightningPayout.tsx b/frontend/src/components/TradeBox/Forms/LightningPayout.tsx index df4bc7eb..c8853f02 100644 --- a/frontend/src/components/TradeBox/Forms/LightningPayout.tsx +++ b/frontend/src/components/TradeBox/Forms/LightningPayout.tsx @@ -151,6 +151,7 @@ export const LightningPayoutForm = ({ // filter lnproxies when the network settings are updated let bitcoinNetwork: string = 'mainnet'; let internetNetwork: 'Clearnet' | 'I2P' | 'TOR' = 'Clearnet'; + useEffect(() => { bitcoinNetwork = settings?.network ?? 'mainnet'; if (settings.host?.includes('.i2p') === true) { diff --git a/frontend/src/contexts/AppContext.tsx b/frontend/src/contexts/AppContext.tsx index c97e1474..b373f795 100644 --- a/frontend/src/contexts/AppContext.tsx +++ b/frontend/src/contexts/AppContext.tsx @@ -153,7 +153,6 @@ export const AppContextProvider = ({ children }: AppContextProviderProps): React }, [settings.fontSize, settings.mode, settings.lightQRs]); useEffect(() => { - setSettings(getSettings()); void i18n.changeLanguage(settings.language); }, []); diff --git a/frontend/src/contexts/FederationContext.tsx b/frontend/src/contexts/FederationContext.tsx index 7f5a857c..7cdc6cb9 100644 --- a/frontend/src/contexts/FederationContext.tsx +++ b/frontend/src/contexts/FederationContext.tsx @@ -18,14 +18,14 @@ export interface UseFederationStoreType { federation: Federation; federationUpdatedAt: string; setFederationUpdatedAt: (federationUpdatedAt: string) => void; + updateConnection: (settings: Settings) => void; } -const initialFederation = new Federation('onion', new Settings(), ''); - export const initialFederationContext: UseFederationStoreType = { - federation: initialFederation, + federation: new Federation('onion', new Settings(), ''), federationUpdatedAt: '', setFederationUpdatedAt: () => {}, + updateConnection: () => {}, }; export const FederationContext = createContext(initialFederationContext); @@ -36,9 +36,13 @@ export const FederationContextProvider = ({ const { settings, page, origin, hostUrl, torStatus, client, fav } = useContext(AppContext); const { setMaker } = useContext(GarageContext); - const [federation] = useState(initialFederationContext.federation); + const [federation] = useState(new Federation(origin, settings, hostUrl)); const [federationUpdatedAt, setFederationUpdatedAt] = useState(new Date().toISOString()); + const updateConnection = (settings: Settings) => { + federation.setConnection(origin, settings, hostUrl, fav.coordinator); + }; + useEffect(() => { setMaker((maker) => { return { ...maker, coordinator: federation.getCoordinatorsAlias()[0] }; @@ -49,9 +53,7 @@ export const FederationContextProvider = ({ }, []); useEffect(() => { - if (client !== 'mobile' || torStatus === 'ON' || !settings.useProxy) { - federation.setConnection(origin, settings, hostUrl, fav.coordinator); - } + if (client !== 'mobile' || torStatus === 'ON' || !settings.useProxy) updateConnection(settings); }, [settings.network, settings.useProxy, torStatus, settings.connection]); useEffect(() => { @@ -64,6 +66,7 @@ export const FederationContextProvider = ({ federation, federationUpdatedAt, setFederationUpdatedAt, + updateConnection, }} > {children} diff --git a/frontend/src/models/Settings.model.ts b/frontend/src/models/Settings.model.ts index 5bb6e87b..9dd1f080 100644 --- a/frontend/src/models/Settings.model.ts +++ b/frontend/src/models/Settings.model.ts @@ -54,7 +54,7 @@ class BaseSettings { }); systemClient.getItem('settings_network').then((result) => { - this.network = result && result !== '' ? (result as 'mainnet' | 'testnet') : this.network; + this.network = result && result !== '' ? (result as 'mainnet' | 'testnet') : 'mainnet'; }); systemClient.getItem('settings_notifications').then((result) => { @@ -80,7 +80,7 @@ class BaseSettings { public lightQRs: boolean = false; public language?: Language; public freezeViewports: boolean = false; - public network: 'mainnet' | 'testnet' = 'mainnet'; + public network?: 'mainnet' | 'testnet'; public connection: 'api' | 'nostr' = 'nostr'; public host?: string; public unsafeClient: boolean = false; diff --git a/frontend/src/models/Slot.model.ts b/frontend/src/models/Slot.model.ts index 323f949b..a615b1f0 100644 --- a/frontend/src/models/Slot.model.ts +++ b/frontend/src/models/Slot.model.ts @@ -58,6 +58,7 @@ class Slot { lastOrder: Order | null = null; nostrSecKey?: Uint8Array; nostrPubKey?: string; + availableRewards: string | null = null; onSlotUpdate: () => void; @@ -99,6 +100,14 @@ class Slot { shortAlias: robot.shortAlias, }); } + + this.availableRewards = + robot.earnedRewards != undefined && robot.earnedRewards > 0 + ? robot.shortAlias + : this.availableRewards === robot.shortAlias + ? null + : this.availableRewards; + this.onSlotUpdate(); }; diff --git a/frontend/static/locales/ca.json b/frontend/static/locales/ca.json index 7eb1ef3b..a18f53d5 100644 --- a/frontend/static/locales/ca.json +++ b/frontend/static/locales/ca.json @@ -52,6 +52,7 @@ "Active order #{{orderID}}": "Ordre activa #{{orderID}}", "Add Robot": "Afegir Robot", "Building...": "Construint...", + "Claim Rewards": "Claim Rewards", "Delete Robot": "Delete Robot", "Last order #{{orderID}}": "Última ordre #{{orderID}}", "Looking for orders!": "Buscant ordres!", diff --git a/frontend/static/locales/cs.json b/frontend/static/locales/cs.json index e81e10d8..c8a70d76 100644 --- a/frontend/static/locales/cs.json +++ b/frontend/static/locales/cs.json @@ -52,6 +52,7 @@ "Active order #{{orderID}}": "Aktivní objednávka #{{orderID}}", "Add Robot": "Přidat robota", "Building...": "Budování...", + "Claim Rewards": "Claim Rewards", "Delete Robot": "Smazat robota", "Last order #{{orderID}}": "Poslední objednávka #{{orderID}}", "Looking for orders!": "Hledání objednávek!", diff --git a/frontend/static/locales/de.json b/frontend/static/locales/de.json index 661e34b1..c9a3b94f 100644 --- a/frontend/static/locales/de.json +++ b/frontend/static/locales/de.json @@ -52,6 +52,7 @@ "Active order #{{orderID}}": "Aktive Bestellung #{{orderID}}", "Add Robot": "Roboter hinzufügen", "Building...": "Erstelle...", + "Claim Rewards": "Claim Rewards", "Delete Robot": "Roboter löschen", "Last order #{{orderID}}": "Letzte Bestellung #{{orderID}}", "Looking for orders!": "Suche nach Bestellungen!", diff --git a/frontend/static/locales/en.json b/frontend/static/locales/en.json index 2e17b731..089b74ed 100644 --- a/frontend/static/locales/en.json +++ b/frontend/static/locales/en.json @@ -52,6 +52,7 @@ "Active order #{{orderID}}": "Active order #{{orderID}}", "Add Robot": "Add Robot", "Building...": "Building...", + "Claim Rewards": "Claim Rewards", "Delete Robot": "Delete Robot", "Last order #{{orderID}}": "Last order #{{orderID}}", "Looking for orders!": "Looking for orders!", diff --git a/frontend/static/locales/es.json b/frontend/static/locales/es.json index 4f77818a..6d2d0a26 100644 --- a/frontend/static/locales/es.json +++ b/frontend/static/locales/es.json @@ -52,6 +52,7 @@ "Active order #{{orderID}}": "Orden activa #{{orderID}}", "Add Robot": "Añadir Robot", "Building...": "Construyendo...", + "Claim Rewards": "Claim Rewards", "Delete Robot": "Eliminar Robot", "Last order #{{orderID}}": "Última orden #{{orderID}}", "Looking for orders!": "Buscando órdenes!", diff --git a/frontend/static/locales/eu.json b/frontend/static/locales/eu.json index 2ed557d9..aa904b20 100644 --- a/frontend/static/locales/eu.json +++ b/frontend/static/locales/eu.json @@ -52,6 +52,7 @@ "Active order #{{orderID}}": "Eskaera aktiboa #{{orderID}}", "Add Robot": "Gehitu Robota", "Building...": "Eraikitzen...", + "Claim Rewards": "Claim Rewards", "Delete Robot": "Ezabatu Robota", "Last order #{{orderID}}": "Azken eskaera #{{orderID}}", "Looking for orders!": "Eskaerak bilatzen!", diff --git a/frontend/static/locales/fr.json b/frontend/static/locales/fr.json index f9e548b5..1f77bfcb 100644 --- a/frontend/static/locales/fr.json +++ b/frontend/static/locales/fr.json @@ -52,6 +52,7 @@ "Active order #{{orderID}}": "Ordre actif #{{orderID}}", "Add Robot": "Ajouter un robot", "Building...": "Construction...", + "Claim Rewards": "Claim Rewards", "Delete Robot": "Supprimer le robot", "Last order #{{orderID}}": "Dernier ordre #{{orderID}}", "Looking for orders!": "Recherche de commandes !", diff --git a/frontend/static/locales/it.json b/frontend/static/locales/it.json index d9bc4079..c73ccbbe 100644 --- a/frontend/static/locales/it.json +++ b/frontend/static/locales/it.json @@ -52,6 +52,7 @@ "Active order #{{orderID}}": "Ordine attivo #{{orderID}}", "Add Robot": "Aggiungi robot", "Building...": "Costruzione...", + "Claim Rewards": "Claim Rewards", "Delete Robot": "Elimina robot", "Last order #{{orderID}}": "Ultimo ordine #{{orderID}}", "Looking for orders!": "Alla ricerca di ordini!", diff --git a/frontend/static/locales/ja.json b/frontend/static/locales/ja.json index 1f31d9f6..3de34507 100644 --- a/frontend/static/locales/ja.json +++ b/frontend/static/locales/ja.json @@ -52,6 +52,7 @@ "Active order #{{orderID}}": "公開中の注文 #{{orderID}}", "Add Robot": "ロボットを追加", "Building...": "生成中...", + "Claim Rewards": "Claim Rewards", "Delete Robot": "ロボットを削除", "Last order #{{orderID}}": "直前の注文 #{{orderID}}", "Looking for orders!": "注文を探しています!", diff --git a/frontend/static/locales/pl.json b/frontend/static/locales/pl.json index 8fdfcbfe..9d77f584 100644 --- a/frontend/static/locales/pl.json +++ b/frontend/static/locales/pl.json @@ -52,6 +52,7 @@ "Active order #{{orderID}}": "Aktywne zamówienie #{{orderID}}", "Add Robot": "Dodaj Robota", "Building...": "Budowanie...", + "Claim Rewards": "Claim Rewards", "Delete Robot": "Usuń robota", "Last order #{{orderID}}": "Ostatnie zamówienie #{{orderID}}", "Looking for orders!": "Szukam zamówień!", diff --git a/frontend/static/locales/pt.json b/frontend/static/locales/pt.json index 0b237a6a..83b61a16 100644 --- a/frontend/static/locales/pt.json +++ b/frontend/static/locales/pt.json @@ -52,6 +52,7 @@ "Active order #{{orderID}}": "Ordem ativa #{{orderID}}", "Add Robot": "Adicionar Robô", "Building...": "Criando...", + "Claim Rewards": "Claim Rewards", "Delete Robot": "Deletar Robô", "Last order #{{orderID}}": "Última ordem #{{orderID}}", "Looking for orders!": "Procurando por ordens!", diff --git a/frontend/static/locales/ru.json b/frontend/static/locales/ru.json index b6efdbc4..64dabaa1 100644 --- a/frontend/static/locales/ru.json +++ b/frontend/static/locales/ru.json @@ -52,6 +52,7 @@ "Active order #{{orderID}}": "Активный ордер #{{orderID}}", "Add Robot": "Добавить робота", "Building...": "Строим...", + "Claim Rewards": "Claim Rewards", "Delete Robot": "Удалить робота", "Last order #{{orderID}}": "Последний ордер #{{orderID}}", "Looking for orders!": "В поисках ордеров!", diff --git a/frontend/static/locales/sv.json b/frontend/static/locales/sv.json index f6d57736..70b41ca1 100644 --- a/frontend/static/locales/sv.json +++ b/frontend/static/locales/sv.json @@ -52,6 +52,7 @@ "Active order #{{orderID}}": "Aktiv order #{{orderID}}", "Add Robot": "Lägg till robot", "Building...": "Bygger...", + "Claim Rewards": "Claim Rewards", "Delete Robot": "Radera robot", "Last order #{{orderID}}": "Senaste order #{{orderID}}", "Looking for orders!": "Letar efter ordrar!", diff --git a/frontend/static/locales/sw.json b/frontend/static/locales/sw.json index dcd5fc5f..9e17217f 100644 --- a/frontend/static/locales/sw.json +++ b/frontend/static/locales/sw.json @@ -52,6 +52,7 @@ "Active order #{{orderID}}": "Amri hai #{{orderID}}", "Add Robot": "Ongeza Roboti", "Building...": "Inajengwa...", + "Claim Rewards": "Claim Rewards", "Delete Robot": "Futa Roboti", "Last order #{{orderID}}": "Amri ya mwisho #{{orderID}}", "Looking for orders!": "Inatafuta amri!", diff --git a/frontend/static/locales/th.json b/frontend/static/locales/th.json index ecceb055..b744e8cd 100644 --- a/frontend/static/locales/th.json +++ b/frontend/static/locales/th.json @@ -52,6 +52,7 @@ "Active order #{{orderID}}": "รายการที่ใช้งาน #{{orderID}}", "Add Robot": "เพิ่มหุ่นยนต์", "Building...": "กำลังสร้าง...", + "Claim Rewards": "Claim Rewards", "Delete Robot": "ลบหุ่นยนต์", "Last order #{{orderID}}": "คำสั่งล่าสุด #{{orderID}}", "Looking for orders!": "กำลังมองหาคำสั่งซื้อ!", diff --git a/frontend/static/locales/zh-SI.json b/frontend/static/locales/zh-SI.json index 15bd1f3d..740c8d1f 100644 --- a/frontend/static/locales/zh-SI.json +++ b/frontend/static/locales/zh-SI.json @@ -52,6 +52,7 @@ "Active order #{{orderID}}": "活跃订单 #{{orderID}}", "Add Robot": "添加机器人", "Building...": "正在建造...", + "Claim Rewards": "Claim Rewards", "Delete Robot": "删除机器人", "Last order #{{orderID}}": "上一张订单 #{{orderID}}", "Looking for orders!": "查找订单!", diff --git a/frontend/static/locales/zh-TR.json b/frontend/static/locales/zh-TR.json index e5273955..27344a4c 100644 --- a/frontend/static/locales/zh-TR.json +++ b/frontend/static/locales/zh-TR.json @@ -52,6 +52,7 @@ "Active order #{{orderID}}": "活躍訂單 #{{orderID}}", "Add Robot": "添加機器人", "Building...": "正在建造...", + "Claim Rewards": "Claim Rewards", "Delete Robot": "刪除機器人", "Last order #{{orderID}}": "上一張訂單 #{{orderID}}", "Looking for orders!": "找尋訂單!",