Skip to content

Commit ddbacd1

Browse files
authored
[TOOL-3528] Dasboard: Fix in-app users CSV downloads empty file (#6342)
1 parent 3240ae5 commit ddbacd1

File tree

3 files changed

+59
-57
lines changed

3 files changed

+59
-57
lines changed

apps/dashboard/src/@3rdweb-sdk/react/hooks/useEmbeddedWallets.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
keepPreviousData,
3-
useMutation,
4-
useQuery,
5-
useQueryClient,
6-
} from "@tanstack/react-query";
1+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
72
import { THIRDWEB_EWS_API_HOST } from "constants/urls";
83
import { useActiveAccount } from "thirdweb/react";
94
import type { WalletUser } from "thirdweb/wallets";
@@ -33,7 +28,6 @@ const fetchAccountList = ({
3328
const json = await res.json();
3429
return json as {
3530
users: WalletUser[];
36-
totalPages: number;
3731
};
3832
};
3933
};
@@ -57,11 +51,11 @@ export function useEmbeddedWallets(params: {
5751
clientId,
5852
pageNumber: page,
5953
}),
60-
placeholderData: keepPreviousData,
6154
enabled: !!address && !!clientId,
6255
});
6356
}
6457

58+
// TODO: fetching list of all users needs to be improved
6559
export function useAllEmbeddedWallets(params: {
6660
authToken: string;
6761
}) {
@@ -70,15 +64,13 @@ export function useAllEmbeddedWallets(params: {
7064
const address = useActiveAccount()?.address;
7165

7266
return useMutation({
73-
mutationFn: async ({
74-
clientId,
75-
totalPages,
76-
}: { clientId: string; totalPages: number }) => {
77-
const walletRes = [];
78-
for (let page = 1; page <= totalPages; page++) {
79-
const res = queryClient.fetchQuery<{
67+
mutationFn: async ({ clientId }: { clientId: string }) => {
68+
const responses: WalletUser[] = [];
69+
let page = 1;
70+
71+
while (true) {
72+
const res = await queryClient.fetchQuery<{
8073
users: WalletUser[];
81-
totalPages: number;
8274
}>({
8375
queryKey: embeddedWalletsKeys.embeddedWallets(
8476
address || "",
@@ -91,9 +83,16 @@ export function useAllEmbeddedWallets(params: {
9183
pageNumber: page,
9284
}),
9385
});
94-
walletRes.push(res);
86+
87+
if (res.users.length === 0) {
88+
break;
89+
}
90+
91+
page++;
92+
responses.push(...res.users);
9593
}
96-
return (await Promise.all(walletRes)).flatMap((res) => res.users);
94+
95+
return responses;
9796
},
9897
});
9998
}

apps/dashboard/src/components/embedded-wallets/Users/index.tsx

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use client";
22

33
import { WalletAddress } from "@/components/blocks/wallet-address";
4-
import { PaginationButtons } from "@/components/pagination-buttons";
54
import { Spinner } from "@/components/ui/Spinner/Spinner";
65
import { Button } from "@/components/ui/button";
76
import {
@@ -17,6 +16,7 @@ import {
1716
import { createColumnHelper } from "@tanstack/react-table";
1817
import { TWTable } from "components/shared/TWTable";
1918
import { format } from "date-fns/format";
19+
import { ArrowLeft, ArrowRight } from "lucide-react";
2020
import Papa from "papaparse";
2121
import { useCallback, useState } from "react";
2222
import type { WalletUser } from "thirdweb/wallets";
@@ -97,21 +97,18 @@ const columns = [
9797
}),
9898
];
9999

100-
export const InAppWalletUsersPageContent = (props: {
100+
export function InAppWalletUsersPageContent(props: {
101101
clientId: string;
102102
trackingCategory: string;
103103
authToken: string;
104-
}) => {
104+
}) {
105105
const [activePage, setActivePage] = useState(1);
106106
const walletsQuery = useEmbeddedWallets({
107107
authToken: props.authToken,
108108
clientId: props.clientId,
109109
page: activePage,
110110
});
111-
const { users: wallets, totalPages } = walletsQuery?.data || {
112-
users: [],
113-
totalPages: 1,
114-
};
111+
const wallets = walletsQuery?.data?.users || [];
115112
const { mutateAsync: getAllEmbeddedWallets, isPending } =
116113
useAllEmbeddedWallets({
117114
authToken: props.authToken,
@@ -123,7 +120,6 @@ export const InAppWalletUsersPageContent = (props: {
123120
}
124121
const usersWallets = await getAllEmbeddedWallets({
125122
clientId: props.clientId,
126-
totalPages,
127123
});
128124
const csv = Papa.unparse(
129125
usersWallets.map((row) => {
@@ -144,13 +140,13 @@ export const InAppWalletUsersPageContent = (props: {
144140
tempLink.href = csvUrl;
145141
tempLink.setAttribute("download", "download.csv");
146142
tempLink.click();
147-
}, [wallets, props.clientId, totalPages, getAllEmbeddedWallets]);
143+
}, [wallets, props.clientId, getAllEmbeddedWallets]);
148144

149145
return (
150146
<div>
151-
<div className="flex flex-col gap-6">
147+
<div className="flex flex-col gap-4">
152148
{/* Top section */}
153-
<div className="flex items-center justify-between">
149+
<div className="flex items-center justify-end">
154150
<Button
155151
disabled={wallets.length === 0 || isPending}
156152
variant="outline"
@@ -161,35 +157,42 @@ export const InAppWalletUsersPageContent = (props: {
161157
{isPending && <Spinner className="size-4" />}
162158
Download as .csv
163159
</Button>
164-
165-
<div className="flex items-center justify-end gap-2">
166-
{walletsQuery.isPlaceholderData && (
167-
<>
168-
<Spinner className="size-4" />
169-
<p className="text-muted-foreground text-sm">
170-
Loading page {activePage} of {totalPages}
171-
</p>
172-
</>
173-
)}
174-
</div>
175160
</div>
176161

177-
<TWTable
178-
title="in-app wallets"
179-
data={wallets}
180-
columns={columns}
181-
isPending={walletsQuery.isPending}
182-
isFetched={walletsQuery.isFetched}
183-
/>
184-
185-
{totalPages > 1 && (
186-
<PaginationButtons
187-
activePage={activePage}
188-
onPageClick={setActivePage}
189-
totalPages={totalPages}
162+
<div>
163+
<TWTable
164+
title="in-app wallets"
165+
data={wallets}
166+
columns={columns}
167+
isPending={walletsQuery.isPending}
168+
isFetched={walletsQuery.isFetched}
169+
tableContainerClassName="rounded-b-none"
190170
/>
191-
)}
171+
172+
<div className="flex justify-center gap-3 rounded-b-lg border border-t-0 bg-card p-6">
173+
<Button
174+
variant="outline"
175+
size="sm"
176+
className="gap-2 bg-background"
177+
onClick={() => setActivePage((p) => Math.max(1, p - 1))}
178+
disabled={activePage === 1 || walletsQuery.isPending}
179+
>
180+
<ArrowLeft className="size-4" />
181+
Previous
182+
</Button>
183+
<Button
184+
variant="outline"
185+
size="sm"
186+
className="gap-2 bg-background"
187+
onClick={() => setActivePage((p) => p + 1)}
188+
disabled={wallets.length === 0 || walletsQuery.isPending}
189+
>
190+
Next
191+
<ArrowRight className="size-4" />
192+
</Button>
193+
</div>
194+
</div>
192195
</div>
193196
</div>
194197
);
195-
};
198+
}

apps/dashboard/src/components/shared/TWTable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,10 @@ export function TWTable<TRowData>(tableProps: TWTableProps<TRowData>) {
252252
{!tableProps.isPending &&
253253
tableProps.data.length === 0 &&
254254
tableProps.isFetched && (
255-
<div className="flex items-center justify-center">
255+
<div className="flex items-center justify-center py-16">
256256
<div className="flex items-center gap-4 py-4">
257257
<p className="text-muted-foreground text-sm">
258-
No {pluralize(tableProps.title, 0, false)} found.
258+
No {pluralize(tableProps.title, 0, false)} found
259259
</p>
260260
</div>
261261
</div>

0 commit comments

Comments
 (0)