mirror of
https://github.com/RoboSats/robosats.git
synced 2024-12-28 06:44:40 +03:00
ternaries removed and DesktopRobosats switch it to RobosatsClient === 'desktop-app'
This commit is contained in:
parent
e77edbf100
commit
6843760b87
@ -56,7 +56,7 @@
|
||||
</div>
|
||||
<script>
|
||||
window.RobosatsSettings = 'web-basic'
|
||||
window.DesktopRobosats = 'Desktop-App'
|
||||
window.RobosatsClient = 'desktop-app'
|
||||
</script>
|
||||
<script src="./static/frontend/main.js"></script>
|
||||
</body>
|
||||
|
@ -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"
|
||||
|
@ -24,7 +24,7 @@ const App = (): JSX.Element => {
|
||||
<GarageContextProvider>
|
||||
<FederationContextProvider>
|
||||
<CssBaseline />
|
||||
{(window.NativeRobosats === undefined && window.DesktopRobosats === undefined )? <HostAlert /> : <TorConnectionBadge />}
|
||||
{(window.NativeRobosats === undefined && window.RobosatsClient === undefined )? <HostAlert /> : <TorConnectionBadge />}
|
||||
<Main />
|
||||
</FederationContextProvider>
|
||||
</GarageContextProvider>
|
||||
|
@ -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,
|
||||
|
@ -154,7 +154,7 @@ const RobotProfile = ({
|
||||
)}
|
||||
</Grid>
|
||||
|
||||
{loadingCoordinators > 0 && !Boolean(robot?.activeOrderId) ? (
|
||||
{loadingCoordinators > 0 && !robot?.activeOrderId ? (
|
||||
<Grid>
|
||||
<b>{t('Looking for orders!')}</b>
|
||||
<LinearProgress />
|
||||
@ -208,9 +208,9 @@ const RobotProfile = ({
|
||||
</Grid>
|
||||
) : null}
|
||||
|
||||
{!Boolean(robot?.activeOrderId) &&
|
||||
{!robot?.activeOrderId &&
|
||||
slot?.hashId &&
|
||||
!Boolean(robot?.lastOrderId) &&
|
||||
!robot?.lastOrderId &&
|
||||
loadingCoordinators === 0 ? (
|
||||
<Grid item>{t('No existing orders found')}</Grid>
|
||||
) : null}
|
||||
|
@ -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';
|
||||
|
@ -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}`;
|
||||
|
@ -60,7 +60,7 @@ class Garage {
|
||||
Object.values(rawSlots).forEach((rawSlot: Record<any, any>) => {
|
||||
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();
|
||||
}
|
||||
|
2
frontend/src/services/Native/index.d.ts
vendored
2
frontend/src/services/Native/index.d.ts
vendored
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import RoboidentitiesClientNativeClient from './RoboidentitiesNativeClient';
|
||||
import { RoboidentitiesClient } from './type';
|
||||
import { type RoboidentitiesClient } from './type';
|
||||
|
||||
export const roboidentitiesClient: RoboidentitiesClient = new RoboidentitiesClientNativeClient();
|
||||
|
@ -4,14 +4,14 @@ import { robohash } from './RobohashGenerator';
|
||||
|
||||
class RoboidentitiesClientWebClient implements RoboidentitiesClient {
|
||||
public generateRoboname: (initialString: string) => Promise<string> = async (initialString) => {
|
||||
return new Promise<string>(async (resolve, _reject) => {
|
||||
return await new Promise<string>(async (resolve, _reject) => {
|
||||
resolve(generate_roboname(initialString));
|
||||
});
|
||||
};
|
||||
|
||||
public generateRobohash: (initialString: string, size: 'small' | 'large') => Promise<string> =
|
||||
async (initialString, size) => {
|
||||
return robohash.generate(initialString, size);
|
||||
return await robohash.generate(initialString, size);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import RoboidentitiesClientWebClient from './RoboidentitiesWebClient';
|
||||
import { RoboidentitiesClient } from './type';
|
||||
import { type RoboidentitiesClient } from './type';
|
||||
|
||||
export const roboidentitiesClient: RoboidentitiesClient = new RoboidentitiesClientWebClient();
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -2,7 +2,7 @@ import { type ApiClient, type Auth } from '..';
|
||||
import { systemClient } from '../../System';
|
||||
|
||||
class ApiNativeClient implements ApiClient {
|
||||
private assetsCache: Record<string, string> = {};
|
||||
private readonly assetsCache: Record<string, string> = {};
|
||||
private readonly assetsPromises = new Map<string, Promise<string | undefined>>();
|
||||
|
||||
private readonly getHeaders: (auth?: Auth) => HeadersInit = (auth) => {
|
||||
|
Loading…
Reference in New Issue
Block a user