refactor(gui): Do not store logs in redux-persist (#476)

* refactor(gui): Do not store logs in redux-persist

* amend fmt
This commit is contained in:
Mohan 2025-07-23 22:13:56 +02:00 committed by GitHub
parent 18f1f45642
commit 65a3ebdbe2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 46 additions and 23 deletions

View file

@ -2,12 +2,12 @@ import { listen } from "@tauri-apps/api/event";
import { TauriContextStatusEvent, TauriEvent } from "models/tauriModel";
import {
contextStatusEventReceived,
receivedCliLog,
rpcSetBalance,
timelockChangeEventReceived,
approvalEventReceived,
backgroundProgressEventReceived,
} from "store/features/rpcSlice";
import { receivedCliLog } from "store/features/logsSlice";
import { poolStatusReceived } from "store/features/poolSlice";
import { swapProgressEventReceived } from "store/features/swapSlice";
import logger from "utils/logger";
@ -24,8 +24,6 @@ import {
listSellersAtRendezvousPoint,
refreshApprovals,
updateAllNodeStatuses,
fetchAndUpdateBackgroundItems,
fetchAndUpdateApprovalItems,
} from "./rpc";
import { store } from "./store/storeRenderer";
import { exhaustiveGuard } from "utils/typescriptUtils";

View file

@ -82,7 +82,7 @@ export function useFeedback() {
try {
if (inputState.isDaemonLogsRedacted) {
redactLogs(store.getState().rpc?.logs)
redactLogs(store.getState().logs?.state.logs)
.then((redactedLogs) => {
setLogsState((prev) => ({
...prev,
@ -98,7 +98,7 @@ export function useFeedback() {
} else {
setLogsState((prev) => ({
...prev,
daemonLogs: store.getState().rpc?.logs,
daemonLogs: store.getState().logs?.state.logs,
}));
setError(null);
}

View file

@ -12,7 +12,7 @@ import { revealItemInDir } from "@tauri-apps/plugin-opener";
import { TauriContextStatusEvent } from "models/tauriModel";
export default function DaemonControlBox() {
const logs = useAppSelector((s) => s.rpc.logs);
const logs = useAppSelector((s) => s.logs.state.logs);
// The daemon can be manually started if it has failed or if it has not been started yet
const canContextBeManuallyStarted = useAppSelector(

View file

@ -14,7 +14,7 @@ export default function ExportLogsButton({
}: ExportLogsButtonProps) {
async function handleExportLogs() {
const swapLogs = await getLogsOfSwap(swap_id, false);
const daemonLogs = store.getState().rpc?.logs;
const daemonLogs = store.getState().logs?.state.logs;
const logContent = {
swap_logs: logsToRawString(swapLogs.logs),

View file

@ -17,7 +17,7 @@ import { LazyStore } from "@tauri-apps/plugin-store";
const rootPersistConfig = {
key: "gui-global-state-store",
storage: sessionStorage,
blacklist: ["settings", "conversations"],
blacklist: ["settings", "conversations", "logs"],
};
// Use Tauri's store plugin for persistent settings

View file

@ -8,6 +8,7 @@ import nodesSlice from "./features/nodesSlice";
import conversationsSlice from "./features/conversationsSlice";
import poolSlice from "./features/poolSlice";
import walletSlice from "./features/walletSlice";
import logsSlice from "./features/logsSlice";
export const reducers = {
swap: swapReducer,
@ -20,4 +21,5 @@ export const reducers = {
conversations: conversationsSlice,
pool: poolSlice,
wallet: walletSlice,
logs: logsSlice,
};

View file

@ -0,0 +1,37 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { TauriLogEvent } from "models/tauriModel";
import { parseLogsFromString } from "utils/parseUtils";
import { CliLog } from "models/cliModel";
interface LogsState {
logs: (CliLog | string)[];
}
export interface LogsSlice {
state: LogsState;
}
const initialState: LogsSlice = {
state: {
logs: [],
},
};
export const logsSlice = createSlice({
name: "logs",
initialState,
reducers: {
receivedCliLog(slice, action: PayloadAction<TauriLogEvent>) {
const buffer = action.payload.buffer;
const logs = parseLogsFromString(buffer);
const logsWithoutExisting = logs.filter(
(log) => !slice.state.logs.includes(log),
);
slice.state.logs = slice.state.logs.concat(logsWithoutExisting);
},
},
});
export const { receivedCliLog } = logsSlice.actions;
export default logsSlice.reducer;

View file

@ -1,7 +1,6 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { ExtendedMakerStatus, MakerStatus } from "models/apiModel";
import {
TauriLogEvent,
GetSwapInfoResponse,
TauriContextStatusEvent,
TauriTimelockChangeEvent,
@ -12,8 +11,6 @@ import {
} from "models/tauriModel";
import { MoneroRecoveryResponse } from "../../models/rpcModel";
import { GetSwapInfoResponseExt } from "models/tauriModelExt";
import { parseLogsFromString } from "utils/parseUtils";
import { CliLog } from "models/cliModel";
import logger from "utils/logger";
interface State {
@ -43,7 +40,6 @@ interface State {
export interface RPCSlice {
status: TauriContextStatusEvent | null;
state: State;
logs: (CliLog | string)[];
}
const initialState: RPCSlice = {
@ -58,21 +54,12 @@ const initialState: RPCSlice = {
backgroundRefund: null,
approvalRequests: {},
},
logs: [],
};
export const rpcSlice = createSlice({
name: "rpc",
initialState,
reducers: {
receivedCliLog(slice, action: PayloadAction<TauriLogEvent>) {
const buffer = action.payload.buffer;
const logs = parseLogsFromString(buffer);
const logsWithoutExisting = logs.filter(
(log) => !slice.logs.includes(log),
);
slice.logs = slice.logs.concat(logsWithoutExisting);
},
contextStatusEventReceived(
slice,
action: PayloadAction<TauriContextStatusEvent>,
@ -173,7 +160,6 @@ export const rpcSlice = createSlice({
export const {
contextStatusEventReceived,
receivedCliLog,
rpcSetBalance,
rpcSetWithdrawTxId,
rpcResetWithdrawTxId,

View file

@ -137,7 +137,7 @@ export function useActiveSwapInfo(): GetSwapInfoResponseExt | null {
export function useActiveSwapLogs() {
const swapId = useActiveSwapId();
const logs = useAppSelector((s) => s.rpc.logs);
const logs = useAppSelector((s) => s.logs.state.logs);
return useMemo(
() => logs.filter((log) => isCliLogRelatedToSwap(log, swapId)),