Skip to content

Commit

Permalink
Interest rates brackets: avoid extra requests
Browse files Browse the repository at this point in the history
  • Loading branch information
bpierre committed Jan 22, 2025
1 parent 9d5e8d0 commit 6ab7ad3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 2 additions & 3 deletions frontend/app/src/liquity-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Config as WagmiConfig } from "wagmi";

import { DATA_REFRESH_INTERVAL, INTEREST_RATE_INCREMENT, INTEREST_RATE_MAX, INTEREST_RATE_MIN } from "@/src/constants";
import { getCollateralContract, getContracts, getProtocolContract } from "@/src/contracts";
import { dnum18 } from "@/src/dnum-utils";
import { dnum18, jsonStringifyWithDnum } from "@/src/dnum-utils";
import { CHAIN_BLOCK_EXPLORER } from "@/src/env";
import {
calculateStabilityPoolApr,
Expand Down Expand Up @@ -333,8 +333,7 @@ export function useInterestRateChartData(collIndex: null | CollIndex) {
queryKey: [
"useInterestRateChartData",
collIndex,
brackets.status,
brackets.dataUpdatedAt,
jsonStringifyWithDnum(brackets.data),
],
queryFn: () => {
if (!brackets.isSuccess) {
Expand Down
5 changes: 3 additions & 2 deletions frontend/app/src/subgraph-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { sleep } from "@/src/utils";
import { isAddress, shortenAddress } from "@liquity2/uikit";
import { useQuery } from "@tanstack/react-query";
import * as dn from "dnum";
import { useCallback } from "react";
import {
AllInterestRateBracketsQuery,
BorrowerInfoQuery,
Expand Down Expand Up @@ -402,7 +403,7 @@ export function useInterestRateBrackets(
return useQuery({
queryKey: ["AllInterestRateBrackets"],
queryFn,
select: (brackets) => {
select: useCallback((brackets: Awaited<ReturnType<typeof queryFn>>) => {
// only filter by collIndex in the select()
// so that we can query all the brackets at once
return brackets
Expand All @@ -412,7 +413,7 @@ export function useInterestRateBrackets(
rate: dnum18(bracket.rate),
totalDebt: dnum18(bracket.totalDebt),
}));
},
}, []),
...prepareOptions(options),
});
}
Expand Down

0 comments on commit 6ab7ad3

Please sign in to comment.