From 507406e2de860040d300cdbd769180d786a1af10 Mon Sep 17 00:00:00 2001 From: iamsphere Date: Sun, 8 Dec 2024 13:43:45 +0400 Subject: [PATCH] Fix wrong weekly interest value, change formatting for sol values --- .../InstantLendTable/Summary.tsx | 20 +++++++++++++++++-- src/utils/tokens/constants.tsx | 12 +++++++---- src/utils/tokens/helpers.ts | 7 +++++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/pages/nftLending/LendPage/InstantLendContent/InstantLendTable/Summary.tsx b/src/pages/nftLending/LendPage/InstantLendContent/InstantLendTable/Summary.tsx index 6ef88d5bf..91180319d 100644 --- a/src/pages/nftLending/LendPage/InstantLendContent/InstantLendTable/Summary.tsx +++ b/src/pages/nftLending/LendPage/InstantLendContent/InstantLendTable/Summary.tsx @@ -1,7 +1,9 @@ import React, { FC, useMemo } from 'react' import { useWallet } from '@solana/wallet-adapter-react' +import { calculateCurrentInterestSolPure } from 'fbonds-core/lib/fbond-protocol/functions/perpetual' import { map, maxBy, sumBy } from 'lodash' +import moment from 'moment' import { Button } from '@banx/components/Buttons' import { CounterSlider } from '@banx/components/Slider' @@ -14,7 +16,6 @@ import { core } from '@banx/api/nft' import { SECONDS_IN_DAY } from '@banx/constants' import { useModal } from '@banx/store/common' import { - calcWeeklyInterestFee, calcWeightedAverage, calculateLendValue, calculateLenderApr, @@ -133,7 +134,22 @@ const calculateSummaryInfo = (loans: core.Loan[]) => { const totalDebt = sumBy(loans, (loan) => calculateLendValue(loan)) const totalLoanValue = map(loans, (loan) => calculateLendValue(loan)) - const totalWeeklyInterest = sumBy(loans, (loan) => calcWeeklyInterestFee(loan)) + const totalWeeklyInterest = sumBy(loans, (loan) => { + const isTerminatingStatus = isLoanTerminating(loan) + const aprRate = isTerminatingStatus + ? calculateLenderApr(loan) + : loan.bondTradeTransaction.amountOfBonds + + const repayValue = calculateLendValue(loan) + + const currentTimeInUnix = moment().unix() + return calculateCurrentInterestSolPure({ + loanValue: repayValue, + startTime: currentTimeInUnix, + currentTime: currentTimeInUnix + SECONDS_IN_DAY * 7, + rateBasePoints: aprRate, + }) + }) const totalAprArray = map(loans, (loan) => { const isTerminatingStatus = isLoanTerminating(loan) diff --git a/src/utils/tokens/constants.tsx b/src/utils/tokens/constants.tsx index cc2370b37..a2ad81c05 100644 --- a/src/utils/tokens/constants.tsx +++ b/src/utils/tokens/constants.tsx @@ -51,13 +51,15 @@ export const DECIMAL_PLACES_LIMITS = { ], [LendingTokenType.NativeSol]: [ { limit: 1000, decimalPlaces: 0 }, //? Values up to 1000 have 0 decimal places - { limit: 0.01, decimalPlaces: 2 }, //? Values up to 0.01 have 2 decimal places - { limit: 0, decimalPlaces: 3 }, //? Values greater than 0 but less than 0.01 have 3 decimal places + { limit: 0.1, decimalPlaces: 2 }, //? Values up to 0.1 have 2 decimal places + { limit: 0.01, decimalPlaces: 3 }, //? Values up to 0.01 have 3 decimal places + { limit: 0, decimalPlaces: 4 }, //? Values greater than 0 but less than 0.01 have 4 decimal places ], [LendingTokenType.BanxSol]: [ { limit: 1000, decimalPlaces: 0 }, //? Values up to 1000 have 0 decimal places - { limit: 0.01, decimalPlaces: 2 }, //? Values up to 0.01 have 2 decimal places - { limit: 0, decimalPlaces: 3 }, //? Values greater than 0 but less than 0.01 have 3 decimal places + { limit: 0.1, decimalPlaces: 2 }, //? Values up to 0.1 have 2 decimal places + { limit: 0.01, decimalPlaces: 3 }, //? Values up to 0.01 have 3 decimal places + { limit: 0, decimalPlaces: 4 }, //? Values greater than 0 but less than 0.01 have 4 decimal places ], } @@ -70,3 +72,5 @@ export const COLLATERAL_DECIMAL_PLACES_LIMITS = [ { limit: 0.01, decimalPlaces: 2 }, //? Values up to 0.01 have 2 decimal places { limit: 0, decimalPlaces: 3 }, //? Values greater than 0 but less than 0.01 have 3 decimal places ] + +export const COMMA_SEPARATION_THRESHOLD = 1000 diff --git a/src/utils/tokens/helpers.ts b/src/utils/tokens/helpers.ts index 7759e248e..eaef21d73 100644 --- a/src/utils/tokens/helpers.ts +++ b/src/utils/tokens/helpers.ts @@ -4,6 +4,7 @@ import { find, findIndex, repeat } from 'lodash' import { convertToDecimalString, formatNumbersWithCommas } from '../common' import { COLLATERAL_DECIMAL_PLACES_LIMITS, + COMMA_SEPARATION_THRESHOLD, DECIMAL_PLACES_LIMITS, DEFAULT_DECIMAL_PLACES, MIN_COLLATERAL_VALUE_TO_DISPLAY, @@ -43,8 +44,10 @@ export const formatDecimalWithoutTrailingZeros = ( } export const formatTokenValue = (value: number, tokenType: LendingTokenType): string => { - const formattedValueWithoutTrailingZeros = formatDecimalWithoutTrailingZeros(value, tokenType) - return formatNumbersWithCommas(formattedValueWithoutTrailingZeros) + const formattedValue = formatDecimalWithoutTrailingZeros(value, tokenType) + return value > COMMA_SEPARATION_THRESHOLD + ? formatNumbersWithCommas(formattedValue) + : formattedValue } export const getDecimalPlaces = (value: number, tokenType: LendingTokenType): number => {