Skip to content

Commit

Permalink
resolve comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zklink committed Jun 21, 2024
1 parent ff5c4a3 commit e9c57bc
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/common/response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ResponseDto<T> {

@ApiProperty({
type: Number,
description: "elPoints and kelpMiles",
description: "total points",
example: 437936.342254,
required: false,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const categoryConfig = [
const categoryBaseConfig = [
{
name: "spotdex",
items: ["novaswap", "izumi", "wagmi", "eddyFinance"],
Expand All @@ -20,3 +20,15 @@ export const categoryConfig = [
items: ["rubic", "interport", "orbiter", "symbiosis", "meson"],
},
];

const projectCategoryConfig = [];
for (const category of categoryBaseConfig) {
for (const project of category.items) {
projectCategoryConfig.push({
category: category.name,
project: project,
});
}
}

export default projectCategoryConfig;
20 changes: 9 additions & 11 deletions src/nova/nova.balance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PointsOfLpRepository } from "src/repositories/pointsOfLp.repository";
import { PointsOfLp } from "src/entities/pointsOfLp.entity";
import { BlockAddressPointOfLpRepository } from "src/repositories/blockAddressPointOfLp.repository";
import { BalanceOfLpRepository } from "src/repositories/balanceOfLp.repository";
import { categoryConfig } from "src/projectCategory.config";
import projectCategoryConfig from "src/config/projectCategory.config";
import { ProjectCategoryPoints } from "src/type/points";

interface ProjectPoints {
Expand Down Expand Up @@ -237,16 +237,14 @@ export class NovaBalanceService {
projectPointsMap.set(item.name, Number(item.totalPoints));
}
const projectCategoryPoints: ProjectCategoryPoints[] = [];
for (const category of categoryConfig) {
for (const project of category.items) {
const totalPoints = projectPointsMap.get(project);
projectCategoryPoints.push({
category: category.name,
project: project,
holdingPoints: totalPoints ? totalPoints : 0,
refPoints: 0,
});
}
for (const item of projectCategoryConfig) {
const totalPoints = projectPointsMap.get(item.project);
projectCategoryPoints.push({
category: item.category,
project: item.project,
holdingPoints: totalPoints ? totalPoints : 0,
refPoints: 0,
});
}
return projectCategoryPoints;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tvl/tvl.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class TvlController {
@Get("/category")
@ApiOperation({ summary: "Get token personal points" })
public async getNovaPoints(): Promise<ResponseDto<CategoryTvlDto[]>> {
const data = await this.tvlService.getProjectTvl();
const data = await this.tvlService.getCategoryTvl();
return {
errno: 0,
errmsg: "no error",
Expand Down
28 changes: 14 additions & 14 deletions src/tvl/tvl.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable, Logger } from "@nestjs/common";
import { ProjectRepository } from "src/repositories/project.repository";
import { categoryConfig } from "src/projectCategory.config";
import projectCategoryConfig from "src/config/projectCategory.config";
import { CategoryTvl } from "src/type/points";
import BigNumber from "bignumber.js";

Expand All @@ -12,27 +12,27 @@ export class TvlService {
this.logger = new Logger(TvlService.name);
}

public async getProjectTvl(): Promise<CategoryTvl[]> {
public async getCategoryTvl(): Promise<CategoryTvl[]> {
const projectsTvl = await this.projectRepository.getAllProjectsTvl();
const projectsTvlMap = new Map<string, BigNumber>();
for (const project of projectsTvl) {
projectsTvlMap.set(project.name, project.tvl);
}
const categoryTvlMap: Map<string, BigNumber> = new Map();
for (const category of categoryConfig) {
categoryTvlMap.set(category.name, new BigNumber(0));
for (const project of category.items) {
const projectTvl = projectsTvlMap.get(project) ?? new BigNumber(0);
categoryTvlMap.set(
category.name,
categoryTvlMap.get(category.name).plus(projectTvl),
);
for (const item of projectCategoryConfig) {
if (!categoryTvlMap.has(item.category)) {
categoryTvlMap.set(item.category, new BigNumber(0));
}
const projectTvl = projectsTvlMap.get(item.project) ?? new BigNumber(0);
categoryTvlMap.set(
item.category,
categoryTvlMap.get(item.category).plus(projectTvl),
);
}
const categoryTvl: CategoryTvl[] = [];
for (const [category, tvl] of categoryTvlMap) {
categoryTvl.push({ name: category, tvl });
}
const categoryTvl = Array.from(categoryTvlMap, ([name, tvl]) => ({
name,
tvl,
}));
return categoryTvl;
}
}

0 comments on commit e9c57bc

Please sign in to comment.