mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-11-25 02:13:11 -05:00
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:
parent
18f1f45642
commit
65a3ebdbe2
9 changed files with 46 additions and 23 deletions
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
37
src-gui/src/store/features/logsSlice.ts
Normal file
37
src-gui/src/store/features/logsSlice.ts
Normal 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;
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue