Skip to content

Commit

Permalink
Merge pull request #82 from RealToken-Community/vefa-apr-realtime
Browse files Browse the repository at this point in the history
feat: use API return by API for VEFA property in real time mode
  • Loading branch information
AlexRLT authored Sep 1, 2024
2 parents 378f936 + 309459d commit fd211a5
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/hooks/useFullyRentedAPR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import {
RentCalculationState,
} from 'src/types/RentCalculation'

const fullyRentedAPREstimation = (token: UserRealtoken) => {
const fullyRentedAPREstimation = (
token: UserRealtoken,
rentCalculation: RentCalculation,
) => {
// VEFA properties
if (isVEFA(token)) {
return VEFAAPRs[token.shortName as keyof typeof VEFAAPRs]
return getVEFAFullRentedAPR(token, rentCalculation)
}

if (token.rentedUnits === token.totalUnits) {
Expand Down Expand Up @@ -64,7 +67,7 @@ export const useFullyRentedAPR = (token: UserRealtoken) => {
const fullyRentedAPR = useMemo(() => {
const isDisabled = APRDisabled(rentCalculation, token)
if (isDisabled && !isVEFA(token)) return 0
return fullyRentedAPREstimation(token)
return fullyRentedAPREstimation(token, rentCalculation)
}, [token, rentCalculation])

return fullyRentedAPR
Expand All @@ -82,7 +85,9 @@ export const useGeneralFullyRentedAPR = (tokens: UserRealtoken[]) => {
const totalAPR = tokens.reduce((acc, token) => {
const isDisabled = APRDisabled(rentCalculation, token) && !isVEFA(token)
if (isDisabled) return acc
return acc + token.value * fullyRentedAPREstimation(token)
return (
acc + token.value * fullyRentedAPREstimation(token, rentCalculation)
)
}, 0)
return totalAPR / totalValue
}, [tokens, rentCalculation])
Expand Down Expand Up @@ -121,3 +126,13 @@ const VEFAAPRs = {
'PH Pinoalto A003': 10.11,
'Vervana T1 ': 11.33,
}

const getVEFAFullRentedAPR = (
token: UserRealtoken,
rentCalculation: RentCalculation,
) => {
if (rentCalculation.state === RentCalculationState.Realtime) {
return token.annualPercentageYield
}
return VEFAAPRs[token.shortName as keyof typeof VEFAAPRs]
}

0 comments on commit fd211a5

Please sign in to comment.