Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centrifuge App: Remove accrued interest from portfolio card #1625

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion centrifuge-app/src/components/PoolsTokensShared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export function PoolsTokensShared({ title, children }: PoolsTokensSharedProps) {
<LoadBoundary>
<CardTotalValueLocked />
</LoadBoundary>
<PortfolioCta />
<LoadBoundary>
<PortfolioCta />
</LoadBoundary>
</Grid>

<Stack alignItems="end">
Expand Down
13 changes: 0 additions & 13 deletions centrifuge-app/src/components/PortfolioCta/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ActiveLoan } from '@centrifuge/centrifuge-js'
import { useBalances, useCentrifugeConsts, useWallet } from '@centrifuge/centrifuge-react'
import { Box, Button, Shelf, Stack, Text } from '@centrifuge/fabric'
import * as React from 'react'
Expand All @@ -8,7 +7,6 @@ import { Dec } from '../../utils/Decimal'
import { formatBalance, formatBalanceAbbreviated } from '../../utils/formatting'
import { useAddress } from '../../utils/useAddress'
import { useListedPools } from '../../utils/useListedPools'
import { useLoansAcrossPools } from '../../utils/useLoans'
import { useDebugFlags } from '../DebugFlags'
import { useComputeLiquidityRewards } from '../LiquidityRewards/hooks'
import { Cubes } from './Cubes'
Expand All @@ -33,24 +31,13 @@ export function PortfolioCta() {
}) ?? []
const investedValue = [...currencies, ...tranches].reduce((a, b) => a.add(b), Dec(0))

const pools = balances?.tranches.map(({ poolId }) => poolId) ?? []
const loans = useLoansAcrossPools(pools) ?? []
const activeLoans = loans?.filter(({ status }) => status === 'Active') as ActiveLoan[]
const accruedInterest = activeLoans
.map(({ outstandingInterest }) => outstandingInterest.toDecimal())
.reduce((a, b) => a.add(b), Dec(0))

const terms = [
{
title: 'Portfolio value',
value: investedValue.gte(1000)
? formatBalanceAbbreviated(investedValue, config.baseCurrency)
: formatBalance(investedValue, config.baseCurrency),
},
{
title: 'Accrued interest',
value: formatBalance(accruedInterest, config.baseCurrency),
},
{
title: 'CFG rewards',
value: formatBalance(rewards, consts.chainSymbol, 2),
Expand Down
15 changes: 0 additions & 15 deletions centrifuge-app/src/utils/useLoans.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { useCentrifugeQuery } from '@centrifuge/centrifuge-react'
import { combineLatest } from 'rxjs'
import { map } from 'rxjs/operators'
import { Dec } from './Decimal'
import { useTinlakeLoans } from './tinlake/useTinlakePools'

Expand All @@ -16,19 +14,6 @@ export function useLoans(poolId: string) {
return isTinlakePool ? tinlakeLoans : centLoans
}

export function useLoansAcrossPools(poolIds?: string[]) {
const [result] = useCentrifugeQuery(
['loansAcrossPools', poolIds],
(cent) => combineLatest(poolIds!.map((poolId) => cent.pools.getLoans([poolId]))).pipe(map((loans) => loans.flat())),
{
suspense: true,
enabled: poolIds && poolIds.length > 0,
}
)

return result
}

export function useLoan(poolId: string, assetId: string) {
const loans = useLoans(poolId)

Expand Down
Loading