Skip to content

Commit

Permalink
Add token price new sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
kattylucy committed Jan 28, 2025
1 parent 7dff8d0 commit d69f969
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 24 deletions.
2 changes: 1 addition & 1 deletion centrifuge-app/src/components/Report/FeeTransactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function FeeTransactions({ pool }: { pool: Pool }) {
.map((tx) => ({
name: '',
value: [
tx.timestamp.toISOString(),
tx.timestamp,
poolMetadata?.pool?.poolFees?.find((f) => f.id === tx.poolFee.feeId)?.name || '-',
formatPoolFeeTransactionType(tx.type),
tx.amount?.toFloat() ?? '-',
Expand Down
68 changes: 45 additions & 23 deletions centrifuge-app/src/components/Report/TokenPrice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ export function TokenPrice({ pool }: { pool: Pool }) {
groupBy
)

console.log(poolStates)

const columns = React.useMemo(() => {
if (!poolStates) {
return []
Expand Down Expand Up @@ -84,9 +82,10 @@ export function TokenPrice({ pool }: { pool: Pool }) {
.map((token) => ({
name: `\u00A0 \u00A0 ${token.currency.displayName} token`,
value:
poolStates?.map((state) =>
state.tranches[token.id]?.price ? state.tranches[token.id].price!.toFloat() : 1
) || [],
poolStates?.map((state) => {
const matchingTranche = state.tranches.find((t) => t.id === token.id)
return matchingTranche?.price.toFloat() ?? 1
}) || [],
heading: false,
formatter: (v: any) => formatBalance(v, pool.currency.symbol, 6),
})) || []),
Expand All @@ -100,7 +99,11 @@ export function TokenPrice({ pool }: { pool: Pool }) {
.reverse()
.map((token) => ({
name: `\u00A0 \u00A0 ${token.currency.displayName} token`,
value: poolStates?.map((state) => state.tranches[token.id].tokenSupply.toFloat()) || [],
value:
poolStates?.map((state) => {
const matchingTranche = state.tranches.find((t) => t.id === token.id)
return matchingTranche?.supply.toFloat() ?? 0
}) || [],
heading: false,
formatter: (v: any) => formatBalance(v, '', 2),
})) || []),
Expand All @@ -119,7 +122,11 @@ export function TokenPrice({ pool }: { pool: Pool }) {
.reverse()
.map((token) => ({
name: `\u00A0 \u00A0 ${token.currency.displayName} token`,
value: poolStates?.map((state) => state.tranches[token.id].yieldSinceInception.toFloat()) || [],
value:
poolStates?.map((state) => {
const matchingTranche = state.tranches.find((t) => t.id === token.id)
return matchingTranche?.yieldSinceInception.toFloat() ?? 0
}) || [],
heading: false,
formatter: (v: any) => formatPercentage(v * 100, true, {}, 2),
}))
Expand All @@ -139,27 +146,26 @@ export function TokenPrice({ pool }: { pool: Pool }) {
.reverse()
.map((token) => ({
name: `\u00A0 \u00A0 ${token.currency.displayName} token`,
value: poolStates?.map((state) => state.tranches[token.id].yieldMTD.toFloat()) || [],
value:
poolStates?.map((state) => {
const matchingTranche = state.tranches.find((t) => t.id === token.id)
return matchingTranche?.yieldMTD?.toFloat() ?? 0
}) || [],
heading: false,
formatter: (v: any) => formatPercentage(v * 100, true, {}, 2),
}))
: []),
...(!!showTokenYields
? [
{
name: 'Yield QTD',
value: poolStates?.map(() => '' as any) || [],
heading: false,
},
]
: []),
...(!!showTokenYields
? pool?.tranches
.slice()
.reverse()
.map((token) => ({
name: `\u00A0 \u00A0 ${token.currency.displayName} token`,
value: poolStates?.map((state) => state.tranches[token.id].yieldQTD.toFloat()) || [],
value:
poolStates?.map((state) => {
const matchingTranche = state.tranches.find((t) => t.id === token.id)
return matchingTranche?.yieldQTD?.toFloat() ?? 0
}) || [],
heading: false,
formatter: (v: any) => formatPercentage(v * 100, true, {}, 2),
}))
Expand All @@ -179,7 +185,11 @@ export function TokenPrice({ pool }: { pool: Pool }) {
.reverse()
.map((token) => ({
name: `\u00A0 \u00A0 ${token.currency.displayName} token`,
value: poolStates?.map((state) => state.tranches[token.id].yieldYTD.toFloat()) || [],
value:
poolStates?.map((state) => {
const matchingTranche = state.tranches.find((t) => t.id === token.id)
return matchingTranche?.yieldYTD?.toFloat() ?? 0
}) || [],
heading: false,
formatter: (v: any) => formatPercentage(v * 100, true, {}, 2),
}))
Expand All @@ -199,7 +209,11 @@ export function TokenPrice({ pool }: { pool: Pool }) {
.reverse()
.map((token) => ({
name: `\u00A0 \u00A0 ${token.currency.displayName} token`,
value: poolStates?.map((state) => state.tranches[token.id].yield7DaysAnnualized.toFloat()) || [],
value:
poolStates?.map((state) => {
const matchingTranche = state.tranches.find((t) => t.id === token.id)
return matchingTranche?.yield7daysAnnualized?.toFloat() ?? 0
}) || [],
heading: false,
formatter: (v: any) => formatPercentage(v * 100, true, {}, 2),
}))
Expand All @@ -219,7 +233,11 @@ export function TokenPrice({ pool }: { pool: Pool }) {
.reverse()
.map((token) => ({
name: `\u00A0 \u00A0 ${token.currency.displayName} token`,
value: poolStates?.map((state) => state.tranches[token.id].yield30DaysAnnualized.toFloat()) || [],
value:
poolStates?.map((state) => {
const matchingTranche = state.tranches.find((t) => t.id === token.id)
return matchingTranche?.yield30daysAnnualized?.toFloat() ?? 0
}) || [],
heading: false,
formatter: (v: any) => formatPercentage(v * 100, true, {}, 2),
}))
Expand All @@ -239,7 +257,11 @@ export function TokenPrice({ pool }: { pool: Pool }) {
.reverse()
.map((token) => ({
name: `\u00A0 \u00A0 ${token.currency.displayName} token`,
value: poolStates?.map((state) => state.tranches[token.id].yield90DaysAnnualized.toFloat()) || [],
value:
poolStates?.map((state) => {
const matchingTranche = state.tranches.find((t) => t.id === token.id)
return matchingTranche?.yield90daysAnnualized?.toFloat() ?? 0
}) || [],
heading: false,
formatter: (v: any) => formatPercentage(v * 100, true, {}, 2),
}))
Expand Down Expand Up @@ -287,7 +309,7 @@ export function TokenPrice({ pool }: { pool: Pool }) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [priceRecords])

if (!poolStates) {
if (isLoading) {
return <Spinner mt={2} />
}

Expand Down

0 comments on commit d69f969

Please # to comment.