mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-11-25 10:23:20 -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 { 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";
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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),
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
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 { 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,
|
||||||
|
|
|
||||||
|
|
@ -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)),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue