From 8b3bdd0b3df62bcc8b61289e88250af734ba1d04 Mon Sep 17 00:00:00 2001 From: Sergey Kintsel Date: Thu, 12 Oct 2023 13:16:18 +0100 Subject: [PATCH] Fix doubled operations --- src/views/operations/useGetOperations.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/views/operations/useGetOperations.tsx b/src/views/operations/useGetOperations.tsx index 5cb0e5c248..98eaba5876 100644 --- a/src/views/operations/useGetOperations.tsx +++ b/src/views/operations/useGetOperations.tsx @@ -8,6 +8,7 @@ import { tokensActions } from "../../utils/redux/slices/tokensSlice"; import { Network } from "../../types/Network"; import { AppDispatch } from "../../utils/redux/store"; import { useAsyncActionHandler } from "../../utils/hooks/useAsyncActionHandler"; +import { uniqBy } from "lodash"; const REFRESH_INTERVAL = 15000; @@ -39,7 +40,11 @@ export const useGetOperations = (initialAddresses: RawPkh[]) => { ); // reverse is needed because we fetch the operations in the opposite order - setOperations(currentOperations => [...newOperations.reverse(), ...currentOperations]); + // there is a chance that we get the same operation twice when + // latest fetching updates so, we need to deduplicate records + setOperations(currentOperations => + uniqBy([...newOperations.reverse(), ...currentOperations], op => op.id) + ); }); }, REFRESH_INTERVAL); return () => clearInterval(interval);