Skip to content

Commit f022834

Browse files
authored
use the pagination link directly for links.prev and links.next (#1959)
1 parent cafc321 commit f022834

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

src/app/(sidebar)/smart-contracts/contract-explorer/components/ContractStorage.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const ContractStorage = ({
5757
const { transaction } = useStore();
5858
const router = useRouter();
5959

60-
const [currentCursor, setCurrentCursor] = useState<string | undefined>();
60+
const [currentHref, setCurrentHref] = useState<string | undefined>();
6161
const [currentPage, setCurrentPage] = useState(1);
6262
const [sortBy, setSortBy] = useState<string>("updated_at");
6363
const [sortOrder, setSortOrder] = useState<"asc" | "desc">("desc");
@@ -67,7 +67,7 @@ export const ContractStorage = ({
6767
isActive: isActive && !isSourceStellarExpert,
6868
networkId,
6969
contractId,
70-
cursor: currentCursor,
70+
paginationHref: currentHref,
7171
sortBy,
7272
order: sortOrder,
7373
});
@@ -82,7 +82,7 @@ export const ContractStorage = ({
8282

8383
useEffect(() => {
8484
// Reset when contractId or networkId changes
85-
setCurrentCursor(undefined);
85+
setCurrentHref(undefined);
8686
setCurrentPage(1);
8787
setSortBy("updated_at");
8888
setSortOrder("desc");
@@ -148,12 +148,6 @@ export const ContractStorage = ({
148148
);
149149
}
150150

151-
const getCursorFromHref = (href: string) => {
152-
const queryString = href.split("?")[1] || "";
153-
const params = new URLSearchParams(queryString);
154-
return params.get("cursor") || undefined;
155-
};
156-
157151
const parsedKeyValueData = () => {
158152
return storageData.map((i) => ({
159153
...i,
@@ -325,7 +319,7 @@ export const ContractStorage = ({
325319
setSortOrder(dir);
326320
}
327321
// Reset pagination on sort change
328-
setCurrentCursor(undefined);
322+
setCurrentHref(undefined);
329323
setCurrentPage(1);
330324
},
331325
}
@@ -336,7 +330,7 @@ export const ContractStorage = ({
336330
prev: {
337331
onClick: () => {
338332
if (prevCursor) {
339-
setCurrentCursor(getCursorFromHref(prevCursor));
333+
setCurrentHref(prevCursor);
340334
setCurrentPage(Math.max(currentPage - 1, 1));
341335
}
342336
},
@@ -346,7 +340,7 @@ export const ContractStorage = ({
346340
next: {
347341
onClick: () => {
348342
if (nextCursor) {
349-
setCurrentCursor(getCursorFromHref(nextCursor));
343+
setCurrentHref(nextCursor);
350344
setCurrentPage(currentPage + 1);
351345
}
352346
},

src/query/external/useBackendContractStorage.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ export const useBackendContractStorage = ({
88
isActive,
99
networkId,
1010
contractId,
11-
cursor,
11+
paginationHref,
1212
sortBy,
1313
order,
1414
}: {
1515
isActive: boolean;
1616
networkId: NetworkType;
1717
contractId: string;
18-
cursor?: string;
18+
paginationHref?: string;
1919
sortBy?: string;
2020
order?: "asc" | "desc";
2121
}) => {
@@ -24,18 +24,24 @@ export const useBackendContractStorage = ({
2424
"useBackendContractStorage",
2525
networkId,
2626
contractId,
27-
cursor,
27+
paginationHref,
2828
{ sortBy, order },
2929
],
3030
queryFn: async () => {
31-
const network = networkId === "mainnet" ? "pubnet" : networkId;
32-
const params = new URLSearchParams({
33-
limit: "10",
34-
sort_by: sortBy ?? "updated_at",
35-
order: order ?? "desc",
36-
});
37-
if (cursor) params.set("cursor", cursor);
38-
const fetchUrl = `${BACKEND_ENDPOINT}/${network}/api/contract/${contractId}/storage?${params}`;
31+
let fetchUrl: string;
32+
33+
if (paginationHref) {
34+
const url = new URL(paginationHref, BACKEND_ENDPOINT);
35+
fetchUrl = url.toString();
36+
} else {
37+
const network = networkId === "mainnet" ? "pubnet" : networkId;
38+
const params = new URLSearchParams({
39+
limit: "10",
40+
sort_by: sortBy ?? "updated_at",
41+
order: order ?? "desc",
42+
});
43+
fetchUrl = `${BACKEND_ENDPOINT}/${network}/api/contract/${contractId}/storage?${params}`;
44+
}
3945

4046
const response = await fetch(fetchUrl);
4147

0 commit comments

Comments
 (0)