Skip to content

Commit

Permalink
Merge pull request #502 from trilitech/fix-doubled-operations
Browse files Browse the repository at this point in the history
Fix doubled operations
  • Loading branch information
serjonya-trili authored Oct 12, 2023
2 parents 19ef281 + 8b3bdd0 commit 027fe29
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/views/operations/useGetOperations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 027fe29

Please sign in to comment.