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

Support corrections (increase/decrease debt) #2373

Merged
merged 3 commits into from
Aug 15, 2024
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
37 changes: 34 additions & 3 deletions centrifuge-app/src/components/PoolOverview/TransactionHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,38 +60,65 @@ export const TransactionHistoryTable = ({
}) => {
const basePath = useBasePath('/pools')
const getLabelAndAmount = (transaction: AssetTransaction) => {
const netFlow = activeAssetId
? activeAssetId === transaction.toAsset?.id.split('-')[1]
? 'positive'
: 'negative'
: 'neutral'

if (transaction.type === 'CASH_TRANSFER') {
return {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe is a good idea to have this line of code on line 63

const netFlow = activeAssetId
          ? activeAssetId === transaction.toAsset?.id.split('-')[1]
            ? 'positive'
            : 'negative'
          : 'neutral',

and then add netFlow below in each corresponding case. In case we are debugging in the future so we can only change one place instead of the 5 different values within the same function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed! Will change.

label: 'Cash transfer',
amount: transaction.amount,
netFlow,
}
}

if (transaction.type === 'DEPOSIT_FROM_INVESTMENTS') {
return {
label: 'Deposit from investments',
amount: transaction.amount,
netFlow: 'positive',
}
}

if (transaction.type === 'WITHDRAWAL_FOR_REDEMPTIONS') {
return {
label: 'Withdrawal for redemptions',
amount: transaction.amount,
netFlow: 'negative',
}
}

if (transaction.type === 'WITHDRAWAL_FOR_FEES') {
return {
label: 'Withdrawal for fees',
amount: transaction.amount,
netFlow: 'negative',
}
}

if (transaction.type === 'BORROWED') {
return {
label: 'Purchase',
amount: transaction.amount,
netFlow,
}
}

if (transaction.type === 'INCREASE_DEBT') {
return {
label: 'Correction',
amount: transaction.amount,
netFlow: 'positive',
}
}

if (transaction.type === 'DECREASE_DEBT') {
return {
label: 'Correction',
amount: transaction.amount,
netFlow: 'negative',
}
}

Expand All @@ -107,6 +134,7 @@ export const TransactionHistoryTable = ({
new BN(transaction.principalAmount || 0).add(new BN(transaction.interestAmount || 0)),
transaction.principalAmount!.decimals
),
netFlow,
}
}

Expand All @@ -118,12 +146,14 @@ export const TransactionHistoryTable = ({
return {
label: 'Interest payment',
amount: transaction.interestAmount,
netFlow,
}
}

return {
label: 'Principal payment',
amount: transaction.principalAmount,
netFlow,
}
}

Expand Down Expand Up @@ -167,9 +197,10 @@ export const TransactionHistoryTable = ({

const tableData =
transformedTransactions.slice(0, preview ? 8 : Infinity).map((transaction) => {
const { label, amount } = getLabelAndAmount(transaction)
const { label, amount, netFlow } = getLabelAndAmount(transaction)
return {
activeAssetId,
netFlow,
type: label,
transactionDate: transaction.timestamp,
assetId: transaction.asset.id,
Expand Down Expand Up @@ -235,9 +266,9 @@ export const TransactionHistoryTable = ({
{
align: 'right',
header: <SortableTableHeader label="Amount" />,
cell: ({ amount }: Row) => (
cell: ({ amount, netFlow }: Row) => (
<Text as="span" variant="body3">
{amount ? formatBalance(amount, 'USD', 2, 2) : ''}
{amount ? `${activeAssetId && netFlow === 'negative' ? '-' : ''}${formatBalance(amount, 'USD', 2, 2)}` : ''}
</Text>
),
sortKey: 'amount',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const status = {
DEPOSIT_FROM_INVESTMENTS: 'default',
WITHDRAWAL_FOR_REDEMPTIONS: 'default',
WITHDRAWAL_FOR_FEES: 'default',
INCREASE_DEBT: 'default',
DECREASE_DEBT: 'default',
} as const

export function TransactionTypeChip(props: TransactionTypeProps) {
Expand Down
20 changes: 20 additions & 0 deletions centrifuge-app/src/components/Report/TokenPrice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,26 @@ export function TokenPrice({ pool }: { pool: Pool }) {
formatter: (v: any) => formatPercentage(v * 100, true, {}, 2),
}))
: []),
...(!!showTokenYields
? [
{
name: '7d APY',
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].yield7DaysAnnualized.toFloat()) || [],
heading: false,
formatter: (v: any) => formatPercentage(v * 100, true, {}, 2),
}))
: []),
...(!!showTokenYields
? [
{
Expand Down
2 changes: 2 additions & 0 deletions centrifuge-app/src/components/Report/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ const assetTransactionTypes: {
DEPOSIT_FROM_INVESTMENTS: 'Deposit from investments',
WITHDRAWAL_FOR_REDEMPTIONS: 'Withdrawal for redemptions',
WITHDRAWAL_FOR_FEES: 'Withdrawal for fees',
INCREASE_DEBT: 'Correction (increase)',
DECREASE_DEBT: 'Correction (decrease)',
}

export function formatAssetTransactionType(type: AssetTransactionType) {
Expand Down
6 changes: 2 additions & 4 deletions centrifuge-app/src/pages/Loan/TransactionTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,12 @@ export const TransactionTable = ({
{
align: 'left',
header: `Amount (${currency})`,
cell: (row: Row) =>
row.amount ? `${row.type === 'REPAID' ? '-' : ''}${formatBalance(row.amount, undefined, 2, 2)}` : '-',
cell: (row: Row) => (row.amount ? `${formatBalance(row.amount, undefined, 2, 2)}` : '-'),
},
{
align: 'left',
header: `Principal (${currency})`,
cell: (row: Row) =>
row.position ? `${row.type === 'REPAID' ? '-' : ''}${formatBalance(row.position, undefined, 2, 2)}` : '-',
cell: (row: Row) => (row.position ? `${formatBalance(row.position, undefined, 2, 2)}` : '-'),
},
]),
] as Column[]
Expand Down
5 changes: 5 additions & 0 deletions centrifuge-js/src/modules/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ export type DailyTrancheState = {
fulfilledRedeemOrders: CurrencyBalance
outstandingInvestOrders: CurrencyBalance
outstandingRedeemOrders: CurrencyBalance
yield7DaysAnnualized: Perquintill
yield30DaysAnnualized: Perquintill
yield90DaysAnnualized: Perquintill
yieldSinceInception: Perquintill
Expand Down Expand Up @@ -2386,6 +2387,7 @@ export function getPoolsModule(inst: Centrifuge) {
sumOutstandingRedeemOrdersByPeriod
sumFulfilledInvestOrdersByPeriod
sumFulfilledRedeemOrdersByPeriod
yield7DaysAnnualized
yield30DaysAnnualized
yield90DaysAnnualized
yieldSinceInception
Expand Down Expand Up @@ -2599,6 +2601,9 @@ export function getPoolsModule(inst: Centrifuge) {
tranche.sumOutstandingRedeemOrdersByPeriod,
poolCurrency.decimals
),
yield7DaysAnnualized: tranche.yield7DaysAnnualized
? new Perquintill(hexToBN(tranche.yield7DaysAnnualized))
: new Perquintill(0),
yield30DaysAnnualized: tranche.yield30DaysAnnualized
? new Perquintill(hexToBN(tranche.yield30DaysAnnualized))
: new Perquintill(0),
Expand Down
3 changes: 3 additions & 0 deletions centrifuge-js/src/types/subquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type SubqueryTrancheSnapshot = {
sumOutstandingRedeemOrdersByPeriod: string
sumFulfilledInvestOrdersByPeriod: string
sumFulfilledRedeemOrdersByPeriod: string
yield7DaysAnnualized: string
yield30DaysAnnualized: string
yield90DaysAnnualized: string
yieldSinceInception: string
Expand Down Expand Up @@ -97,6 +98,8 @@ export type AssetTransactionType =
| 'DEPOSIT_FROM_INVESTMENTS'
| 'WITHDRAWAL_FOR_REDEMPTIONS'
| 'WITHDRAWAL_FOR_FEES'
| 'INCREASE_DEBT'
| 'DECREASE_DEBT'

export enum AssetType {
OnchainCash = 'OnchainCash',
Expand Down
Loading