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 { TauriContextStatusEvent, TauriEvent } from "models/tauriModel";
import { import {
contextStatusEventReceived, contextStatusEventReceived,
receivedCliLog,
rpcSetBalance, rpcSetBalance,
timelockChangeEventReceived, timelockChangeEventReceived,
approvalEventReceived, approvalEventReceived,
backgroundProgressEventReceived, backgroundProgressEventReceived,
} from "store/features/rpcSlice"; } from "store/features/rpcSlice";
import { receivedCliLog } from "store/features/logsSlice";
import { poolStatusReceived } from "store/features/poolSlice"; import { poolStatusReceived } from "store/features/poolSlice";
import { swapProgressEventReceived } from "store/features/swapSlice"; import { swapProgressEventReceived } from "store/features/swapSlice";
import logger from "utils/logger"; import logger from "utils/logger";
@ -24,8 +24,6 @@ import {
listSellersAtRendezvousPoint, listSellersAtRendezvousPoint,
refreshApprovals, refreshApprovals,
updateAllNodeStatuses, updateAllNodeStatuses,
fetchAndUpdateBackgroundItems,
fetchAndUpdateApprovalItems,
} from "./rpc"; } from "./rpc";
import { store } from "./store/storeRenderer"; import { store } from "./store/storeRenderer";
import { exhaustiveGuard } from "utils/typescriptUtils"; import { exhaustiveGuard } from "utils/typescriptUtils";

View file

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

View file

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

View file

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

View file

@ -17,7 +17,7 @@ import { LazyStore } from "@tauri-apps/plugin-store";
const rootPersistConfig = { const rootPersistConfig = {
key: "gui-global-state-store", key: "gui-global-state-store",
storage: sessionStorage, storage: sessionStorage,
blacklist: ["settings", "conversations"], blacklist: ["settings", "conversations", "logs"],
}; };
// Use Tauri's store plugin for persistent settings // 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 conversationsSlice from "./features/conversationsSlice";
import poolSlice from "./features/poolSlice"; import poolSlice from "./features/poolSlice";
import walletSlice from "./features/walletSlice"; import walletSlice from "./features/walletSlice";
import logsSlice from "./features/logsSlice";
export const reducers = { export const reducers = {
swap: swapReducer, swap: swapReducer,
@ -20,4 +21,5 @@ export const reducers = {
conversations: conversationsSlice, conversations: conversationsSlice,
pool: poolSlice, pool: poolSlice,
wallet: walletSlice, 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 { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { ExtendedMakerStatus, MakerStatus } from "models/apiModel"; import { ExtendedMakerStatus, MakerStatus } from "models/apiModel";
import { import {
TauriLogEvent,
GetSwapInfoResponse, GetSwapInfoResponse,
TauriContextStatusEvent, TauriContextStatusEvent,
TauriTimelockChangeEvent, TauriTimelockChangeEvent,
@ -12,8 +11,6 @@ import {
} from "models/tauriModel"; } from "models/tauriModel";
import { MoneroRecoveryResponse } from "../../models/rpcModel"; import { MoneroRecoveryResponse } from "../../models/rpcModel";
import { GetSwapInfoResponseExt } from "models/tauriModelExt"; import { GetSwapInfoResponseExt } from "models/tauriModelExt";
import { parseLogsFromString } from "utils/parseUtils";
import { CliLog } from "models/cliModel";
import logger from "utils/logger"; import logger from "utils/logger";
interface State { interface State {
@ -43,7 +40,6 @@ interface State {
export interface RPCSlice { export interface RPCSlice {
status: TauriContextStatusEvent | null; status: TauriContextStatusEvent | null;
state: State; state: State;
logs: (CliLog | string)[];
} }
const initialState: RPCSlice = { const initialState: RPCSlice = {
@ -58,21 +54,12 @@ const initialState: RPCSlice = {
backgroundRefund: null, backgroundRefund: null,
approvalRequests: {}, approvalRequests: {},
}, },
logs: [],
}; };
export const rpcSlice = createSlice({ export const rpcSlice = createSlice({
name: "rpc", name: "rpc",
initialState, initialState,
reducers: { 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( contextStatusEventReceived(
slice, slice,
action: PayloadAction<TauriContextStatusEvent>, action: PayloadAction<TauriContextStatusEvent>,
@ -173,7 +160,6 @@ export const rpcSlice = createSlice({
export const { export const {
contextStatusEventReceived, contextStatusEventReceived,
receivedCliLog,
rpcSetBalance, rpcSetBalance,
rpcSetWithdrawTxId, rpcSetWithdrawTxId,
rpcResetWithdrawTxId, rpcResetWithdrawTxId,

View file

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