diff --git a/src-gui/src/renderer/components/pages/help/HelpPage.tsx b/src-gui/src/renderer/components/pages/help/HelpPage.tsx index 9299d7196..9d2a175b2 100644 --- a/src-gui/src/renderer/components/pages/help/HelpPage.tsx +++ b/src-gui/src/renderer/components/pages/help/HelpPage.tsx @@ -18,7 +18,7 @@ const useStyles = makeStyles((theme) => ({ export default function HelpPage() { const classes = useStyles(); - const location = useLocation(); + const location = useLocation(); useEffect(() => { if (location.hash) { diff --git a/src-gui/src/renderer/components/pages/help/SettingsBox.tsx b/src-gui/src/renderer/components/pages/help/SettingsBox.tsx index 77f846532..530713666 100644 --- a/src-gui/src/renderer/components/pages/help/SettingsBox.tsx +++ b/src-gui/src/renderer/components/pages/help/SettingsBox.tsx @@ -44,6 +44,8 @@ import { Theme } from "renderer/components/theme"; import { Add, ArrowUpward, Delete, Edit, HourglassEmpty } from "@material-ui/icons"; import { getNetwork } from "store/config"; import { currencySymbol } from "utils/formatUtils"; +import { setTorEnabled } from "store/features/settingsSlice"; + const PLACEHOLDER_ELECTRUM_RPC_URL = "ssl://blockstream.info:700"; const PLACEHOLDER_MONERO_NODE_URL = "http://xmr-node.cakewallet.com:18081"; @@ -82,6 +84,7 @@ export default function SettingsBox() { + @@ -489,4 +492,23 @@ function NodeTable({
) -} \ No newline at end of file +} + +export function TorSettings() { + const dispatch = useAppDispatch(); + const torEnabled = useSettings((settings) => settings.enableTor) + const handleChange = (event: React.ChangeEvent) => dispatch(setTorEnabled(event.target.checked)); + const status = (state: boolean) => state === true ? "enabled" : "disabled"; + + return ( + + + + + + + + + + ) +} diff --git a/src-gui/src/renderer/components/pages/help/TorInfoBox.tsx b/src-gui/src/renderer/components/pages/help/TorInfoBox.tsx deleted file mode 100644 index 9f6bb09ec..000000000 --- a/src-gui/src/renderer/components/pages/help/TorInfoBox.tsx +++ /dev/null @@ -1,71 +0,0 @@ -import { Box, makeStyles, Typography } from "@material-ui/core"; -import PlayArrowIcon from "@material-ui/icons/PlayArrow"; -import StopIcon from "@material-ui/icons/Stop"; -import PromiseInvokeButton from "renderer/components/PromiseInvokeButton"; -import { useAppSelector } from "store/hooks"; -import InfoBox from "../../modal/swap/InfoBox"; -import CliLogsBox from "../../other/RenderedCliLog"; - -const useStyles = makeStyles((theme) => ({ - actionsOuter: { - display: "flex", - gap: theme.spacing(1), - }, -})); - -export default function TorInfoBox() { - const isTorRunning = useAppSelector((state) => state.tor.processRunning); - const torStdOut = useAppSelector((s) => s.tor.stdOut); - const classes = useStyles(); - - return ( - - - Tor is a network that allows you to anonymously connect to the - internet. It is a free and open network that is operated by - volunteers. You can start and stop Tor by clicking the buttons - below. If Tor is running, all traffic will be routed through it and - the maker will not be able to see your IP address. - - - - } - additionalContent={ - - } - onInvoke={() => { - throw new Error("Not implemented"); - }} - > - Start Tor - - } - onInvoke={() => { - throw new Error("Not implemented"); - }} - > - Stop Tor - - - } - icon={null} - loading={false} - /> - ); -} diff --git a/src-gui/src/renderer/rpc.ts b/src-gui/src/renderer/rpc.ts index 63204e832..109079c93 100644 --- a/src-gui/src/renderer/rpc.ts +++ b/src-gui/src/renderer/rpc.ts @@ -175,6 +175,7 @@ export async function listSellersAtRendezvousPoint( export async function initializeContext() { const network = getNetwork(); const testnet = isTestnet(); + const useTor = store.getState().settings.enableTor; // This looks convoluted but it does the following: // - Fetch the status of all nodes for each blockchain in parallel @@ -208,6 +209,7 @@ export async function initializeContext() { const tauriSettings: TauriSettings = { electrum_rpc_url: bitcoinNode, monero_node_url: moneroNode, + use_tor: useTor }; logger.info("Initializing context with settings", tauriSettings); diff --git a/src-gui/src/store/features/settingsSlice.ts b/src-gui/src/store/features/settingsSlice.ts index 76aa63984..8b23c5da6 100644 --- a/src-gui/src/store/features/settingsSlice.ts +++ b/src-gui/src/store/features/settingsSlice.ts @@ -9,6 +9,8 @@ export interface SettingsState { /// Whether to fetch fiat prices from the internet fetchFiatPrices: boolean; fiatCurrency: FiatCurrency; + /// Whether to enable Tor for p2p connections + enableTor: boolean } export enum FiatCurrency { @@ -98,6 +100,7 @@ const initialState: SettingsState = { theme: Theme.Darker, fetchFiatPrices: true, fiatCurrency: FiatCurrency.Usd, + enableTor: true }; const alertsSlice = createSlice({ @@ -134,6 +137,9 @@ const alertsSlice = createSlice({ }, resetSettings(_) { return initialState; + }, + setTorEnabled(slice, action: PayloadAction) { + slice.enableTor = action.payload; } }, }); @@ -146,6 +152,7 @@ export const { resetSettings, setFetchFiatPrices, setFiatCurrency, + setTorEnabled, } = alertsSlice.actions; export default alertsSlice.reducer; diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index bf2c62992..b82734fde 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -18,7 +18,6 @@ use swap::cli::{ command::{Bitcoin, Monero}, }; use tauri::{async_runtime::RwLock, Manager, RunEvent}; -use uuid::Uuid; /// Trait to convert Result to Result /// Tauri commands require the error type to be a string @@ -327,7 +326,7 @@ async fn initialize_context( }) .with_json(false) .with_debug(true) - .with_tor(true) + .with_tor(settings.use_tor) .with_tauri(tauri_handle.clone()) .build() .await; diff --git a/swap/src/cli/api.rs b/swap/src/cli/api.rs index b9226a678..5b364b39f 100644 --- a/swap/src/cli/api.rs +++ b/swap/src/cli/api.rs @@ -394,6 +394,12 @@ impl ContextBuilder { }; let initialize_tor_client = async { + // Don't init a tor client unless we should use it. + if !self.tor { + tracing::warn!("Internal Tor client not enabled, skipping initialization"); + return Ok(None); + } + self.tauri_handle.emit_context_init_progress_event( TauriContextStatusEvent::Initializing(vec![ TauriPartialInitProgress::EstablishingTorCircuits( diff --git a/swap/src/cli/api/tauri_bindings.rs b/swap/src/cli/api/tauri_bindings.rs index a36c78abe..fe3131310 100644 --- a/swap/src/cli/api/tauri_bindings.rs +++ b/swap/src/cli/api/tauri_bindings.rs @@ -133,7 +133,7 @@ impl TauriHandle { let request_id = Uuid::new_v4(); let now_secs = SystemTime::now() .duration_since(UNIX_EPOCH) - .unwrap() + .expect("it is later than the begin of the unix epoch") .as_secs(); let expiration_ts = now_secs + timeout_secs; @@ -501,4 +501,6 @@ pub struct TauriSettings { /// The URL of the Electrum RPC server e.g `ssl://bitcoin.com:50001` #[typeshare(serialized_as = "string")] pub electrum_rpc_url: Option, + /// Whether to initialize and use a tor client. + pub use_tor: bool, } diff --git a/swap/src/protocol/bob/swap.rs b/swap/src/protocol/bob/swap.rs index 297f8d061..d262533b5 100644 --- a/swap/src/protocol/bob/swap.rs +++ b/swap/src/protocol/bob/swap.rs @@ -164,7 +164,7 @@ async fn next_state( let btc_lock_amount = bitcoin::Amount::from_sat( signed_tx .output - .get(0) + .first() .context("Failed to get lock amount")? .value, );