Skip to content

Commit

Permalink
Fixed the issue with duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
saidam90 committed Aug 2, 2024
1 parent 871bd83 commit bf0f393
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
6 changes: 0 additions & 6 deletions src/app/components/PairSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import Image from "next/image";
import React from "react";

import { BLACKLISTED_PAIRS } from "../data/BLACKLISTED_PAIRS";
import {
fetchAccountHistory,
fetchAccountHistoryAllPairs,
} from "state/accountHistorySlice";

interface PairInfo {
name: string;
Expand Down Expand Up @@ -96,8 +92,6 @@ export function PairSelector() {
pairName: option["name"],
})
);
dispatch(fetchAccountHistory);
dispatch(fetchAccountHistoryAllPairs);
setHighlightedIndex(-1);
setIsOpen(!isOpen);
},
Expand Down
23 changes: 18 additions & 5 deletions src/app/state/accountHistorySlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ export const fetchAccountHistoryAllPairs = createAsyncThunk<
{ state: RootState }
>("accountHistory/fetchAccountHistoryAllPairs", async (_, thunkAPI) => {
const state = thunkAPI.getState();
const pairAddresses = state.pairSelector.pairsList
.map((pairInfo) => pairInfo.address)
.filter((pairAddress) => pairAddress !== state.pairSelector.address);
const pairAddresses = state.pairSelector.pairsList.map(
(pairInfo) => pairInfo.address
);
// .filter((pairAddress) => pairAddress !== state.pairSelector.address);

const account = state.radix?.walletData.accounts[0]?.address || "";

Expand Down Expand Up @@ -267,13 +268,25 @@ export const selectOrderHistory = createSelector(
// A function that checks an order against a filter condition and returns TRUE if it matches, FALSE otherwise
type FilterFunction = (order: adex.OrderReceipt) => boolean;

// Selectors can have input arguments
let selectCombinedOrders = (filterFunction: FilterFunction) =>
createSelector(
(state: RootState) => state.accountHistory.orderHistory,
(state: RootState) => state.accountHistory.orderHistoryAllPairs,
(orderHistory, orderHistoryAllPairs) => {
return [...orderHistoryAllPairs, ...orderHistory]
// Create a Map to handle duplicates
const orderMap = new Map<number, adex.OrderReceipt>();

// Add orders from orderHistory
orderHistory.forEach((order) => {
orderMap.set(order.id, order);
});

// Add orders from orderHistoryAllPairs, will overwrite any duplicates from orderHistory
orderHistoryAllPairs.forEach((order) => {
orderMap.set(order.id, order);
});

return Array.from(orderMap.values())
.filter(filterFunction)
.sort((a, b) => {
const timeDifference =
Expand Down

0 comments on commit bf0f393

Please sign in to comment.