Skip to content

Commit

Permalink
Merge pull request #41 from invariant-labs/add-pagination
Browse files Browse the repository at this point in the history
Add pagination to API
  • Loading branch information
Sniezka1927 authored Dec 16, 2024
2 parents 71357fe + 4585d57 commit 85b0437
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions api/[net]/[address].ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { VercelRequest, VercelResponse } from "@vercel/node";
import ECLIPSE_TESTNET_DATA from "../../data/final_data_testnet.json";
import ECLIPSE_MAINNET_DATA from "../../data/final_data_mainnet.json";
import { BN } from "@coral-xyz/anchor";

interface IData {
user: {
Expand Down Expand Up @@ -43,6 +42,7 @@ export default function (req: VercelRequest, res: VercelResponse) {
);

const { net, address } = req.query;

const pubkey = address as string;
let currentData: ICachedData[];

Expand All @@ -54,11 +54,16 @@ export default function (req: VercelRequest, res: VercelResponse) {
return res.status(400).send("INVALID NETWORK");
}

const offset = Number(req.query.offset) || 0;
const size = Number(req.query.size) || undefined;
const userItem = currentData.find((item) => item.address === pubkey);
const userData = address && userItem ? userItem : null;
const finalData: IData = {
user: userData ? { ...userData } : null,
leaderboard: currentData,
leaderboard: currentData.slice(
offset,
size ? offset + size : currentData.length
),
};

res.json(finalData);
Expand Down
2 changes: 1 addition & 1 deletion data/events_snap_testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -899,4 +899,4 @@
],
"closed": []
}
}
}
2 changes: 1 addition & 1 deletion data/previous_config_testnet.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"lastTxHash": "3TXmTyeNnrGjWpM2ZhYSzWqcsXmUdzXxaLQm6K7T8WqvyLBv6MZMmbQq7NL9bwwPS83uZowLaX7jQ5xM4SpML4nQ"
}
}

0 comments on commit 85b0437

Please sign in to comment.