Skip to content

Commit

Permalink
Merge pull request #450 from DeXter-on-Radix/restylianos/trade-histor…
Browse files Browse the repository at this point in the history
…y-reset

[Fix]: Remove trade history on log out
  • Loading branch information
dcts authored Jun 19, 2024
2 parents a88e4b5 + 191c789 commit 85fedf0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/app/components/NavBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import Image from "next/image";
import Link from "next/link";

Expand All @@ -11,6 +11,8 @@ import { i18nSlice } from "../state/i18nSlice";
import Cookies from "js-cookie";
import { usePathname } from "next/navigation";
import { isMobile } from "../utils";
import { accountHistorySlice } from "state/accountHistorySlice";
import { pairSelectorSlice } from "state/pairSelectorSlice";

interface NavbarItemProps {
title: string;
Expand All @@ -32,6 +34,23 @@ const NavItems: { path: string; title: string }[] = [
];

export function Navbar() {
const dispatch = useAppDispatch();

useEffect(() => {
const radixConnectButton = document.querySelector("radix-connect-button")!;
// Trigger disconnect actions
const handleDisconnect = () => {
dispatch(accountHistorySlice.actions.resetAccountHistory());
dispatch(pairSelectorSlice.actions.resetBalances());
};

radixConnectButton.addEventListener("onDisconnect", handleDisconnect);

return () => {
radixConnectButton.removeEventListener("onDisconnect", handleDisconnect);
};
}, [dispatch]);

return (
<nav
className={
Expand Down
3 changes: 3 additions & 0 deletions src/app/state/accountHistorySlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ export const accountHistorySlice = createSlice({
const adexState = action.payload;
state.trades = adexState.currentPairTrades;
},
resetAccountHistory: () => {
return initialState;
},
setSelectedTable: (state, action: PayloadAction<Tables>) => {
state.selectedTable = action.payload;
},
Expand Down
14 changes: 14 additions & 0 deletions src/app/state/pairSelectorSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ export const pairSelectorSlice = createSlice({
state.token2 = { ...state.token2, balance };
}
},
resetBalances: (state: PairSelectorState) => {
const [token1State, token2State] = [
{ ...state.token1 },
{ ...state.token2 },
];
delete token1State.balance;
delete token2State.balance;

return {
...state,
["token1"]: token1State,
["token2"]: token2State,
};
},
},

extraReducers: (builder) => {
Expand Down

0 comments on commit 85fedf0

Please sign in to comment.