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

misc: Adapt docs and use correct reserve amount #2448

Merged
merged 2 commits into from
Sep 13, 2024
Merged
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
32 changes: 16 additions & 16 deletions centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [initialValues, isEditing, isLoading])


// NOTE: This assumes that pool.reserve.total comes from onchain state AND NOT from the runtime-apis
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@onnovisser or @sophialittlejohn is this correct? Does the pool.reserve.total come from onchain state? That is critical here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the value you're using definitely comes from onchain

const totalReserve = new CurrencyBalance(hexToBN(pool.reserve.total), currency.decimals)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect. As long as it is not coming from api.PoolsApi.nav() we are good.

const totalAum = pool.nav.aum.toDecimal().add(pool.reserve.total.toDecimal())

// NOTE: current pending here in the app does include both pending + disbursed fees
const pendingFees = React.useMemo(() => {
return new CurrencyBalance(
poolFees?.map((f) => f.amounts.pending).reduce((acc, f) => acc.add(f), new BN(0)) ?? new BN(0),
Expand All @@ -212,9 +217,8 @@
pool.currency.decimals
)
}, new CurrencyBalance(0, pool.currency.decimals))
}, [externalLoans, pool?.nav, form.values.feed])

Check warning on line 220 in centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx

View workflow job for this annotation

GitHub Actions / build-app

React Hook React.useMemo has a missing dependency: 'pool.currency.decimals'. Either include it or remove the dependency array

Check warning on line 220 in centrifuge-app/src/pages/NavManagement/NavManagementAssetTable.tsx

View workflow job for this annotation

GitHub Actions / ff-prod / build-app

React Hook React.useMemo has a missing dependency: 'pool.currency.decimals'. Either include it or remove the dependency array

const totalAum = pool.nav.aum.toDecimal().add(pool.reserve.available.toDecimal())
const pendingNav = totalAum.add(changeInValuation.toDecimal()).sub(pendingFees.toDecimal())

// Only for single tranche pools
Expand Down Expand Up @@ -319,7 +323,13 @@
return (
<>
<LayoutSection pt={3}>
<NavOverviewCard poolId={pool.id} changeInValuation={changeInValuation.toDecimal().toNumber()} />
<NavOverviewCard
poolId={pool.id}
changeInValuation={changeInValuation.toDecimal().toNumber()}
totalAum={totalAum.toNumber()}
pendingFees={pendingFees.toDecimal().toNumber()}
pendingNav={pendingNav.toNumber()}
/>
</LayoutSection>

<Stack pb={8}>
Expand Down Expand Up @@ -411,28 +421,18 @@
)
}

export function NavOverviewCard({ poolId, changeInValuation }: { poolId: string; changeInValuation: number }) {
export function NavOverviewCard({ poolId, changeInValuation, totalAum, pendingFees, pendingNav }: { poolId: string; changeInValuation: number; totalAum: number; pendingFees: number; pendingNav: number}) {
const pool = usePool(poolId)
const poolFees = usePoolFees(poolId)
const today = new Date()
today.setHours(0, 0, 0, 0)

const pendingFees = React.useMemo(() => {
return new CurrencyBalance(
poolFees?.map((f) => f.amounts.pending).reduce((acc, f) => acc.add(f), new BN(0)) ?? new BN(0),
pool.currency.decimals
)
}, [poolFees, pool.currency.decimals])

const totalAum = pool.nav.aum.toDecimal().add(pool.reserve.available.toDecimal())

return (
<VisualNavCard
currency={pool.currency}
aum={totalAum.toNumber()}
aum={totalAum ?? 0}
change={changeInValuation ?? 0}
pendingFees={pendingFees.toFloat()}
pendingNav={totalAum.add(changeInValuation).sub(pendingFees.toDecimal()).toNumber()}
pendingFees={pendingFees ?? 0}
pendingNav={pendingNav ?? 0}
/>
)
}
Expand Down
Loading