From 831adf577b30f4405c7f8527498803f1e88ef645 Mon Sep 17 00:00:00 2001 From: Kozer4 Date: Mon, 24 Jun 2024 15:01:37 +0300 Subject: [PATCH] fix(apr): aprs type number -> string --- .../tokens-info/TokenInfoWithChainDetails-TRX.json | 4 ++-- src/__tests__/utils/calculation/index.test.ts | 14 +++++++------- src/client/core-api/core-api.model.ts | 8 ++++---- src/index.ts | 2 +- src/services/index.ts | 2 +- src/tokens-info/tokens-info.model.ts | 8 ++++---- src/utils/calculation/index.ts | 4 ++-- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/__tests__/data/tokens-info/TokenInfoWithChainDetails-TRX.json b/src/__tests__/data/tokens-info/TokenInfoWithChainDetails-TRX.json index 764b6ac6..e16eab0e 100644 --- a/src/__tests__/data/tokens-info/TokenInfoWithChainDetails-TRX.json +++ b/src/__tests__/data/tokens-info/TokenInfoWithChainDetails-TRX.json @@ -6,8 +6,8 @@ "decimals": 18, "symbol": "YARO", "feeShare": "0.003", - "apr": 0, - "lpRate": 1.00000007, + "apr": "0", + "lpRate": "1.00000007", "chainSymbol": "TRX", "chainType": "TRX", "allbridgeChainId": 4, diff --git a/src/__tests__/utils/calculation/index.test.ts b/src/__tests__/utils/calculation/index.test.ts index a12a7358..197f4b33 100644 --- a/src/__tests__/utils/calculation/index.test.ts +++ b/src/__tests__/utils/calculation/index.test.ts @@ -90,10 +90,10 @@ describe("Calculation", () => { name: "name", poolAddress: "poolAddress", tokenAddress: "tokenAddress", - apr: 0, - apr7d: 0, - apr30d: 0, - lpRate: 0, + apr: "0", + apr7d: "0", + apr30d: "0", + lpRate: "0", }; describe("Given token with a balanced poolInfo", () => { @@ -241,11 +241,11 @@ describe("Calculation", () => { describe("aprInPercents", () => { test("convert apr to percent view", () => { - expect(aprInPercents(0.1256)).toEqual("12.56%"); + expect(aprInPercents("0.1256")).toEqual("12.56%"); }); test("invalid apr to percent view", () => { - expect(aprInPercents(0)).toEqual("N/A"); - expect(aprInPercents(-1)).toEqual("N/A"); + expect(aprInPercents("0")).toEqual("N/A"); + expect(aprInPercents("-1")).toEqual("N/A"); }); }); }); diff --git a/src/client/core-api/core-api.model.ts b/src/client/core-api/core-api.model.ts index 17605154..12169a45 100644 --- a/src/client/core-api/core-api.model.ts +++ b/src/client/core-api/core-api.model.ts @@ -29,10 +29,10 @@ export interface TokenDTO { tokenAddress: string; poolInfo: PoolInfoDTO; feeShare: string; - apr: number; - apr7d: number; - apr30d: number; - lpRate: number; + apr: string; + apr7d: string; + apr30d: string; + lpRate: string; } export interface PoolInfoDTO { diff --git a/src/index.ts b/src/index.ts index 3f1c166c..70eb0a09 100644 --- a/src/index.ts +++ b/src/index.ts @@ -492,7 +492,7 @@ export class AllbridgeCoreSdk { * @param apr * @returns aprPercentageView */ - aprInPercents(apr: number): string { + aprInPercents(apr: string): string { return this.service.aprInPercents(apr); } diff --git a/src/services/index.ts b/src/services/index.ts index 8802267f..6309f4f4 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -466,7 +466,7 @@ export class AllbridgeCoreSdkService { return this.api.refreshPoolInfo(); } - aprInPercents(apr: number): string { + aprInPercents(apr: string): string { return aprInPercents(apr); } diff --git a/src/tokens-info/tokens-info.model.ts b/src/tokens-info/tokens-info.model.ts index 93fdc3db..39826153 100644 --- a/src/tokens-info/tokens-info.model.ts +++ b/src/tokens-info/tokens-info.model.ts @@ -88,19 +88,19 @@ export interface Token { * @Deprecated use {@link apr7d}
* Token APR */ - apr: number; + apr: string; /** * Token APR based on last 7 days */ - apr7d: number; + apr7d: string; /** * Token APR based on last 30 days */ - apr30d: number; + apr30d: string; /** * Token LP rate */ - lpRate: number; + lpRate: string; } /** diff --git a/src/utils/calculation/index.ts b/src/utils/calculation/index.ts index 9c012ff7..f8298793 100644 --- a/src/utils/calculation/index.ts +++ b/src/utils/calculation/index.ts @@ -174,8 +174,8 @@ export function getEarned(userLpAmount: string, userRewardDebt: string, accRewar return rewards.sub(userRewardDebtBN).toString(); } -export function aprInPercents(apr: number): string { - return apr * 100 > 0 ? `${Number(Big(apr).times(100).toFixed(2)).toLocaleString()}%` : "N/A"; +export function aprInPercents(apr: string): string { + return Big(apr).gt(0) ? `${Number(Big(apr).times(100).toFixed(2)).toLocaleString()}%` : "N/A"; } // a = 8Axy(x+y)