Skip to content

Commit

Permalink
use BASE_URL instead of multiple instances of the the base url
Browse files Browse the repository at this point in the history
  • Loading branch information
ribeirojose committed Aug 30, 2023
1 parent 0e1eaa9 commit 5b19bff
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
3 changes: 2 additions & 1 deletion apps/balancer-tools/src/app/apr/api/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { fetcher } from "#/utils/fetcher";
import { calculatePoolStats } from "../(utils)/calculatePoolStats";
import { Round } from "../(utils)/rounds";

const BASE_URL = process.env.NEXT_PUBLIC_SITE_URL;
export const BASE_URL =
process.env.NEXT_PUBLIC_SITE_URL ?? process.env.NEXT_PUBLIC_VERCEL_URL;

type Order = "asc" | "desc";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PlotType } from "plotly.js";
import { trimTrailingValues } from "#/lib/utils";
import { fetcher } from "#/utils/fetcher";

import { PoolStatsResults } from "../../api/route";
import { BASE_URL, PoolStatsResults } from "../../api/route";
import HistoricalAPRPlot from "./HistoricalAPRPlot";

const getRoundName = (roundId?: string | number) =>
Expand All @@ -20,7 +20,7 @@ export default async function HistoricalAPRChart({
const HOVERTEMPLATE = "%{x}<br />%{y:.2f}% APR<extra></extra>";

const results: PoolStatsResults = await fetcher(
`${process.env.NEXT_PUBLIC_SITE_URL}/apr/api/?poolId=${poolId}&sort=roundId`,
`${BASE_URL}/apr/api/?poolId=${poolId}&sort=roundId`,
);

const aprPerRoundCords = Object.entries(results.perRound).reduce(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import OverviewCards, {
} from "../../(components)/OverviewCards";
import { calculatePoolStats } from "../../(utils)/calculatePoolStats";
import { formatAPR, formatTVL } from "../../(utils)/formatPoolStats";
import { PoolStatsResults } from "../../api/route";
import { BASE_URL, PoolStatsResults } from "../../api/route";

async function AverageTVLCard({ poolId }: { poolId: string }) {
const data: PoolStatsResults = await fetcher(
`${process.env.NEXT_PUBLIC_SITE_URL}/apr/api/?poolId=${poolId}`,
`${BASE_URL}/apr/api/?poolId=${poolId}`,
);
return <div>{formatTVL(data.average.tvl)}</div>;
}

async function AverageAPRCard({ poolId }: { poolId: string }) {
const data: PoolStatsResults = await fetcher(
`${process.env.NEXT_PUBLIC_SITE_URL}/apr/api/?poolId=${poolId}`,
`${BASE_URL}/apr/api/?poolId=${poolId}`,
);
return <div>{formatAPR(data.average.apr)}</div>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { formatNumber } from "#/utils/formatNumber";

import { PoolTypeEnum } from "../../(utils)/calculatePoolStats";
import { formatAPR, formatTVL } from "../../(utils)/formatPoolStats";
import { PoolStatsData, PoolStatsResults } from "../../api/route";
import { BASE_URL, PoolStatsData, PoolStatsResults } from "../../api/route";

export function PoolListTable({
roundId,
Expand Down Expand Up @@ -71,9 +71,7 @@ export function PoolListTable({
const loadMorePools = async () => {
setIsLoadingMore(true);
const aditionalPoolsData = await fetcher<PoolStatsResults>(
`${
process.env.NEXT_PUBLIC_SITE_URL
}/apr/api/?roundId=${roundId}&sort=${sortField}&order=${order}&limit=10&offset=${
`${BASE_URL}/apr/api/?roundId=${roundId}&sort=${sortField}&order=${order}&limit=10&offset=${
Object.keys(tableData).length
}&minTvl=1000`,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fetcher } from "#/utils/fetcher";

import { PoolStatsResults } from "../../api/route";
import { BASE_URL, PoolStatsResults } from "../../api/route";
import { PoolListTable } from "./PoolListTable";

export default async function PoolTableWrapper({
Expand All @@ -9,7 +9,7 @@ export default async function PoolTableWrapper({
roundId: string;
}) {
const initialData = await fetcher<PoolStatsResults>(
`${process.env.NEXT_PUBLIC_SITE_URL}/apr/api/?roundId=${roundId}&sort=apr&limit=10&order=desc&minTvl=1000`,
`${BASE_URL}/apr/api/?roundId=${roundId}&sort=apr&limit=10&order=desc&minTvl=1000`,
);
return <PoolListTable roundId={roundId} initialData={initialData} />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { PlotType } from "plotly.js";
import Plot from "#/components/Plot";
import { fetcher } from "#/utils/fetcher";

import { PoolStatsResults } from "../../api/route";
import { BASE_URL, PoolStatsResults } from "../../api/route";

export default async function TopPoolsChart({ roundId }: { roundId: string }) {
const shades = Object.values(greenDarkA).map((color) => color.toString());
const colors = [...shades.slice(4, 10).reverse(), ...shades.slice(4, 10)];

const topAprApi = await fetcher<PoolStatsResults>(
`${process.env.NEXT_PUBLIC_SITE_URL}/apr/api/?roundId=${roundId}&sort=apr&limit=10&order=desc&minTvl=1000`,
`${BASE_URL}/apr/api/?roundId=${roundId}&sort=apr&limit=10&order=desc&minTvl=1000`,
);

const chartData = {
Expand Down

0 comments on commit 5b19bff

Please sign in to comment.