Skip to content

Commit

Permalink
recently used addresses update
Browse files Browse the repository at this point in the history
  • Loading branch information
kartiksaini3 committed Jan 29, 2025
1 parent 15e8490 commit 167b800
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions src/Pages/History/History.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { CURRENCY } from "../../Constants/index";
import { arrayReverser } from "../../Utility/utility";
import noTransaction from "../../Assets/NoTransaction.svg";
import ModalCloseIcon from "../../Assets/ModalCloseIcon.svg";
import React, { useContext, useState, useCallback } from "react";
import React, { useContext, useState, useCallback, useEffect, useMemo } from "react";
import TransectionHistry from "../../Components/TransectionHistry/TransectionHistry";

function History() {
const [open1, setOpen1] = useState(false);
const [selectedTransaction, setSelectedTransaction] = useState(null);
const [recentlyUsedAddresses, setRecentlyUsedAddresses] = useState([]);
const { state } = useContext(AuthContext);
const { currentNetwork, txHistory, currentAccount } = state;

Expand All @@ -29,6 +30,32 @@ function History() {
[currentAccount.evmAddress, txHistory]
);

const filteredTxHistory = useMemo(
() =>
arrayReverser(
txHistory[currentAccount?.evmAddress].filter(
(tx) => tx?.chain.toLowerCase() === currentNetwork.toLowerCase()
)
),
[txHistory, currentAccount?.evmAddress, currentNetwork]
);

useEffect(() => {
const uniqueAddressesObj = {};
const uniqueRecentlyUsedAdresses = [];

filteredTxHistory.forEach((tx) => {
if (!uniqueAddressesObj[tx?.to]) {
uniqueAddressesObj[tx?.to] = true;
uniqueRecentlyUsedAdresses.push(tx?.to);
}
});

setRecentlyUsedAddresses(uniqueRecentlyUsedAdresses.slice(0, 10));
}, [txHistory, currentAccount?.evmAddress, filteredTxHistory]);

console.log("state", recentlyUsedAddresses);

return (
<div className={style.historySec}>
<div className={style.historySec__historyHead}>
Expand All @@ -37,11 +64,7 @@ function History() {
<div className={style.histryDataScrol}>
{txHistory[currentAccount?.evmAddress] &&
txHistory[currentAccount?.evmAddress].length > 0 ? (
arrayReverser(
txHistory[currentAccount?.evmAddress].filter(
(tx) => tx?.chain.toLowerCase() === currentNetwork.toLowerCase()
)
).map((data, index) => (
filteredTxHistory.map((data, index) => (
<HistoryItem
historyItem={data}
handleHistoryOpen={handleHistoryOpen}
Expand Down

0 comments on commit 167b800

Please sign in to comment.