From b753a5212bc2a740143a64622871aabeb6e988db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nandy=20B=C3=A2?= Date: Thu, 29 Aug 2024 01:19:00 +0900 Subject: [PATCH] fix: VEFA Realtime APR --- src/hooks/useFullyRentedAPR.ts | 40 ++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/hooks/useFullyRentedAPR.ts b/src/hooks/useFullyRentedAPR.ts index 33f59da..7026af6 100644 --- a/src/hooks/useFullyRentedAPR.ts +++ b/src/hooks/useFullyRentedAPR.ts @@ -12,17 +12,9 @@ import { const fullyRentedAPREstimation = (token: UserRealtoken) => { // VEFA properties - if (token.shortName === 'Playa Caracol Cottage 10' && !token.hasTenants) - return 10.77 - else if (token.shortName === 'Playa Caracol 303300' && !token.hasTenants) - return 10.69 - else if (token.shortName === 'Playa Caracol 303200' && !token.hasTenants) - return 10.8 - else if (token.shortName === 'PH Pinoalto A002' && !token.hasTenants) - return 10.11 - else if (token.shortName === 'PH Pinoalto A003' && !token.hasTenants) - return 10.11 - else if (token.shortName === 'Vervana T1 ' && !token.hasTenants) return 11.33 + if (isVEFA(token)) { + return VEFAAPRs[token.shortName as keyof typeof VEFAAPRs] + } if (token.rentedUnits === token.totalUnits) { // Case of fully rented property @@ -71,7 +63,7 @@ export const useFullyRentedAPR = (token: UserRealtoken) => { const fullyRentedAPR = useMemo(() => { const isDisabled = APRDisabled(rentCalculation, token) - if (isDisabled) return 0 + if (isDisabled && !isVEFA(token)) return 0 return fullyRentedAPREstimation(token) }, [token, rentCalculation]) @@ -83,12 +75,12 @@ export const useGeneralFullyRentedAPR = (tokens: UserRealtoken[]) => { // Fully rented APR average using valuation ponderation const fullyRentedAPR = useMemo(() => { const totalValue = tokens.reduce((acc, token) => { - const isDisabled = APRDisabled(rentCalculation, token) + const isDisabled = APRDisabled(rentCalculation, token) && !isVEFA(token) if (isDisabled) return acc return acc + token.value }, 0) const totalAPR = tokens.reduce((acc, token) => { - const isDisabled = APRDisabled(rentCalculation, token) + const isDisabled = APRDisabled(rentCalculation, token) && !isVEFA(token) if (isDisabled) return acc return acc + token.value * fullyRentedAPREstimation(token) }, 0) @@ -109,3 +101,23 @@ const APRDisabled = ( rentStartDate > realtimeDate.toDate() return isDisabled } + +export const isVEFA = (token: UserRealtoken) => { + return ( + token.shortName === 'Playa Caracol Cottage 10' || + token.shortName === 'Playa Caracol 303300' || + token.shortName === 'Playa Caracol 303200' || + token.shortName === 'PH Pinoalto A002' || + token.shortName === 'PH Pinoalto A003' || + token.shortName === 'Vervana T1 ' + ) +} + +const VEFAAPRs = { + 'Playa Caracol Cottage 10': 10.77, + 'Playa Caracol 303300': 10.69, + 'Playa Caracol 303200': 10.8, + 'PH Pinoalto A002': 10.11, + 'PH Pinoalto A003': 10.11, + 'Vervana T1 ': 11.33, +}