From 7fe2d03afd9e4b1756f51ae1fbcbf8f3d8048bf8 Mon Sep 17 00:00:00 2001 From: Manan Tank Date: Wed, 26 Feb 2025 03:40:38 +0530 Subject: [PATCH] [TOOL-3528] Dasboard: Fix in-app users CSV downloads empty file --- .../react/hooks/useEmbeddedWallets.ts | 35 ++++----- .../embedded-wallets/Users/index.tsx | 77 ++++++++++--------- .../src/components/shared/TWTable.tsx | 4 +- 3 files changed, 59 insertions(+), 57 deletions(-) diff --git a/apps/dashboard/src/@3rdweb-sdk/react/hooks/useEmbeddedWallets.ts b/apps/dashboard/src/@3rdweb-sdk/react/hooks/useEmbeddedWallets.ts index 0bdd40a054e..86254d1e4e7 100644 --- a/apps/dashboard/src/@3rdweb-sdk/react/hooks/useEmbeddedWallets.ts +++ b/apps/dashboard/src/@3rdweb-sdk/react/hooks/useEmbeddedWallets.ts @@ -1,9 +1,4 @@ -import { - keepPreviousData, - useMutation, - useQuery, - useQueryClient, -} from "@tanstack/react-query"; +import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { THIRDWEB_EWS_API_HOST } from "constants/urls"; import { useActiveAccount } from "thirdweb/react"; import type { WalletUser } from "thirdweb/wallets"; @@ -33,7 +28,6 @@ const fetchAccountList = ({ const json = await res.json(); return json as { users: WalletUser[]; - totalPages: number; }; }; }; @@ -57,11 +51,11 @@ export function useEmbeddedWallets(params: { clientId, pageNumber: page, }), - placeholderData: keepPreviousData, enabled: !!address && !!clientId, }); } +// TODO: fetching list of all users needs to be improved export function useAllEmbeddedWallets(params: { authToken: string; }) { @@ -70,15 +64,13 @@ export function useAllEmbeddedWallets(params: { const address = useActiveAccount()?.address; return useMutation({ - mutationFn: async ({ - clientId, - totalPages, - }: { clientId: string; totalPages: number }) => { - const walletRes = []; - for (let page = 1; page <= totalPages; page++) { - const res = queryClient.fetchQuery<{ + mutationFn: async ({ clientId }: { clientId: string }) => { + const responses: WalletUser[] = []; + let page = 1; + + while (true) { + const res = await queryClient.fetchQuery<{ users: WalletUser[]; - totalPages: number; }>({ queryKey: embeddedWalletsKeys.embeddedWallets( address || "", @@ -91,9 +83,16 @@ export function useAllEmbeddedWallets(params: { pageNumber: page, }), }); - walletRes.push(res); + + if (res.users.length === 0) { + break; + } + + page++; + responses.push(...res.users); } - return (await Promise.all(walletRes)).flatMap((res) => res.users); + + return responses; }, }); } diff --git a/apps/dashboard/src/components/embedded-wallets/Users/index.tsx b/apps/dashboard/src/components/embedded-wallets/Users/index.tsx index b1cb9a38258..2b6a3135c14 100644 --- a/apps/dashboard/src/components/embedded-wallets/Users/index.tsx +++ b/apps/dashboard/src/components/embedded-wallets/Users/index.tsx @@ -1,7 +1,6 @@ "use client"; import { WalletAddress } from "@/components/blocks/wallet-address"; -import { PaginationButtons } from "@/components/pagination-buttons"; import { Spinner } from "@/components/ui/Spinner/Spinner"; import { Button } from "@/components/ui/button"; import { @@ -17,6 +16,7 @@ import { import { createColumnHelper } from "@tanstack/react-table"; import { TWTable } from "components/shared/TWTable"; import { format } from "date-fns/format"; +import { ArrowLeft, ArrowRight } from "lucide-react"; import Papa from "papaparse"; import { useCallback, useState } from "react"; import type { WalletUser } from "thirdweb/wallets"; @@ -97,21 +97,18 @@ const columns = [ }), ]; -export const InAppWalletUsersPageContent = (props: { +export function InAppWalletUsersPageContent(props: { clientId: string; trackingCategory: string; authToken: string; -}) => { +}) { const [activePage, setActivePage] = useState(1); const walletsQuery = useEmbeddedWallets({ authToken: props.authToken, clientId: props.clientId, page: activePage, }); - const { users: wallets, totalPages } = walletsQuery?.data || { - users: [], - totalPages: 1, - }; + const wallets = walletsQuery?.data?.users || []; const { mutateAsync: getAllEmbeddedWallets, isPending } = useAllEmbeddedWallets({ authToken: props.authToken, @@ -123,7 +120,6 @@ export const InAppWalletUsersPageContent = (props: { } const usersWallets = await getAllEmbeddedWallets({ clientId: props.clientId, - totalPages, }); const csv = Papa.unparse( usersWallets.map((row) => { @@ -144,13 +140,13 @@ export const InAppWalletUsersPageContent = (props: { tempLink.href = csvUrl; tempLink.setAttribute("download", "download.csv"); tempLink.click(); - }, [wallets, props.clientId, totalPages, getAllEmbeddedWallets]); + }, [wallets, props.clientId, getAllEmbeddedWallets]); return (
-
+
{/* Top section */} -
+
- -
- {walletsQuery.isPlaceholderData && ( - <> - -

- Loading page {activePage} of {totalPages} -

- - )} -
- - - {totalPages > 1 && ( - + - )} + +
+ + +
+
); -}; +} diff --git a/apps/dashboard/src/components/shared/TWTable.tsx b/apps/dashboard/src/components/shared/TWTable.tsx index d76bfd2e0f3..4f38e902773 100644 --- a/apps/dashboard/src/components/shared/TWTable.tsx +++ b/apps/dashboard/src/components/shared/TWTable.tsx @@ -252,10 +252,10 @@ export function TWTable(tableProps: TWTableProps) { {!tableProps.isPending && tableProps.data.length === 0 && tableProps.isFetched && ( -
+

- No {pluralize(tableProps.title, 0, false)} found. + No {pluralize(tableProps.title, 0, false)} found