From cb66be4b92f30efc58dfec4db0ce39c2e88de7b7 Mon Sep 17 00:00:00 2001 From: MananTank Date: Fri, 20 Dec 2024 12:19:55 +0000 Subject: [PATCH] [TOOL-2773] Fix incorrect caching in useCsvUpload hook (#5820) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem solved Fixes: https://github.com/thirdweb-dev/js/issues/5791 Problem: User uploads a CSV1 and then uploads a CSV2 - CSV2 is ignored and CSV1's data is sent instead of CSV2 because of incorrect query cache key --- ## PR-Codex overview This PR focuses on refactoring the `normalizeQuery` in the `useCsvUpload` hook to improve clarity and consistency in parameter naming. ### Detailed summary - Changed the parameter name from `o` to `item` in the `rawData.map` function for better readability. - Updated the `queryKey` to use `item` directly instead of `o.address`. - Maintained the same functionality while enhancing code clarity. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --- apps/dashboard/src/hooks/useCsvUpload.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/dashboard/src/hooks/useCsvUpload.ts b/apps/dashboard/src/hooks/useCsvUpload.ts index c233337846d..14423a956eb 100644 --- a/apps/dashboard/src/hooks/useCsvUpload.ts +++ b/apps/dashboard/src/hooks/useCsvUpload.ts @@ -134,10 +134,11 @@ export function useCsvUpload< const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop, }); + const normalizeQuery = useQueries({ - queries: rawData.map((o) => ({ - queryKey: ["snapshot-check-isAddress", o.address], - queryFn: () => checkIsAddress({ item: o, thirdwebClient }), + queries: rawData.map((item) => ({ + queryKey: ["snapshot-check-isAddress", item], + queryFn: () => checkIsAddress({ item: item, thirdwebClient }), })), combine: (results) => { return { @@ -149,6 +150,7 @@ export function useCsvUpload< }; }, }); + const removeInvalid = useCallback(() => { const filteredData = normalizeQuery.data?.result.filter( ({ isValid }) => isValid,