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

@ -21,7 +21,7 @@ yarn install && yarn run dev
```bash
cd src-tauri
cargo tauri dev
cargo tauri dev --no-watch -- -- --testnet
# let this run as well
```

View file

@ -30,8 +30,6 @@
height: 100%;
margin: 0;
overflow: auto;
overscroll-behavior: none; /* Prevents the bounce effect */
overscroll-behavior-y: contain; /* Prevents the bounce effect on the y-axis */
}
</style>
</body>

View file

@ -20,6 +20,7 @@
"@material-ui/lab": "^4.0.0-alpha.61",
"@reduxjs/toolkit": "^2.2.6",
"@tauri-apps/api": "^2.0.0",
"@tauri-apps/plugin-cli": "^2.0.0",
"@tauri-apps/plugin-clipboard-manager": "^2.0.0",
"@tauri-apps/plugin-process": "^2.0.0",
"@tauri-apps/plugin-shell": "^2.0.0",
@ -58,6 +59,7 @@
"typescript": "^5.2.2",
"typescript-eslint": "^8.1.0",
"vite": "^5.3.1",
"vite-plugin-top-level-await": "^1.4.4",
"vite-plugin-watch": "^0.3.1",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^2.1.1"

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,
});
}

View file

@ -1,7 +1,12 @@
import { ExtendedProviderStatus } from "models/apiModel";
import { splitPeerIdFromMultiAddress } from "utils/parseUtils";
import { getMatches } from '@tauri-apps/plugin-cli';
export const isTestnet = () => true;
const matches = await getMatches();
export function isTestnet() {
return matches.args.testnet?.value === true
}
export const isDevelopment = true;

View file

@ -2,7 +2,6 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { TauriSettings } from "models/tauriModel";
const initialState: TauriSettings = {
bitcoin_confirmation_target: 1,
electrum_rpc_url: null,
monero_node_url: null,
};
@ -11,18 +10,15 @@ const alertsSlice = createSlice({
name: "settings",
initialState,
reducers: {
setBitcoinConfirmationTarget(slice, action: PayloadAction<number>) {
slice.bitcoin_confirmation_target = action.payload;
},
setElectrumRpcUrl(slice, action: PayloadAction<string | null>) {
if (action.payload === null || action.payload === "") {
if (action.payload === null || action.payload === "") {
slice.electrum_rpc_url = null;
} else {
slice.electrum_rpc_url = action.payload;
}
},
setMoneroNodeUrl(slice, action: PayloadAction<string | null>) {
if (action.payload === null || action.payload === "") {
if (action.payload === null || action.payload === "") {
slice.monero_node_url = null;
} else {
slice.monero_node_url = action.payload;
@ -35,9 +31,8 @@ const alertsSlice = createSlice({
});
export const {
setBitcoinConfirmationTarget,
setElectrumRpcUrl,
setMoneroNodeUrl,
resetSettings
resetSettings,
} = alertsSlice.actions;
export default alertsSlice.reducer;

View file

@ -5,6 +5,7 @@ import type { AppDispatch, RootState } from "renderer/store/storeRenderer";
import { parseDateString } from "utils/parseUtils";
import { useMemo } from "react";
import { isCliLogRelatedToSwap } from "models/cliModel";
import { TauriSettings } from "models/tauriModel";
export const useAppDispatch = () => useDispatch<AppDispatch>();
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
@ -73,6 +74,6 @@ export function useSwapInfosSortedByDate() {
);
}
export function useSettings() {
return useAppSelector((state) => state.settings);
}
export function useSettings<T>(selector: (settings: TauriSettings) => T): T {
return useAppSelector((state) => selector(state.settings));
}

View file

@ -4,6 +4,7 @@ import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
import { watch } from "vite-plugin-watch";
import path from "path";
import topLevelAwait from "vite-plugin-top-level-await";
const mobile = !!/android|ios/.exec(process.env.TAURI_ENV_PLATFORM);
@ -12,7 +13,8 @@ export default defineConfig(async () => ({
plugins: [
react(),
tsconfigPaths(),
// automatically regenerate the typescript bindings when there's a change
topLevelAwait(),
// Automatically regenerate the typescript bindings when there's a change to the rust code
watch({
pattern: ["../swap/src/**/*"],
command: "yarn run gen-bindings",
@ -25,9 +27,6 @@ export default defineConfig(async () => ({
server.watcher.add(path.resolve(__dirname, "../swap/src"));
},
},
// VitePluginRestart({
// restart: ["../swap/src/**/*"]
// })
],
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
//

View file

@ -557,6 +557,11 @@
resolved "https://registry.yarnpkg.com/@remix-run/router/-/router-1.17.1.tgz#bf93997beb81863fde042ebd05013a2618471362"
integrity sha512-mCOMec4BKd6BRGBZeSnGiIgwsbLGp3yhVqAD8H+PxiRNEHgDpZb8J1TnrSDlg97t0ySKMQJTHCWBCmBpSmkF6Q==
"@rollup/plugin-virtual@^3.0.2":
version "3.0.2"
resolved "https://registry.yarnpkg.com/@rollup/plugin-virtual/-/plugin-virtual-3.0.2.tgz#17e17eeecb4c9fa1c0a6e72c9e5f66382fddbb82"
integrity sha512-10monEYsBp3scM4/ND4LNH5Rxvh3e/cVeL3jWTgZ2SrQ+BmUoQcopVQvnaMcOnykb1VkxUFuDAN+0FnpTFRy2A==
"@rollup/rollup-android-arm-eabi@4.18.0":
version "4.18.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.18.0.tgz#bbd0e616b2078cd2d68afc9824d1fadb2f2ffd27"
@ -717,6 +722,87 @@
resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.22.2.tgz#c770006ccc780b2de7b2151fc7f37b49121a21c1"
integrity sha512-Yy8So+SoRz8I3NS4Bjh91BICPOSVgdompTIPYTByUqU66AXSIOgmW3Lv1ke3NORPqxdF+RdrZET+8vYai6f4aA==
"@swc/core-darwin-arm64@1.7.26":
version "1.7.26"
resolved "https://registry.yarnpkg.com/@swc/core-darwin-arm64/-/core-darwin-arm64-1.7.26.tgz#5f4096c00e71771ca1b18c824f0c92a052c70760"
integrity sha512-FF3CRYTg6a7ZVW4yT9mesxoVVZTrcSWtmZhxKCYJX9brH4CS/7PRPjAKNk6kzWgWuRoglP7hkjQcd6EpMcZEAw==
"@swc/core-darwin-x64@1.7.26":
version "1.7.26"
resolved "https://registry.yarnpkg.com/@swc/core-darwin-x64/-/core-darwin-x64-1.7.26.tgz#867b7a4f094e6b64201090ca5fcbf3da7d0f3e22"
integrity sha512-az3cibZdsay2HNKmc4bjf62QVukuiMRh5sfM5kHR/JMTrLyS6vSw7Ihs3UTkZjUxkLTT8ro54LI6sV6sUQUbLQ==
"@swc/core-linux-arm-gnueabihf@1.7.26":
version "1.7.26"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.7.26.tgz#35bb43894def296d92aaa2cc9372d48042f37777"
integrity sha512-VYPFVJDO5zT5U3RpCdHE5v1gz4mmR8BfHecUZTmD2v1JeFY6fv9KArJUpjrHEEsjK/ucXkQFmJ0jaiWXmpOV9Q==
"@swc/core-linux-arm64-gnu@1.7.26":
version "1.7.26"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.7.26.tgz#8e2321cc4ec84cbfed8f8e16ff1ed7b854450443"
integrity sha512-YKevOV7abpjcAzXrhsl+W48Z9mZvgoVs2eP5nY+uoMAdP2b3GxC0Df1Co0I90o2lkzO4jYBpTMcZlmUXLdXn+Q==
"@swc/core-linux-arm64-musl@1.7.26":
version "1.7.26"
resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.7.26.tgz#b1c16e4b23ffa9ff19973eda6ffee35d2a7de7b0"
integrity sha512-3w8iZICMkQQON0uIcvz7+Q1MPOW6hJ4O5ETjA0LSP/tuKqx30hIniCGOgPDnv3UTMruLUnQbtBwVCZTBKR3Rkg==
"@swc/core-linux-x64-gnu@1.7.26":
version "1.7.26"
resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.7.26.tgz#388e2cc13a010cd28787aead2cecf31eb491836d"
integrity sha512-c+pp9Zkk2lqb06bNGkR2Looxrs7FtGDMA4/aHjZcCqATgp348hOKH5WPvNLBl+yPrISuWjbKDVn3NgAvfvpH4w==
"@swc/core-linux-x64-musl@1.7.26":
version "1.7.26"
resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.7.26.tgz#51e0ff30981f26d7a5b97a7a7b5b291bad050d1a"
integrity sha512-PgtyfHBF6xG87dUSSdTJHwZ3/8vWZfNIXQV2GlwEpslrOkGqy+WaiiyE7Of7z9AvDILfBBBcJvJ/r8u980wAfQ==
"@swc/core-win32-arm64-msvc@1.7.26":
version "1.7.26"
resolved "https://registry.yarnpkg.com/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.7.26.tgz#a7fdcc4074c34ee6a026506b594d00323383c11f"
integrity sha512-9TNXPIJqFynlAOrRD6tUQjMq7KApSklK3R/tXgIxc7Qx+lWu8hlDQ/kVPLpU7PWvMMwC/3hKBW+p5f+Tms1hmA==
"@swc/core-win32-ia32-msvc@1.7.26":
version "1.7.26"
resolved "https://registry.yarnpkg.com/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.7.26.tgz#ae7be6dde798eebee2000b8fd84e01a439b5bd6a"
integrity sha512-9YngxNcG3177GYdsTum4V98Re+TlCeJEP4kEwEg9EagT5s3YejYdKwVAkAsJszzkXuyRDdnHUpYbTrPG6FiXrQ==
"@swc/core-win32-x64-msvc@1.7.26":
version "1.7.26"
resolved "https://registry.yarnpkg.com/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.7.26.tgz#310d607004d7319085a4dec20c0c38c3405cc05b"
integrity sha512-VR+hzg9XqucgLjXxA13MtV5O3C0bK0ywtLIBw/+a+O+Oc6mxFWHtdUeXDbIi5AiPbn0fjgVJMqYnyjGyyX8u0w==
"@swc/core@^1.7.0":
version "1.7.26"
resolved "https://registry.yarnpkg.com/@swc/core/-/core-1.7.26.tgz#beda9b82063fcec7b56c958804a4d175aecf9a9d"
integrity sha512-f5uYFf+TmMQyYIoxkn/evWhNGuUzC730dFwAKGwBVHHVoPyak1/GvJUm6i1SKl+2Hrj9oN0i3WSoWWZ4pgI8lw==
dependencies:
"@swc/counter" "^0.1.3"
"@swc/types" "^0.1.12"
optionalDependencies:
"@swc/core-darwin-arm64" "1.7.26"
"@swc/core-darwin-x64" "1.7.26"
"@swc/core-linux-arm-gnueabihf" "1.7.26"
"@swc/core-linux-arm64-gnu" "1.7.26"
"@swc/core-linux-arm64-musl" "1.7.26"
"@swc/core-linux-x64-gnu" "1.7.26"
"@swc/core-linux-x64-musl" "1.7.26"
"@swc/core-win32-arm64-msvc" "1.7.26"
"@swc/core-win32-ia32-msvc" "1.7.26"
"@swc/core-win32-x64-msvc" "1.7.26"
"@swc/counter@^0.1.3":
version "0.1.3"
resolved "https://registry.yarnpkg.com/@swc/counter/-/counter-0.1.3.tgz#cc7463bd02949611c6329596fccd2b0ec782b0e9"
integrity sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==
"@swc/types@^0.1.12":
version "0.1.12"
resolved "https://registry.yarnpkg.com/@swc/types/-/types-0.1.12.tgz#7f632c06ab4092ce0ebd046ed77ff7557442282f"
integrity sha512-wBJA+SdtkbFhHjTMYH+dEH1y4VpfGdAc2Kw/LK09i9bXd/K6j6PkDcFCEzb6iVfZMkPRrl/q0e3toqTAJdkIVA==
dependencies:
"@swc/counter" "^0.1.3"
"@tauri-apps/api@^2.0.0":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@tauri-apps/api/-/api-2.0.1.tgz#dc49d899fb873b96ee1d46a171384625ba5ad404"
@ -788,6 +874,13 @@
"@tauri-apps/cli-win32-ia32-msvc" "2.0.1"
"@tauri-apps/cli-win32-x64-msvc" "2.0.1"
"@tauri-apps/plugin-cli@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/plugin-cli/-/plugin-cli-2.0.0.tgz#cf90232909a3f1c0ac963dcef9914ca0c9f874f9"
integrity sha512-glQmlL1IiCGEa1FHYa/PTPSeYhfu56omLRgHXWlJECDt6DbJyRuJWVgtkQfUxtqnVdYnnU+DGIGeiInoEqtjLw==
dependencies:
"@tauri-apps/api" "^2.0.0"
"@tauri-apps/plugin-clipboard-manager@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@tauri-apps/plugin-clipboard-manager/-/plugin-clipboard-manager-2.0.0.tgz#cf08df2338c055d15a60cbb61140766859e06a77"
@ -3633,6 +3726,11 @@ use-sync-external-store@^1.0.0:
resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.2.2.tgz#c3b6390f3a30eba13200d2302dcdf1e7b57b2ef9"
integrity sha512-PElTlVMwpblvbNqQ82d2n6RjStvdSoNe9FG28kNfz3WiXilJm4DdNkEzRhCZuIDwY8U08WVihhGR5iRqAwfDiw==
uuid@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-10.0.0.tgz#5a95aa454e6e002725c79055fd42aaba30ca6294"
integrity sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==
varint@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/varint/-/varint-6.0.0.tgz#9881eb0ce8feaea6512439d19ddf84bf551661d0"
@ -3653,6 +3751,15 @@ vite-node@2.1.1:
pathe "^1.1.2"
vite "^5.0.0"
vite-plugin-top-level-await@^1.4.4:
version "1.4.4"
resolved "https://registry.yarnpkg.com/vite-plugin-top-level-await/-/vite-plugin-top-level-await-1.4.4.tgz#4900e06bfb7179de20aaa9b4730d04022a9e259e"
integrity sha512-QyxQbvcMkgt+kDb12m2P8Ed35Sp6nXP+l8ptGrnHV9zgYDUpraO0CPdlqLSeBqvY2DToR52nutDG7mIHuysdiw==
dependencies:
"@rollup/plugin-virtual" "^3.0.2"
"@swc/core" "^1.7.0"
uuid "^10.0.0"
vite-plugin-watch@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/vite-plugin-watch/-/vite-plugin-watch-0.3.1.tgz#5000f7ded6eb1c42e9483d6ea3d812061ab8188f"