feat(gui, tauri): Accept --testnet flag, default to mainnet (#106)

This PR tackles #92 

- Add the `tauri-plugin-cli` (only on desktop)
- Check in the frontend if the `--testnet` flag is set. If it's set we pass `testnet=true` to the `initialize_context` command on invokation
- We add the `vite-plugin-top-level-await` to allow top level await in all browsers
- Remove the `bitcoin_confirmation_target` from settings for simplicity
This commit is contained in:
binarybaron 2024-10-10 18:51:56 +06:00 committed by GitHub
parent 9e94dca7aa
commit 83f831ccac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 311 additions and 53 deletions

View file

@ -10,7 +10,6 @@ import {
Select,
TextField,
} from "@material-ui/core";
import { CliLog } from "models/cliModel";
import { useSnackbar } from "notistack";
import { useState } from "react";
import TruncatedText from "renderer/components/other/TruncatedText";
@ -20,21 +19,22 @@ import { parseDateString } from "utils/parseUtils";
import { submitFeedbackViaHttp } from "../../../api";
import LoadingButton from "../../other/LoadingButton";
import { PiconeroAmount } from "../../other/Units";
import { getLogsOfSwap } from "renderer/rpc";
async function submitFeedback(body: string, swapId: string | number) {
let attachedBody = "";
if (swapId !== 0 && typeof swapId === "string") {
const swapInfo = store.getState().rpc.state.swapInfos[swapId];
const logs = [] as CliLog[];
throw new Error("Not implemented");
if (swapInfo === undefined) {
throw new Error(`Swap with id ${swapId} not found`);
}
attachedBody = `${JSON.stringify(swapInfo, null, 4)} \n\nLogs: ${logs
// Retrieve logs for the specific swap
const logs = await getLogsOfSwap(swapId, false);
attachedBody = `${JSON.stringify(swapInfo, null, 4)} \n\nLogs: ${logs.logs
.map((l) => JSON.stringify(l))
.join("\n====\n")}`;
}

View file

@ -31,11 +31,12 @@ export default function SwapDialog({
onClose: () => void;
}) {
const classes = useStyles();
const swap = useAppSelector((state) => state.swap);
const isSwapRunning = useIsSwapRunning();
const [debug, setDebug] = useState(false);
const [openSuspendAlert, setOpenSuspendAlert] = useState(false);
const dispatch = useAppDispatch();
function onCancel() {

View file

@ -9,6 +9,7 @@ import {
Box,
makeStyles,
Tooltip,
Switch,
} from "@material-ui/core";
import InfoBox from "renderer/components/modal/swap/InfoBox";
import {
@ -16,7 +17,7 @@ import {
setElectrumRpcUrl,
setMoneroNodeUrl,
} from "store/features/settingsSlice";
import { useAppDispatch, useAppSelector } from "store/hooks";
import { useAppDispatch, useSettings } from "store/hooks";
import ValidatedTextField from "renderer/components/other/ValidatedTextField";
import RefreshIcon from "@material-ui/icons/Refresh";
import HelpIcon from '@material-ui/icons/HelpOutline';
@ -80,7 +81,7 @@ function isValidUrl(url: string, allowedProtocols: string[]): boolean {
}
function ElectrumRpcUrlSetting() {
const electrumRpcUrl = useAppSelector((s) => s.settings.electrum_rpc_url);
const electrumRpcUrl = useSettings((s) => s.electrum_rpc_url);
const dispatch = useAppDispatch();
function isValid(url: string): boolean {
@ -123,7 +124,7 @@ function SettingLabel({ label, tooltip }: { label: ReactNode, tooltip: string |
}
function MoneroNodeUrlSetting() {
const moneroNodeUrl = useAppSelector((s) => s.settings.monero_node_url);
const moneroNodeUrl = useSettings((s) => s.monero_node_url);
const dispatch = useAppDispatch();
function isValid(url: string): boolean {
@ -150,4 +151,4 @@ function MoneroNodeUrlSetting() {
</TableCell>
</TableRow>
);
}
}

View file

@ -17,9 +17,11 @@ import {
import App from "./components/App";
import { initEventListeners } from "./rpc";
import { persistor, store } from "./store/storeRenderer";
import { Box } from "@material-ui/core";
const container = document.getElementById("root");
const root = createRoot(container!);
root.render(
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>

View file

@ -36,6 +36,7 @@ import { providerToConcatenatedMultiAddr } from "utils/multiAddrUtils";
import { MoneroRecoveryResponse } from "models/rpcModel";
import { ListSellersResponse } from "../models/tauriModel";
import logger from "utils/logger";
import { isTestnet } from "store/config";
export async function initEventListeners() {
// This operation is in-expensive
@ -201,7 +202,10 @@ export async function listSellersAtRendezvousPoint(
export async function initializeContext() {
const settings = store.getState().settings;
const testnet = isTestnet();
await invokeUnsafe<void>("initialize_context", {
settings,
testnet,
});
}