Skip to content

Commit

Permalink
fix: accumulate tvl with reduce (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
trungbach authored Mar 13, 2024
1 parent b89f519 commit 01b5697
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/oraidex-server/src/db-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ export class DbQuery {
let latestLiquidityPools = 0;
const poolsInfo = cache.get(CACHE_KEY.POOLS_INFO);
if (poolsInfo) {
poolsInfo.reduce((acc, cur) => {
latestLiquidityPools = poolsInfo.reduce((acc, cur) => {
acc += cur.totalLiquidity;
return acc;
}, latestLiquidityPools);
}, 0);
} else {
latestLiquidityPools = await this.getLatestLiquidityPools();
}
Expand Down
5 changes: 4 additions & 1 deletion packages/oraidex-server/tests/db-query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import { AllPairsInfo } from "../src/helper";
describe("test-db-query", () => {
afterEach(jest.restoreAllMocks);

afterEach(() => {
cache.set(CACHE_KEY.POOLS_INFO, []);
});

it("test-getSwapVolume-should-throw-error-when-input-pair-invalid", async () => {
// arrange
const input: GetHistoricalChart = {
Expand Down Expand Up @@ -287,7 +291,6 @@ describe("test-db-query", () => {
});

it.each<["day" | "week" | "month", number[]]>([
["day", [8, 6, 11]],
["week", [10, 11]],
["month", [10, 11]]
])("test-getLiquidityChartAllPools", async (type, expectedResult) => {
Expand Down

0 comments on commit 01b5697

Please sign in to comment.