mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-18 12:11:35 +00:00
Disable tor option (#1315)
* Disable Tor option * Fix settings save * Remove unused code * Remove unused code 2
This commit is contained in:
parent
bf6e994792
commit
74143c8da1
@ -44,7 +44,7 @@ const RobotPage = (): JSX.Element => {
|
||||
const token = urlToken ?? garage.currentSlot;
|
||||
if (token !== undefined && token !== null && page === 'robot') {
|
||||
setInputToken(token);
|
||||
if (window.NativeRobosats === undefined || torStatus === 'ON') {
|
||||
if (window.NativeRobosats === undefined || torStatus === 'ON' || !settings.useProxy) {
|
||||
getGenerateRobot(token);
|
||||
setView('profile');
|
||||
}
|
||||
@ -83,7 +83,7 @@ const RobotPage = (): JSX.Element => {
|
||||
garage.deleteSlot();
|
||||
};
|
||||
|
||||
if (!(window.NativeRobosats === undefined) && !(torStatus === 'ON')) {
|
||||
if (settings.useProxy && !(window.NativeRobosats === undefined) && !(torStatus === 'ON')) {
|
||||
return (
|
||||
<Paper
|
||||
elevation={12}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import useAutocomplete from '@mui/base/useAutocomplete';
|
||||
import { useAutocomplete } from '@mui/base/useAutocomplete';
|
||||
import { styled } from '@mui/material/styles';
|
||||
import {
|
||||
Button,
|
||||
|
@ -90,12 +90,6 @@ const MakerForm = ({
|
||||
const minRangeAmountMultiple = 1.6;
|
||||
const amountSafeThresholds = [1.03, 0.98];
|
||||
|
||||
useEffect(() => {
|
||||
// Why?
|
||||
// const slot = garage.getSlot();
|
||||
// if (slot?.token) void federation.fetchRobot(garage, slot?.token);
|
||||
}, [garage.currentSlot]);
|
||||
|
||||
useEffect(() => {
|
||||
setCurrencyCode(currencyDict[fav.currency === 0 ? 1 : fav.currency]);
|
||||
}, [coordinatorUpdatedAt]);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import React, { useContext } from 'react';
|
||||
import React, { useContext, useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { type UseAppStoreType, AppContext } from '../../contexts/AppContext';
|
||||
import {
|
||||
@ -28,17 +28,19 @@ import {
|
||||
QrCode,
|
||||
} from '@mui/icons-material';
|
||||
import { systemClient } from '../../services/System';
|
||||
import { TorIcon } from '../Icons';
|
||||
import SwapCalls from '@mui/icons-material/SwapCalls';
|
||||
import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext';
|
||||
import { GarageContext, UseGarageStoreType } from '../../contexts/GarageContext';
|
||||
|
||||
interface SettingsFormProps {
|
||||
dense?: boolean;
|
||||
}
|
||||
|
||||
const SettingsForm = ({ dense = false }: SettingsFormProps): JSX.Element => {
|
||||
const { fav, setFav, origin, hostUrl, settings, setSettings } =
|
||||
useContext<UseAppStoreType>(AppContext);
|
||||
const { fav, setFav, settings, setSettings } = useContext<UseAppStoreType>(AppContext);
|
||||
const { federation } = useContext<UseFederationStoreType>(FederationContext);
|
||||
const { garage } = useContext<UseGarageStoreType>(GarageContext);
|
||||
const theme = useTheme();
|
||||
const { t } = useTranslation();
|
||||
const fontSizes = [
|
||||
@ -237,6 +239,29 @@ const SettingsForm = ({ dense = false }: SettingsFormProps): JSX.Element => {
|
||||
</ToggleButton>
|
||||
</ToggleButtonGroup>
|
||||
</ListItem>
|
||||
|
||||
{window.NativeRobosats !== undefined && (
|
||||
<ListItem>
|
||||
<ListItemIcon>
|
||||
<TorIcon />
|
||||
</ListItemIcon>
|
||||
<ToggleButtonGroup
|
||||
exclusive={true}
|
||||
value={settings.useProxy}
|
||||
onChange={(_e, useProxy) => {
|
||||
setSettings({ ...settings, useProxy });
|
||||
systemClient.setItem('settings_use_proxy', String(useProxy));
|
||||
}}
|
||||
>
|
||||
<ToggleButton value={true} color='primary'>
|
||||
{t('Build-in')}
|
||||
</ToggleButton>
|
||||
<ToggleButton value={false} color='secondary'>
|
||||
{t('Disabled')}
|
||||
</ToggleButton>
|
||||
</ToggleButtonGroup>
|
||||
</ListItem>
|
||||
)}
|
||||
</List>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
@ -55,10 +55,10 @@ const TorIndicator = ({
|
||||
};
|
||||
|
||||
const TorConnectionBadge = (): JSX.Element => {
|
||||
const { torStatus } = useContext<UseAppStoreType>(AppContext);
|
||||
const { torStatus, settings } = useContext<UseAppStoreType>(AppContext);
|
||||
const { t } = useTranslation();
|
||||
|
||||
if (window?.NativeRobosats == null) {
|
||||
if (window?.NativeRobosats == null || !settings.useProxy) {
|
||||
return <></>;
|
||||
}
|
||||
|
||||
|
@ -111,12 +111,14 @@ export const FederationContextProvider = ({
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
// On bitcoin network change we reset book, limits and federation info and fetch everything again
|
||||
if (window.NativeRobosats === undefined || torStatus === 'ON') {
|
||||
if (window.NativeRobosats === undefined || torStatus === 'ON' || !settings.useProxy) {
|
||||
void federation.updateUrl(origin, settings, hostUrl);
|
||||
void federation.update();
|
||||
|
||||
const token = garage.getSlot()?.getRobot()?.token;
|
||||
if (token) void federation.fetchRobot(garage, token);
|
||||
}
|
||||
}, [settings.network, torStatus]);
|
||||
}, [settings.network, settings.useProxy, torStatus]);
|
||||
|
||||
const onOrderReceived = (order: Order): void => {
|
||||
let newDelay = defaultDelay;
|
||||
@ -178,15 +180,6 @@ 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 && 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();
|
||||
|
@ -145,7 +145,7 @@ export class Coordinator {
|
||||
public loadingInfo: boolean = false;
|
||||
public limits: LimitList = {};
|
||||
public loadingLimits: boolean = false;
|
||||
public loadingRobot: boolean = true;
|
||||
public loadingRobot: string | null;
|
||||
|
||||
updateUrl = (origin: Origin, settings: Settings, hostUrl: string): void => {
|
||||
if (settings.selfhostedClient && this.shortAlias !== 'local') {
|
||||
@ -185,6 +185,7 @@ export class Coordinator {
|
||||
if (this.loadingBook) return;
|
||||
|
||||
this.loadingBook = true;
|
||||
this.book = [];
|
||||
|
||||
apiClient
|
||||
.get(this.url, `${this.basePath}/api/book/`)
|
||||
@ -297,7 +298,7 @@ export class Coordinator {
|
||||
};
|
||||
|
||||
fetchRobot = async (garage: Garage, token: string): Promise<Robot | null> => {
|
||||
if (!this.enabled || !token) return null;
|
||||
if (!this.enabled || !token || this.loadingRobot === token) return null;
|
||||
|
||||
const robot = garage?.getSlot(token)?.getRobot() ?? null;
|
||||
const authHeaders = robot?.getAuthHeaders();
|
||||
@ -308,6 +309,8 @@ export class Coordinator {
|
||||
|
||||
if (!hasEnoughEntropy) return null;
|
||||
|
||||
this.loadingRobot = token;
|
||||
|
||||
garage.updateRobot(token, this.shortAlias, { loading: true });
|
||||
|
||||
const newAttributes = await apiClient
|
||||
@ -330,7 +333,8 @@ export class Coordinator {
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e);
|
||||
});
|
||||
})
|
||||
.finally(() => (this.loadingRobot = null));
|
||||
|
||||
garage.updateRobot(token, this.shortAlias, {
|
||||
...newAttributes,
|
||||
|
@ -100,7 +100,7 @@ export class Federation {
|
||||
this.exchange.loadingCoordinators = Object.keys(this.coordinators).length;
|
||||
this.updateEnabledCoordinators();
|
||||
for (const coor of Object.values(this.coordinators)) {
|
||||
await coor.update(() => {
|
||||
coor.update(() => {
|
||||
this.exchange.onlineCoordinators = this.exchange.onlineCoordinators + 1;
|
||||
this.onCoordinatorSaved();
|
||||
});
|
||||
@ -109,10 +109,11 @@ export class Federation {
|
||||
|
||||
updateBook = async (): Promise<void> => {
|
||||
this.loading = true;
|
||||
this.book = [];
|
||||
this.triggerHook('onCoordinatorUpdate');
|
||||
this.exchange.loadingCoordinators = Object.keys(this.coordinators).length;
|
||||
for (const coor of Object.values(this.coordinators)) {
|
||||
await coor.updateBook(() => {
|
||||
coor.updateBook(() => {
|
||||
this.onCoordinatorSaved();
|
||||
});
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import i18n from '../i18n/Web';
|
||||
import { systemClient } from '../services/System';
|
||||
import { apiClient } from '../services/api';
|
||||
import { getHost } from '../utils';
|
||||
|
||||
export type Language =
|
||||
@ -42,8 +43,13 @@ class BaseSettings {
|
||||
: i18n.resolvedLanguage.substring(0, 2);
|
||||
|
||||
const networkCookie = systemClient.getItem('settings_network');
|
||||
this.network = networkCookie !== '' ? networkCookie : 'mainnet';
|
||||
this.network = networkCookie && networkCookie !== '' ? networkCookie : 'mainnet';
|
||||
this.host = getHost();
|
||||
|
||||
const useProxy = systemClient.getItem('settings_use_proxy');
|
||||
this.useProxy = window.NativeRobosats !== undefined && useProxy !== 'false';
|
||||
|
||||
apiClient.useProxy = this.useProxy;
|
||||
}
|
||||
|
||||
public frontend: 'basic' | 'pro' = 'basic';
|
||||
@ -56,6 +62,7 @@ class BaseSettings {
|
||||
public host?: string;
|
||||
public unsafeClient: boolean = false;
|
||||
public selfhostedClient: boolean = false;
|
||||
public useProxy: boolean;
|
||||
}
|
||||
|
||||
export default BaseSettings;
|
||||
|
@ -28,7 +28,7 @@ class SystemNativeClient implements SystemClient {
|
||||
};
|
||||
|
||||
public setCookie: (key: string, value: string) => void = (key, value) => {
|
||||
delete window.NativeRobosats?.cookies[key];
|
||||
window.NativeRobosats?.loadCookie({ key, value });
|
||||
void window.NativeRobosats?.postMessage({
|
||||
category: 'system',
|
||||
type: 'setCookie',
|
||||
|
@ -1,8 +1,12 @@
|
||||
import { type ApiClient, type Auth } from '..';
|
||||
import { systemClient } from '../../System';
|
||||
import ApiWebClient from '../ApiWebClient';
|
||||
|
||||
class ApiNativeClient implements ApiClient {
|
||||
private assetsCache: Record<string, string> = {};
|
||||
public useProxy = true;
|
||||
|
||||
private webClient: ApiClient = new ApiWebClient();
|
||||
|
||||
private readonly assetsPromises = new Map<string, Promise<string | undefined>>();
|
||||
|
||||
private readonly getHeaders: (auth?: Auth) => HeadersInit = (auth) => {
|
||||
@ -51,6 +55,7 @@ class ApiNativeClient implements ApiClient {
|
||||
|
||||
public delete: (baseUrl: string, path: string, auth?: Auth) => Promise<object | undefined> =
|
||||
async (baseUrl, path, auth) => {
|
||||
if (!this.proxy) this.webClient.delete(baseUrl, path, auth);
|
||||
return await window.NativeRobosats?.postMessage({
|
||||
category: 'http',
|
||||
type: 'delete',
|
||||
@ -66,6 +71,7 @@ class ApiNativeClient implements ApiClient {
|
||||
body: object,
|
||||
auth?: Auth,
|
||||
) => Promise<object | undefined> = async (baseUrl, path, body, auth) => {
|
||||
if (!this.proxy) this.webClient.post(baseUrl, path, body, auth);
|
||||
return await window.NativeRobosats?.postMessage({
|
||||
category: 'http',
|
||||
type: 'post',
|
||||
@ -81,6 +87,7 @@ class ApiNativeClient implements ApiClient {
|
||||
path,
|
||||
auth,
|
||||
) => {
|
||||
if (!this.proxy) this.webClient.get(baseUrl, path, auth);
|
||||
return await window.NativeRobosats?.postMessage({
|
||||
category: 'http',
|
||||
type: 'get',
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { type ApiClient, type Auth } from '..';
|
||||
|
||||
class ApiWebClient implements ApiClient {
|
||||
public useProxy = false;
|
||||
|
||||
private readonly getHeaders: (auth?: Auth) => HeadersInit = (auth) => {
|
||||
let headers = {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -7,6 +7,7 @@ export interface Auth {
|
||||
}
|
||||
|
||||
export interface ApiClient {
|
||||
useProxy: boolean;
|
||||
post: (baseUrl: string, path: string, body: object, auth?: Auth) => Promise<object | undefined>;
|
||||
put: (baseUrl: string, path: string, body: object, auth?: Auth) => Promise<object | undefined>;
|
||||
get: (baseUrl: string, path: string, auth?: Auth) => Promise<object | undefined>;
|
||||
|
@ -45,7 +45,6 @@ export default function federationLottery(federation: Federation): string[] {
|
||||
// federation[shortAlias] = { badges:{ donatesToDevFund }};
|
||||
// }
|
||||
|
||||
// console.log(federation)
|
||||
// return federation;
|
||||
// }
|
||||
|
||||
@ -58,5 +57,4 @@ export default function federationLottery(federation: Federation): string[] {
|
||||
// results.push(rankedCoordinators);
|
||||
// }
|
||||
|
||||
// console.log(results)
|
||||
// }
|
||||
|
@ -489,7 +489,9 @@
|
||||
"Your last order #{{orderID}}": "La teva última ordre #{{orderID}}",
|
||||
"finished order": "finished order",
|
||||
"#43": "Phrases in components/SettingsForm/index.tsx",
|
||||
"Build-in": "Build-in",
|
||||
"Dark": "Fosc",
|
||||
"Disabled": "Disabled",
|
||||
"Fiat": "Fiat",
|
||||
"Light": "Clar",
|
||||
"Mainnet": "Mainnet",
|
||||
|
@ -489,7 +489,9 @@
|
||||
"Your last order #{{orderID}}": "Tvá poslední nabídka #{{orderID}}",
|
||||
"finished order": "finished order",
|
||||
"#43": "Phrases in components/SettingsForm/index.tsx",
|
||||
"Build-in": "Build-in",
|
||||
"Dark": "Dark",
|
||||
"Disabled": "Disabled",
|
||||
"Fiat": "Fiat",
|
||||
"Light": "Light",
|
||||
"Mainnet": "Mainnet",
|
||||
|
@ -489,7 +489,9 @@
|
||||
"Your last order #{{orderID}}": "Deine letzte Order #{{orderID}}",
|
||||
"finished order": "finished order",
|
||||
"#43": "Phrases in components/SettingsForm/index.tsx",
|
||||
"Build-in": "Build-in",
|
||||
"Dark": "Dark",
|
||||
"Disabled": "Disabled",
|
||||
"Fiat": "Fiat",
|
||||
"Light": "Light",
|
||||
"Mainnet": "Mainnet",
|
||||
|
@ -489,7 +489,9 @@
|
||||
"Your last order #{{orderID}}": "Your last order #{{orderID}}",
|
||||
"finished order": "finished order",
|
||||
"#43": "Phrases in components/SettingsForm/index.tsx",
|
||||
"Build-in": "Build-in",
|
||||
"Dark": "Dark",
|
||||
"Disabled": "Disabled",
|
||||
"Fiat": "Fiat",
|
||||
"Light": "Light",
|
||||
"Mainnet": "Mainnet",
|
||||
|
@ -489,7 +489,9 @@
|
||||
"Your last order #{{orderID}}": "Tu última orden #{{orderID}}",
|
||||
"finished order": "finished order",
|
||||
"#43": "Phrases in components/SettingsForm/index.tsx",
|
||||
"Build-in": "Build-in",
|
||||
"Dark": "Oscuro",
|
||||
"Disabled": "Disabled",
|
||||
"Fiat": "Fiat",
|
||||
"Light": "Claro",
|
||||
"Mainnet": "Mainnet",
|
||||
|
@ -489,7 +489,9 @@
|
||||
"Your last order #{{orderID}}": "Zure azken eskaera #{{orderID}}",
|
||||
"finished order": "finished order",
|
||||
"#43": "Phrases in components/SettingsForm/index.tsx",
|
||||
"Build-in": "Build-in",
|
||||
"Dark": "Dark",
|
||||
"Disabled": "Disabled",
|
||||
"Fiat": "Fiat",
|
||||
"Light": "Light",
|
||||
"Mainnet": "Mainnet",
|
||||
|
@ -489,7 +489,9 @@
|
||||
"Your last order #{{orderID}}": "Votre dernière commande #{{orderID}}",
|
||||
"finished order": "finished order",
|
||||
"#43": "Phrases in components/SettingsForm/index.tsx",
|
||||
"Build-in": "Build-in",
|
||||
"Dark": "Sombre",
|
||||
"Disabled": "Disabled",
|
||||
"Fiat": "Fiat",
|
||||
"Light": "Light",
|
||||
"Mainnet": "Mainnet",
|
||||
|
@ -489,7 +489,9 @@
|
||||
"Your last order #{{orderID}}": "Il tuo ultimo ordine #{{orderID}}",
|
||||
"finished order": "finished order",
|
||||
"#43": "Phrases in components/SettingsForm/index.tsx",
|
||||
"Build-in": "Build-in",
|
||||
"Dark": "Scuro",
|
||||
"Disabled": "Disabled",
|
||||
"Fiat": "Fiat",
|
||||
"Light": "Chiaro",
|
||||
"Mainnet": "Mainnet",
|
||||
|
@ -489,7 +489,9 @@
|
||||
"Your last order #{{orderID}}": "前回のオーダー #{{orderID}}",
|
||||
"finished order": "finished order",
|
||||
"#43": "Phrases in components/SettingsForm/index.tsx",
|
||||
"Build-in": "Build-in",
|
||||
"Dark": "ダーク",
|
||||
"Disabled": "Disabled",
|
||||
"Fiat": "フィアット",
|
||||
"Light": "ライト",
|
||||
"Mainnet": "メインネット",
|
||||
|
@ -489,7 +489,9 @@
|
||||
"Your last order #{{orderID}}": "Your last order #{{orderID}}",
|
||||
"finished order": "finished order",
|
||||
"#43": "Phrases in components/SettingsForm/index.tsx",
|
||||
"Build-in": "Build-in",
|
||||
"Dark": "Dark",
|
||||
"Disabled": "Disabled",
|
||||
"Fiat": "Fiat",
|
||||
"Light": "Light",
|
||||
"Mainnet": "Mainnet",
|
||||
|
@ -489,7 +489,9 @@
|
||||
"Your last order #{{orderID}}": "Sua última ordem #{{orderID}}",
|
||||
"finished order": "ordem finalizada",
|
||||
"#43": "Phrases in components/SettingsForm/index.tsx",
|
||||
"Build-in": "Build-in",
|
||||
"Dark": "Dark",
|
||||
"Disabled": "Disabled",
|
||||
"Fiat": "Fiat",
|
||||
"Light": "Light",
|
||||
"Mainnet": "Mainnet",
|
||||
|
@ -489,7 +489,9 @@
|
||||
"Your last order #{{orderID}}": "Ваш последний ордер #{{orderID}}",
|
||||
"finished order": "finished order",
|
||||
"#43": "Phrases in components/SettingsForm/index.tsx",
|
||||
"Build-in": "Build-in",
|
||||
"Dark": "Темный",
|
||||
"Disabled": "Disabled",
|
||||
"Fiat": "Фиат",
|
||||
"Light": "Светлый",
|
||||
"Mainnet": "Основная сеть",
|
||||
|
@ -489,7 +489,9 @@
|
||||
"Your last order #{{orderID}}": "Din senaste order #{{orderID}}",
|
||||
"finished order": "finished order",
|
||||
"#43": "Phrases in components/SettingsForm/index.tsx",
|
||||
"Build-in": "Build-in",
|
||||
"Dark": "Dark",
|
||||
"Disabled": "Disabled",
|
||||
"Fiat": "Fiat",
|
||||
"Light": "Light",
|
||||
"Mainnet": "Mainnet",
|
||||
|
@ -489,7 +489,9 @@
|
||||
"Your last order #{{orderID}}": "Amri yako ya mwisho #{{orderID}}",
|
||||
"finished order": "finished order",
|
||||
"#43": "Phrases in components/SettingsForm/index.tsx",
|
||||
"Build-in": "Build-in",
|
||||
"Dark": "Giza",
|
||||
"Disabled": "Disabled",
|
||||
"Fiat": "Fiat",
|
||||
"Light": "Nuru",
|
||||
"Mainnet": "Mainnet",
|
||||
|
@ -489,7 +489,9 @@
|
||||
"Your last order #{{orderID}}": "รายการล่าสุดของคุณ #{{orderID}}",
|
||||
"finished order": "finished order",
|
||||
"#43": "Phrases in components/SettingsForm/index.tsx",
|
||||
"Build-in": "Build-in",
|
||||
"Dark": "Dark",
|
||||
"Disabled": "Disabled",
|
||||
"Fiat": "Fiat",
|
||||
"Light": "Light",
|
||||
"Mainnet": "Mainnet",
|
||||
|
@ -489,7 +489,9 @@
|
||||
"Your last order #{{orderID}}": "你的上一笔交易 #{{orderID}}",
|
||||
"finished order": "finished order",
|
||||
"#43": "Phrases in components/SettingsForm/index.tsx",
|
||||
"Build-in": "Build-in",
|
||||
"Dark": "深色",
|
||||
"Disabled": "Disabled",
|
||||
"Fiat": "法币",
|
||||
"Light": "浅色",
|
||||
"Mainnet": "主网",
|
||||
|
@ -489,7 +489,9 @@
|
||||
"Your last order #{{orderID}}": "你的上一筆交易 #{{orderID}}",
|
||||
"finished order": "finished order",
|
||||
"#43": "Phrases in components/SettingsForm/index.tsx",
|
||||
"Build-in": "Build-in",
|
||||
"Dark": "深色",
|
||||
"Disabled": "Disabled",
|
||||
"Fiat": "法幣",
|
||||
"Light": "淺色",
|
||||
"Mainnet": "主網",
|
||||
|
@ -71,6 +71,7 @@ const App = () => {
|
||||
loadCookie('settings_mode');
|
||||
loadCookie('settings_light_qr');
|
||||
loadCookie('settings_network');
|
||||
loadCookie('settings_use_proxy');
|
||||
loadCookie('garage_slots').then(() => injectMessageResolve(responseId));
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user