Skip to content

Commit

Permalink
Add inception value
Browse files Browse the repository at this point in the history
  • Loading branch information
kattylucy committed Jan 13, 2025
1 parent 1d71e32 commit cf572af
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion centrifuge-app/src/components/Portfolio/Holdings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CurrencyBalance, Token, evmToSubstrateAddress } from '@centrifuge/centrifuge-js'
import { CurrencyBalance, Perquintill, Token, evmToSubstrateAddress } from '@centrifuge/centrifuge-js'
import { NetworkIcon, formatBalance, useBalances, useCentrifuge, useWallet } from '@centrifuge/centrifuge-react'
import { Box, Grid, IconDownload, IconMinus, IconPlus, IconSend, Shelf, Text, Thumbnail } from '@centrifuge/fabric'
import Decimal from 'decimal.js-light'
Expand Down Expand Up @@ -38,6 +38,7 @@ export type Holding = {
connectedNetwork?: any
realizedProfit?: CurrencyBalance
unrealizedProfit?: CurrencyBalance
yieldSinceInception?: Perquintill | null
}

const columns: Column[] = [
Expand Down
8 changes: 8 additions & 0 deletions centrifuge-app/src/components/Portfolio/usePortfolio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
CurrencyBalance,
CurrencyMetadata,
InvestorTransactionType,
Perquintill,
Price,
Token,
TokenBalance,
Expand Down Expand Up @@ -170,6 +171,7 @@ export function usePortfolio(substrateAddress?: string) {
timestamp
trancheId
tranche {
yieldSinceInception
pool {
sumUnrealizedProfitAtMarketPrice
sumRealizedProfitFifoByPeriod
Expand All @@ -195,6 +197,7 @@ export function usePortfolio(substrateAddress?: string) {
tokenPrice: Price
unrealizedProfit: CurrencyBalance
realizedProfit: CurrencyBalance
yieldSinceInception: Perquintill | null
}
> = {}

Expand All @@ -213,6 +216,7 @@ export function usePortfolio(substrateAddress?: string) {
tokenPrice,
realizedProfit: new CurrencyBalance(position.tranche.pool.sumRealizedProfitFifoByPeriod, decimals),
unrealizedProfit: new CurrencyBalance(position.tranche.pool.sumUnrealizedProfitAtMarketPrice, decimals),
yieldSinceInception: new Perquintill(position.tranche.yieldSinceInception),
}
}
})
Expand All @@ -231,6 +235,7 @@ type PortfolioToken = {
currency: Token['currency']
realizedProfit: CurrencyBalance
unrealizedProfit: CurrencyBalance
yieldSinceInception: Perquintill
}

export function usePortfolioTokens(address?: string) {
Expand All @@ -246,6 +251,7 @@ export function usePortfolioTokens(address?: string) {
poolId: tranche.poolId,
realizedProfit: portfolioData[tranche.id]?.realizedProfit,
unrealizedProfit: portfolioData[tranche.id]?.unrealizedProfit,
yieldSinceInception: portfolioData[tranche.id]?.yieldSinceInception,
}
return tranches
}, tranches),
Expand All @@ -257,6 +263,7 @@ export function usePortfolioTokens(address?: string) {
currency: CurrencyMetadata
realizedProfit: CurrencyBalance
unrealizedProfit: CurrencyBalance
yieldSinceInception: Perquintill | null
}
>
)
Expand All @@ -276,6 +283,7 @@ export function usePortfolioTokens(address?: string) {
currency: trancheTokenPrices[trancheId].currency,
realizedProfit: trancheTokenPrices[trancheId].realizedProfit,
unrealizedProfit: trancheTokenPrices[trancheId].unrealizedProfit,
yieldSinceInception: trancheTokenPrices[trancheId].yieldSinceInception,
}
}, [] as PortfolioToken[])
}
Expand Down
10 changes: 5 additions & 5 deletions centrifuge-app/src/pages/Prime/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Transactions } from '../../../src/components/Portfolio/Transactions'
import { Resolutions } from '../../../src/components/Resolutions'
import { config } from '../../../src/config'
import { Dec } from '../../../src/utils/Decimal'
import { formatBalance } from '../../../src/utils/formatting'
import { formatBalance, formatPercentage } from '../../../src/utils/formatting'
import { Holdings, useHoldings } from '../../components/Portfolio/Holdings'
import { useDAOConfig } from '../../utils/useDAOConfig'

Expand Down Expand Up @@ -42,7 +42,7 @@ const PrimeDetail = () => {
Dec(0)
)

console.log(tokens[0].realizedProfit?.toDecimal())
const yieldSinceInception = tokens.find((token) => token.yieldSinceInception)?.yieldSinceInception

return !isLoading && dao && centAddress ? (
<Stack mx={1} my={1}>
Expand All @@ -53,16 +53,16 @@ const PrimeDetail = () => {
label: 'Portfolio Value',
value: formatBalance(currentPortfolioValue || 0, ''),
heading: false,
children: (
children: yieldSinceInception ? (
<Box backgroundColor={theme.colors.statusOkBg} padding="4px" borderRadius={4}>
<Text variant="body4" color="statusOk" style={{ fontWeight: 500 }}>
+25
+{formatPercentage(yieldSinceInception)}
</Text>
<Text variant="body4" color="statusOk">
Since inception
</Text>
</Box>
),
) : null,
},
{
label: 'Realized P&L',
Expand Down

0 comments on commit cf572af

Please sign in to comment.