Skip to content

Commit

Permalink
APR: redirect to correct network when poolid is accessed in the (#548)
Browse files Browse the repository at this point in the history
* update to node 20.9.0

* apr: redirect to correct pool network page when wrong network selected in url

* apr: hide subplots whose values are all 0
  • Loading branch information
ribeirojose authored Dec 22, 2023
1 parent d5a1b71 commit 1f4214d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nodejs 18.14.0
nodejs 20.9.0
6 changes: 4 additions & 2 deletions apps/balancer-tools/src/app/apr/(utils)/getFilteredUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ export function generatePoolPageLink(
endAt: Date,
searchParams?: SearchParams | null,
poolId?: string,
network?: string,
) {
const queryParams = generateQueryParams(startAt, endAt, searchParams);
if (poolId) {
const network = networkFor(new Pool(poolId).network);
return `/apr/pool/${network}/${poolId}?startAt=${formatDateToMMDDYYYY(
return `/apr/pool/${
network || networkFor(new Pool(poolId).network)
}/${poolId}?startAt=${formatDateToMMDDYYYY(
startAt,
)}&endAt=${formatDateToMMDDYYYY(endAt)}`;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { PoolStatsResults } from "#/app/apr/(utils)/fetchDataTypes";

import { generateAprCords } from "..";

const isAllZeroYValues = (data: { y: number[] }) =>
data.y.every((value) => value === 0);

export default function formatAPRChartData(
results: PoolStatsResults,
yaxis: string,
Expand Down Expand Up @@ -48,6 +51,7 @@ export default function formatAPRChartData(
hovertemplate: HOVERTEMPLATE,
x: vebalAprData.x,
y: vebalAprData.y,
visible: isAllZeroYValues(vebalAprData) ? ("legendonly" as const) : true,
line: { shape: "linear", color: blueDarkA.blueA9 } as const,
type: "scatter" as PlotType,
};
Expand All @@ -58,6 +62,7 @@ export default function formatAPRChartData(
hovertemplate: HOVERTEMPLATE,
x: feeAprData.x,
y: feeAprData.y,
visible: isAllZeroYValues(feeAprData) ? ("legendonly" as const) : true,
line: { shape: "linear", color: greenDarkA.greenA9 } as const,
type: "scatter" as PlotType,
};
Expand All @@ -68,6 +73,9 @@ export default function formatAPRChartData(
hovertemplate: HOVERTEMPLATE,
x: tokenTotalAprData.x,
y: tokenTotalAprData.y,
visible: isAllZeroYValues(tokenTotalAprData)
? ("legendonly" as const)
: true,
line: { shape: "linear", color: violetDarkA.violetA9 } as const,
type: "scatter" as PlotType,
};
Expand All @@ -78,6 +86,9 @@ export default function formatAPRChartData(
hovertemplate: HOVERTEMPLATE,
x: rewardsTotalAprData.x,
y: rewardsTotalAprData.y,
visible: isAllZeroYValues(rewardsTotalAprData)
? ("legendonly" as const)
: true,
line: { shape: "linear", color: yellowDarkA.yellowA9 } as const,
type: "scatter" as PlotType,
};
Expand All @@ -88,6 +99,7 @@ export default function formatAPRChartData(
hovertemplate: HOVERTEMPLATE,
x: totalAprData.x,
y: totalAprData.y,
visible: isAllZeroYValues(totalAprData) ? ("legendonly" as const) : true,
line: { shape: "linear", color: whiteA.whiteA9 } as const,
type: "scatter" as PlotType,
};
Expand All @@ -106,6 +118,9 @@ export default function formatAPRChartData(
hovertemplate: HOVERTEMPLATE,
x: trimmedTokenAprData.x,
y: trimmedTokenAprData.y,
visible: isAllZeroYValues(trimmedTokenAprData)
? ("legendonly" as const)
: true,
line: { shape: "linear", color: "rgba(0,0,0,0);" } as const,
type: "scatter" as PlotType,
};
Expand All @@ -125,6 +140,9 @@ export default function formatAPRChartData(
hovertemplate: HOVERTEMPLATE,
x: trimmedTokenAprData.x,
y: trimmedTokenAprData.y,
visible: isAllZeroYValues(trimmedTokenAprData)
? ("legendonly" as const)
: true,
line: { shape: "linear", color: "rgba(0,0,0,0);" } as const,
type: "scatter" as PlotType,
};
Expand Down
20 changes: 18 additions & 2 deletions apps/balancer-tools/src/app/apr/pool/[network]/[poolId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ export async function generateMetadata(
}

export default async function Page({
params: { poolId },
params: { poolId, network },
searchParams,
}: {
searchParams: SearchParams;
params: { poolId: string };
params: { poolId: string; network: string };
}) {
const parsedParams = QueryParamsPagesSchema.safeParse(searchParams);

Expand Down Expand Up @@ -86,6 +86,22 @@ export default async function Page({
endAtDate,
);

const actualNetwork = Object.values(poolData.perDay[0])[0].network;

if (actualNetwork !== network) {
return redirect(
generatePoolPageLink(
startAtDate,
endAtDate,
{
...searchParams,
},
poolId,
actualNetwork,
),
);
}

return (
<div className="flex flex-1 h-full w-full flex-col justify-start rounded-3xl text-white gap-y-3 mb-4">
<Breadcrumb />
Expand Down

0 comments on commit 1f4214d

Please sign in to comment.