Skip to content

Commit

Permalink
[APR] use getfilterdatafromparams when making a request (#334)
Browse files Browse the repository at this point in the history
* Refactor getFilteredRoundApiUrl args

* Apply getFilteredRoundApiUrl on remaining components
  • Loading branch information
Rawallon authored Sep 26, 2023
1 parent 49fdf22 commit 2bb2693
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
9 changes: 6 additions & 3 deletions apps/balancer-tools/src/app/apr/(utils)/getFilteredApiUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,18 @@ function getFilterDataFromParams(searchParams: SearchParams) {
}

export default function getFilteredRoundApiUrl(
searchParams: SearchParams,
startAt: Date,
endAt: Date,
searchParams?: SearchParams | null,
poolId?: string,
) {
const filteredData = getFilterDataFromParams(searchParams);
const filteredData = getFilterDataFromParams(searchParams ?? {});
const params = Object.entries(filteredData)
.map(([key, value]) => (value !== undefined ? `${key}=${value}` : ""))
.join("&");
return `${BASE_URL}/apr/api?startAt=${formatDateToMMDDYYYY(
startAt,
)}&endAt=${formatDateToMMDDYYYY(endAt)}&${params}`;
)}&endAt=${formatDateToMMDDYYYY(endAt)}${
poolId ? `&poolId=${poolId}` : ""
}&${params}`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const computeAverages = (formattedPoolData: {
}

// @ts-ignore - Need help with this typing!
return { perDay: formattedPoolData, average: averages };
return averages;
};

function calculateAverageForObject(
Expand Down
2 changes: 1 addition & 1 deletion apps/balancer-tools/src/app/apr/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function Page({
return redirect("/apr/");
}

const url = getFilteredRoundApiUrl(searchParams, startAtDate, endAtDate);
const url = getFilteredRoundApiUrl(startAtDate, endAtDate, searchParams);

return (
<div className="flex flex-1 flex-col gap-y-3">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BASE_URL } from "#/app/apr/(utils)/types";
import { formatDateToMMDDYYYY } from "#/app/apr/api/(utils)/date";
import getFilteredRoundApiUrl from "#/app/apr/(utils)/getFilteredApiUrl";
import { PoolStatsData, PoolStatsResults } from "#/app/apr/api/route";
import { trimTrailingValues } from "#/lib/utils";
import { fetcher } from "#/utils/fetcher";
Expand All @@ -16,9 +15,7 @@ export default async function HistoricalCharts({
poolId?: string;
}) {
const results: PoolStatsResults = await fetcher(
`${BASE_URL}/apr/api/?poolId=${poolId}&startAt=${formatDateToMMDDYYYY(
startAt,
)}&endAt=${formatDateToMMDDYYYY(endAt)}`,
getFilteredRoundApiUrl(startAt, endAt, null, poolId),
);

return <HistoricalChart apiResult={results} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import OverviewCards, {
getDatesDetails,
} from "../../(components)/OverviewCards";
import { formatAPR, formatTVL } from "../../(utils)/formatPoolStats";
import { BASE_URL } from "../../(utils)/types";
import getFilteredRoundApiUrl from "../../(utils)/getFilteredApiUrl";
import { PoolStatsResults } from "../../api/route";

export default async function PoolOverviewCards({
Expand All @@ -22,9 +22,8 @@ export default async function PoolOverviewCards({
tooltip?: string;
}[] = [];
const results: PoolStatsResults = await fetcher(
`${BASE_URL}/apr/api/?poolId=${poolId}&startAt${startAt}&endAt=${endAt}`,
getFilteredRoundApiUrl(startAt, endAt, null, poolId),
);

cardsDetails.push(
...[
{ title: "Avg. TVL", content: formatTVL(results.average.tvl) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function PoolListTable({
const params = Object.fromEntries(searchParams.entries());
params["offset"] = (tableData.length + 1).toString();

const url = new URL(getFilteredRoundApiUrl(params, startAt, endAt));
const url = new URL(getFilteredRoundApiUrl(startAt, endAt, params));
const aditionalPoolsData = await fetcher<PoolStatsResults>(
url.pathname + url.search,
);
Expand Down

0 comments on commit 2bb2693

Please sign in to comment.