Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 10 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
target
target
112 changes: 111 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"rustfmt.associations": "**/*.rs"
},
"includes": ["**/*.{md}", "**/*.{toml}", "**/*.{rs}"],
"excludes": ["target/"],
"excludes": ["target/", "src-tauri/Cargo.toml"],
"plugins": [
"https://plugins.dprint.dev/markdown-0.13.1.wasm",
"https://github.com/thomaseizinger/dprint-plugin-cargo-toml/releases/download/0.1.0/cargo-toml-0.1.0.wasm",
Expand Down
2 changes: 1 addition & 1 deletion src-gui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
2 changes: 0 additions & 2 deletions src-gui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions src-gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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")}`;
}
Expand Down
3 changes: 2 additions & 1 deletion src-gui/src/renderer/components/modal/swap/SwapDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
9 changes: 5 additions & 4 deletions src-gui/src/renderer/components/pages/help/SettingsBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import {
Box,
makeStyles,
Tooltip,
Switch,
} from "@material-ui/core";
import InfoBox from "renderer/components/modal/swap/InfoBox";
import {
resetSettings,
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';
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -150,4 +151,4 @@ function MoneroNodeUrlSetting() {
</TableCell>
</TableRow>
);
}
}
2 changes: 2 additions & 0 deletions src-gui/src/renderer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}>
Expand Down
4 changes: 4 additions & 0 deletions src-gui/src/renderer/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
});
}
7 changes: 6 additions & 1 deletion src-gui/src/store/config.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
11 changes: 3 additions & 8 deletions src-gui/src/store/features/settingsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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;
Expand All @@ -35,9 +31,8 @@ const alertsSlice = createSlice({
});

export const {
setBitcoinConfirmationTarget,
setElectrumRpcUrl,
setMoneroNodeUrl,
resetSettings
resetSettings,
} = alertsSlice.actions;
export default alertsSlice.reducer;
Loading
Loading