mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-18 20:21:35 +00: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>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
window.RobosatsSettings = 'web-basic'
|
window.RobosatsSettings = 'web-basic'
|
||||||
window.DesktopRobosats = 'Desktop-App'
|
window.RobosatsClient = 'desktop-app'
|
||||||
</script>
|
</script>
|
||||||
<script src="./static/frontend/main.js"></script>
|
<script src="./static/frontend/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -6,8 +6,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "node --max-old-space-size=4096 ./node_modules/.bin/webpack --watch --progress --mode development",
|
"dev": "node --max-old-space-size=4096 ./node_modules/.bin/webpack --watch --progress --mode development",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"build": "webpack --config webpack.config.ts --mode development",
|
"build": "webpack --config webpack.config.ts --mode production",
|
||||||
"builds": "react-scripts build",
|
|
||||||
"lint": "eslint src/**/*.{ts,tsx}",
|
"lint": "eslint src/**/*.{ts,tsx}",
|
||||||
"lint:fix": "eslint --fix 'src/**/*.{ts,tsx}'",
|
"lint:fix": "eslint --fix 'src/**/*.{ts,tsx}'",
|
||||||
"format": "prettier --write '**/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc"
|
"format": "prettier --write '**/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc"
|
||||||
|
@ -24,7 +24,7 @@ const App = (): JSX.Element => {
|
|||||||
<GarageContextProvider>
|
<GarageContextProvider>
|
||||||
<FederationContextProvider>
|
<FederationContextProvider>
|
||||||
<CssBaseline />
|
<CssBaseline />
|
||||||
{(window.NativeRobosats === undefined && window.DesktopRobosats === undefined )? <HostAlert /> : <TorConnectionBadge />}
|
{(window.NativeRobosats === undefined && window.RobosatsClient === undefined )? <HostAlert /> : <TorConnectionBadge />}
|
||||||
<Main />
|
<Main />
|
||||||
</FederationContextProvider>
|
</FederationContextProvider>
|
||||||
</GarageContextProvider>
|
</GarageContextProvider>
|
||||||
|
@ -10,7 +10,16 @@ import Notifications from '../components/Notifications';
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { GarageContext, type UseGarageStoreType } from '../contexts/GarageContext';
|
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)({
|
const TestnetTypography = styled(Typography)({
|
||||||
height: 0,
|
height: 0,
|
||||||
|
@ -154,7 +154,7 @@ const RobotProfile = ({
|
|||||||
)}
|
)}
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
{loadingCoordinators > 0 && !Boolean(robot?.activeOrderId) ? (
|
{loadingCoordinators > 0 && !robot?.activeOrderId ? (
|
||||||
<Grid>
|
<Grid>
|
||||||
<b>{t('Looking for orders!')}</b>
|
<b>{t('Looking for orders!')}</b>
|
||||||
<LinearProgress />
|
<LinearProgress />
|
||||||
@ -208,9 +208,9 @@ const RobotProfile = ({
|
|||||||
</Grid>
|
</Grid>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{!Boolean(robot?.activeOrderId) &&
|
{!robot?.activeOrderId &&
|
||||||
slot?.hashId &&
|
slot?.hashId &&
|
||||||
!Boolean(robot?.lastOrderId) &&
|
!robot?.lastOrderId &&
|
||||||
loadingCoordinators === 0 ? (
|
loadingCoordinators === 0 ? (
|
||||||
<Grid item>{t('No existing orders found')}</Grid>
|
<Grid item>{t('No existing orders found')}</Grid>
|
||||||
) : null}
|
) : null}
|
||||||
|
@ -24,7 +24,7 @@ import {
|
|||||||
type GridPaginationModel,
|
type GridPaginationModel,
|
||||||
type GridColDef,
|
type GridColDef,
|
||||||
type GridValidRowModel,
|
type GridValidRowModel,
|
||||||
GridSlotsComponent,
|
type GridSlotsComponent,
|
||||||
} from '@mui/x-data-grid';
|
} from '@mui/x-data-grid';
|
||||||
import currencyDict from '../../../static/assets/currencies.json';
|
import currencyDict from '../../../static/assets/currencies.json';
|
||||||
import { type PublicOrder } from '../../models';
|
import { type PublicOrder } from '../../models';
|
||||||
|
@ -40,7 +40,7 @@ export interface SlideDirection {
|
|||||||
export type TorStatus = 'ON' | 'STARTING' | 'STOPPING' | 'OFF';
|
export type TorStatus = 'ON' | 'STARTING' | 'STOPPING' | 'OFF';
|
||||||
|
|
||||||
export const isNativeRoboSats = !(window.NativeRobosats === undefined);
|
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 pageFromPath = window.location.pathname.split('/')[1];
|
||||||
const isPagePathEmpty = pageFromPath === '';
|
const isPagePathEmpty = pageFromPath === '';
|
||||||
@ -78,15 +78,15 @@ const makeTheme = function (settings: Settings): Theme {
|
|||||||
const getHostUrl = (network = 'mainnet'): string => {
|
const getHostUrl = (network = 'mainnet'): string => {
|
||||||
let host = '';
|
let host = '';
|
||||||
let protocol = '';
|
let protocol = '';
|
||||||
if(window.DesktopRobosats === 'Desktop-App'){
|
if(isDesktopRoboSats){
|
||||||
host = defaultFederation.exp[network]['onion'];
|
host = defaultFederation.exp[network].onion;
|
||||||
protocol = 'http:';
|
protocol = 'http:';
|
||||||
}
|
}
|
||||||
else if (window.NativeRobosats === undefined) {
|
else if (window.NativeRobosats === undefined) {
|
||||||
host = getHost();
|
host = getHost();
|
||||||
protocol = location.protocol;
|
protocol = location.protocol;
|
||||||
} else {
|
} else {
|
||||||
host = defaultFederation.exp[network]['onion'];
|
host = defaultFederation.exp[network].onion;
|
||||||
protocol = 'http:';
|
protocol = 'http:';
|
||||||
}
|
}
|
||||||
const hostUrl = `${host}`;
|
const hostUrl = `${host}`;
|
||||||
|
@ -60,7 +60,7 @@ class Garage {
|
|||||||
Object.values(rawSlots).forEach((rawSlot: Record<any, any>) => {
|
Object.values(rawSlots).forEach((rawSlot: Record<any, any>) => {
|
||||||
if (rawSlot?.token) {
|
if (rawSlot?.token) {
|
||||||
this.slots[rawSlot.token] = new Slot(rawSlot.token, Object.keys(rawSlot.robots), {}, () =>
|
this.slots[rawSlot.token] = new Slot(rawSlot.token, Object.keys(rawSlot.robots), {}, () =>
|
||||||
this.triggerHook('onRobotUpdate'),
|
{ this.triggerHook('onRobotUpdate'); },
|
||||||
);
|
);
|
||||||
|
|
||||||
Object.keys(rawSlot.robots).forEach((shortAlias) => {
|
Object.keys(rawSlot.robots).forEach((shortAlias) => {
|
||||||
@ -116,7 +116,7 @@ class Garage {
|
|||||||
|
|
||||||
if (this.getSlot(token) === null) {
|
if (this.getSlot(token) === null) {
|
||||||
this.slots[token] = new Slot(token, shortAliases, attributes, () =>
|
this.slots[token] = new Slot(token, shortAliases, attributes, () =>
|
||||||
this.triggerHook('onRobotUpdate'),
|
{ this.triggerHook('onRobotUpdate'); },
|
||||||
);
|
);
|
||||||
this.save();
|
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;
|
ReactNativeWebView?: ReactNativeWebView;
|
||||||
NativeRobosats?: NativeRobosats;
|
NativeRobosats?: NativeRobosats;
|
||||||
RobosatsSettings: 'web-basic' | 'web-pro' | 'selfhosted-basic' | 'selfhosted-pro';
|
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 RoboidentitiesClientNativeClient from './RoboidentitiesNativeClient';
|
||||||
import { RoboidentitiesClient } from './type';
|
import { type RoboidentitiesClient } from './type';
|
||||||
|
|
||||||
export const roboidentitiesClient: RoboidentitiesClient = new RoboidentitiesClientNativeClient();
|
export const roboidentitiesClient: RoboidentitiesClient = new RoboidentitiesClientNativeClient();
|
||||||
|
@ -4,14 +4,14 @@ import { robohash } from './RobohashGenerator';
|
|||||||
|
|
||||||
class RoboidentitiesClientWebClient implements RoboidentitiesClient {
|
class RoboidentitiesClientWebClient implements RoboidentitiesClient {
|
||||||
public generateRoboname: (initialString: string) => Promise<string> = async (initialString) => {
|
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));
|
resolve(generate_roboname(initialString));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
public generateRobohash: (initialString: string, size: 'small' | 'large') => Promise<string> =
|
public generateRobohash: (initialString: string, size: 'small' | 'large') => Promise<string> =
|
||||||
async (initialString, size) => {
|
async (initialString, size) => {
|
||||||
return robohash.generate(initialString, size);
|
return await robohash.generate(initialString, size);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import RoboidentitiesClientWebClient from './RoboidentitiesWebClient';
|
import RoboidentitiesClientWebClient from './RoboidentitiesWebClient';
|
||||||
import { RoboidentitiesClient } from './type';
|
import { type RoboidentitiesClient } from './type';
|
||||||
|
|
||||||
export const roboidentitiesClient: RoboidentitiesClient = new RoboidentitiesClientWebClient();
|
export const roboidentitiesClient: RoboidentitiesClient = new RoboidentitiesClientWebClient();
|
||||||
|
@ -16,8 +16,7 @@ class SystemDesktopClient implements SystemClient {
|
|||||||
textArea.value = value;
|
textArea.value = value;
|
||||||
// make the textarea out of viewport
|
// make the textarea out of viewport
|
||||||
textArea.style.position = 'fixed';
|
textArea.style.position = 'fixed';
|
||||||
textArea.style.left = '-999999px';
|
textArea.style.visibility = 'hidden';
|
||||||
textArea.style.top = '-999999px';
|
|
||||||
document.body.appendChild(textArea);
|
document.body.appendChild(textArea);
|
||||||
textArea.focus();
|
textArea.focus();
|
||||||
textArea.select();
|
textArea.select();
|
||||||
|
@ -13,9 +13,18 @@ export interface SystemClient {
|
|||||||
deleteItem: (key: string) => void;
|
deleteItem: (key: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const systemClient: SystemClient =
|
function getSystemClient(): SystemClient {
|
||||||
// If userAgent has "RoboSats", we assume the app is running inside of the
|
if (window.navigator.userAgent.includes('robosats')) {
|
||||||
// react-native-web view of the RoboSats Android app.
|
// If userAgent has "RoboSats", we assume the app is running inside of the
|
||||||
window.navigator.userAgent.includes('robosats')
|
// react-native-web view of the RoboSats Android app.
|
||||||
? new SystemNativeClient()
|
return new SystemNativeClient();
|
||||||
: window.navigator.userAgent.includes('Electron')? new SystemDesktopClient() : new SystemWebClient();
|
} 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';
|
import { systemClient } from '../../System';
|
||||||
|
|
||||||
class ApiNativeClient implements ApiClient {
|
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 assetsPromises = new Map<string, Promise<string | undefined>>();
|
||||||
|
|
||||||
private readonly getHeaders: (auth?: Auth) => HeadersInit = (auth) => {
|
private readonly getHeaders: (auth?: Auth) => HeadersInit = (auth) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user