Skip to content

Commit

Permalink
Update token price
Browse files Browse the repository at this point in the history
  • Loading branch information
kattylucy committed Aug 13, 2024
1 parent 0f07a60 commit 695abdd
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions centrifuge-app/src/components/Charts/PoolPerformanceChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ function PoolPerformanceChart() {

// querying chain for more accurate data, since data for today from subquery is not necessarily up to date
const todayAssetValue = pool?.nav.total.toDecimal().toNumber() || 0
const todayPrice = pool?.tranches ? pool?.tranches[pool.tranches.length - 1].tokenPrice : null
const todayPrice = pool?.tranches
? formatBalance(pool?.tranches[pool.tranches.length - 1].tokenPrice || 0, pool?.currency.symbol, 5, 5)
: null

const today = {
nav: todayAssetValue,
Expand All @@ -121,6 +123,15 @@ function PoolPerformanceChart() {
return 45
}

const isToday = (date: Date) => {
const today = new Date()
return (
date.getDate() === today.getDate() &&
date.getMonth() === today.getMonth() &&
date.getFullYear() === today.getFullYear()
)
}

return (
<Stack gap={2}>
<Stack flexDirection="row" justifyContent="space-between">
Expand Down Expand Up @@ -216,9 +227,11 @@ function PoolPerformanceChart() {
</Text>
<Text variant="label2">
{name === 'nav' && typeof value === 'number'
? formatBalance(value, 'USD' || '')
? formatBalance(value, 'USD')
: typeof value === 'number'
? formatBalance(value, 'USD' || '', 6)
? isToday(payload[0].payload.day)
? todayPrice
: formatBalance(value, pool.currency.symbol || '', 5, 5)
: '-'}
</Text>
</Shelf>
Expand Down

0 comments on commit 695abdd

Please sign in to comment.