From 6843760b87b57f92cfd85813d787140001eb5c55 Mon Sep 17 00:00:00 2001 From: amitpanwar789 Date: Fri, 14 Jun 2024 20:48:13 +0530 Subject: [PATCH] ternaries removed and DesktopRobosats switch it to RobosatsClient === 'desktop-app' --- desktopApp/index.html | 2 +- frontend/package.json | 3 +-- frontend/src/App.tsx | 2 +- frontend/src/basic/Main.tsx | 11 +++++++++- frontend/src/basic/RobotPage/RobotProfile.tsx | 6 +++--- frontend/src/components/BookTable/index.tsx | 2 +- frontend/src/contexts/AppContext.tsx | 8 +++---- frontend/src/models/Garage.model.ts | 4 ++-- frontend/src/services/Native/index.d.ts | 2 +- .../src/services/Roboidentities/Native.ts | 2 +- .../RoboidentitiesWebClient/index.ts | 4 ++-- frontend/src/services/Roboidentities/Web.ts | 2 +- .../System/SystemDesktopClient/index.ts | 3 +-- frontend/src/services/System/index.ts | 21 +++++++++++++------ .../src/services/api/ApiNativeClient/index.ts | 2 +- 15 files changed, 45 insertions(+), 29 deletions(-) diff --git a/desktopApp/index.html b/desktopApp/index.html index c71d44f8..7045672b 100644 --- a/desktopApp/index.html +++ b/desktopApp/index.html @@ -56,7 +56,7 @@ diff --git a/frontend/package.json b/frontend/package.json index c5a94906..53c155f9 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -6,8 +6,7 @@ "scripts": { "dev": "node --max-old-space-size=4096 ./node_modules/.bin/webpack --watch --progress --mode development", "test": "jest", - "build": "webpack --config webpack.config.ts --mode development", - "builds": "react-scripts build", + "build": "webpack --config webpack.config.ts --mode production", "lint": "eslint src/**/*.{ts,tsx}", "lint:fix": "eslint --fix 'src/**/*.{ts,tsx}'", "format": "prettier --write '**/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc" diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 236650be..1bc158d1 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -24,7 +24,7 @@ const App = (): JSX.Element => { - {(window.NativeRobosats === undefined && window.DesktopRobosats === undefined )? : } + {(window.NativeRobosats === undefined && window.RobosatsClient === undefined )? : }
diff --git a/frontend/src/basic/Main.tsx b/frontend/src/basic/Main.tsx index cd6840d2..328c0b66 100644 --- a/frontend/src/basic/Main.tsx +++ b/frontend/src/basic/Main.tsx @@ -10,7 +10,16 @@ import Notifications from '../components/Notifications'; import { useTranslation } from 'react-i18next'; import { GarageContext, type UseGarageStoreType } from '../contexts/GarageContext'; -const Router = (window.NativeRobosats === undefined && window.DesktopRobosats === undefined)? BrowserRouter : window.DesktopRobosats === 'Desktop-App' ? HashRouter : MemoryRouter; +function getRouter() { + if (window.NativeRobosats === undefined && window.RobosatsClient === undefined) { + return BrowserRouter; + } else if (window.RobosatsClient === 'desktop-app') { + return HashRouter; + } else { + return MemoryRouter; + } +} +const Router = getRouter(); const TestnetTypography = styled(Typography)({ height: 0, diff --git a/frontend/src/basic/RobotPage/RobotProfile.tsx b/frontend/src/basic/RobotPage/RobotProfile.tsx index 4a21bfbb..8c1bbad6 100644 --- a/frontend/src/basic/RobotPage/RobotProfile.tsx +++ b/frontend/src/basic/RobotPage/RobotProfile.tsx @@ -154,7 +154,7 @@ const RobotProfile = ({ )} - {loadingCoordinators > 0 && !Boolean(robot?.activeOrderId) ? ( + {loadingCoordinators > 0 && !robot?.activeOrderId ? ( {t('Looking for orders!')} @@ -208,9 +208,9 @@ const RobotProfile = ({ ) : null} - {!Boolean(robot?.activeOrderId) && + {!robot?.activeOrderId && slot?.hashId && - !Boolean(robot?.lastOrderId) && + !robot?.lastOrderId && loadingCoordinators === 0 ? ( {t('No existing orders found')} ) : null} diff --git a/frontend/src/components/BookTable/index.tsx b/frontend/src/components/BookTable/index.tsx index 2492bf23..1c0d5c54 100644 --- a/frontend/src/components/BookTable/index.tsx +++ b/frontend/src/components/BookTable/index.tsx @@ -24,7 +24,7 @@ import { type GridPaginationModel, type GridColDef, type GridValidRowModel, - GridSlotsComponent, + type GridSlotsComponent, } from '@mui/x-data-grid'; import currencyDict from '../../../static/assets/currencies.json'; import { type PublicOrder } from '../../models'; diff --git a/frontend/src/contexts/AppContext.tsx b/frontend/src/contexts/AppContext.tsx index 991e165c..bd543bf9 100644 --- a/frontend/src/contexts/AppContext.tsx +++ b/frontend/src/contexts/AppContext.tsx @@ -40,7 +40,7 @@ export interface SlideDirection { export type TorStatus = 'ON' | 'STARTING' | 'STOPPING' | 'OFF'; export const isNativeRoboSats = !(window.NativeRobosats === undefined); -export const isDesktopRoboSats = !(window.DesktopRobosats === undefined); +export const isDesktopRoboSats = !(window.RobosatsClient === undefined); const pageFromPath = window.location.pathname.split('/')[1]; const isPagePathEmpty = pageFromPath === ''; @@ -78,15 +78,15 @@ const makeTheme = function (settings: Settings): Theme { const getHostUrl = (network = 'mainnet'): string => { let host = ''; let protocol = ''; - if(window.DesktopRobosats === 'Desktop-App'){ - host = defaultFederation.exp[network]['onion']; + if(isDesktopRoboSats){ + host = defaultFederation.exp[network].onion; protocol = 'http:'; } else if (window.NativeRobosats === undefined) { host = getHost(); protocol = location.protocol; } else { - host = defaultFederation.exp[network]['onion']; + host = defaultFederation.exp[network].onion; protocol = 'http:'; } const hostUrl = `${host}`; diff --git a/frontend/src/models/Garage.model.ts b/frontend/src/models/Garage.model.ts index 47204b91..19659b5e 100644 --- a/frontend/src/models/Garage.model.ts +++ b/frontend/src/models/Garage.model.ts @@ -60,7 +60,7 @@ class Garage { Object.values(rawSlots).forEach((rawSlot: Record) => { if (rawSlot?.token) { this.slots[rawSlot.token] = new Slot(rawSlot.token, Object.keys(rawSlot.robots), {}, () => - this.triggerHook('onRobotUpdate'), + { this.triggerHook('onRobotUpdate'); }, ); Object.keys(rawSlot.robots).forEach((shortAlias) => { @@ -116,7 +116,7 @@ class Garage { if (this.getSlot(token) === null) { this.slots[token] = new Slot(token, shortAliases, attributes, () => - this.triggerHook('onRobotUpdate'), + { this.triggerHook('onRobotUpdate'); }, ); this.save(); } diff --git a/frontend/src/services/Native/index.d.ts b/frontend/src/services/Native/index.d.ts index 721255a3..4d7a17cb 100644 --- a/frontend/src/services/Native/index.d.ts +++ b/frontend/src/services/Native/index.d.ts @@ -5,7 +5,7 @@ declare global { ReactNativeWebView?: ReactNativeWebView; NativeRobosats?: NativeRobosats; RobosatsSettings: 'web-basic' | 'web-pro' | 'selfhosted-basic' | 'selfhosted-pro'; - DesktopRobosats: undefined | 'Desktop-App'; + RobosatsClient: 'desktop-app' | undefined; } } diff --git a/frontend/src/services/Roboidentities/Native.ts b/frontend/src/services/Roboidentities/Native.ts index 250b9a81..1533a585 100644 --- a/frontend/src/services/Roboidentities/Native.ts +++ b/frontend/src/services/Roboidentities/Native.ts @@ -1,4 +1,4 @@ import RoboidentitiesClientNativeClient from './RoboidentitiesNativeClient'; -import { RoboidentitiesClient } from './type'; +import { type RoboidentitiesClient } from './type'; export const roboidentitiesClient: RoboidentitiesClient = new RoboidentitiesClientNativeClient(); diff --git a/frontend/src/services/Roboidentities/RoboidentitiesWebClient/index.ts b/frontend/src/services/Roboidentities/RoboidentitiesWebClient/index.ts index 20e2e137..1bc976e8 100644 --- a/frontend/src/services/Roboidentities/RoboidentitiesWebClient/index.ts +++ b/frontend/src/services/Roboidentities/RoboidentitiesWebClient/index.ts @@ -4,14 +4,14 @@ import { robohash } from './RobohashGenerator'; class RoboidentitiesClientWebClient implements RoboidentitiesClient { public generateRoboname: (initialString: string) => Promise = async (initialString) => { - return new Promise(async (resolve, _reject) => { + return await new Promise(async (resolve, _reject) => { resolve(generate_roboname(initialString)); }); }; public generateRobohash: (initialString: string, size: 'small' | 'large') => Promise = async (initialString, size) => { - return robohash.generate(initialString, size); + return await robohash.generate(initialString, size); }; } diff --git a/frontend/src/services/Roboidentities/Web.ts b/frontend/src/services/Roboidentities/Web.ts index 8730491c..4637326a 100644 --- a/frontend/src/services/Roboidentities/Web.ts +++ b/frontend/src/services/Roboidentities/Web.ts @@ -1,4 +1,4 @@ import RoboidentitiesClientWebClient from './RoboidentitiesWebClient'; -import { RoboidentitiesClient } from './type'; +import { type RoboidentitiesClient } from './type'; export const roboidentitiesClient: RoboidentitiesClient = new RoboidentitiesClientWebClient(); diff --git a/frontend/src/services/System/SystemDesktopClient/index.ts b/frontend/src/services/System/SystemDesktopClient/index.ts index 8b1051c9..75a8251c 100644 --- a/frontend/src/services/System/SystemDesktopClient/index.ts +++ b/frontend/src/services/System/SystemDesktopClient/index.ts @@ -16,8 +16,7 @@ class SystemDesktopClient implements SystemClient { textArea.value = value; // make the textarea out of viewport textArea.style.position = 'fixed'; - textArea.style.left = '-999999px'; - textArea.style.top = '-999999px'; + textArea.style.visibility = 'hidden'; document.body.appendChild(textArea); textArea.focus(); textArea.select(); diff --git a/frontend/src/services/System/index.ts b/frontend/src/services/System/index.ts index 2d3a2349..743f3850 100644 --- a/frontend/src/services/System/index.ts +++ b/frontend/src/services/System/index.ts @@ -13,9 +13,18 @@ export interface SystemClient { deleteItem: (key: string) => void; } -export const systemClient: SystemClient = - // If userAgent has "RoboSats", we assume the app is running inside of the - // react-native-web view of the RoboSats Android app. - window.navigator.userAgent.includes('robosats') - ? new SystemNativeClient() - : window.navigator.userAgent.includes('Electron')? new SystemDesktopClient() : new SystemWebClient(); +function getSystemClient(): SystemClient { + if (window.navigator.userAgent.includes('robosats')) { + // If userAgent has "RoboSats", we assume the app is running inside of the + // react-native-web view of the RoboSats Android app. + return new SystemNativeClient(); + } else if (window.navigator.userAgent.includes('Electron')) { + // If userAgent has "Electron", we assume the app is running inside of an Electron app. + return new SystemDesktopClient(); + } else { + // Otherwise, we assume the app is running in a web browser. + return new SystemWebClient(); + } +} + +export const systemClient: SystemClient = getSystemClient(); diff --git a/frontend/src/services/api/ApiNativeClient/index.ts b/frontend/src/services/api/ApiNativeClient/index.ts index 6f794eec..63c66606 100644 --- a/frontend/src/services/api/ApiNativeClient/index.ts +++ b/frontend/src/services/api/ApiNativeClient/index.ts @@ -2,7 +2,7 @@ import { type ApiClient, type Auth } from '..'; import { systemClient } from '../../System'; class ApiNativeClient implements ApiClient { - private assetsCache: Record = {}; + private readonly assetsCache: Record = {}; private readonly assetsPromises = new Map>(); private readonly getHeaders: (auth?: Auth) => HeadersInit = (auth) => {