Skip to content

Commit

Permalink
use loan specific transaction types
Browse files Browse the repository at this point in the history
  • Loading branch information
JP Angelle committed Sep 11, 2023
1 parent e2f8c2b commit 79e05c0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
21 changes: 8 additions & 13 deletions centrifuge-app/src/pages/Loan/HoldingsValues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Props = {
}

export function HoldingsValues({ loan: { pricing }, pool, transactions }: Props) {
const currentHolding =
const netCash =
transactions?.reduce((sum, trx) => {
if (trx.type === 'REPAID') {
sum = new CurrencyBalance(
Expand All @@ -33,7 +33,7 @@ export function HoldingsValues({ loan: { pricing }, pool, transactions }: Props)
return sum
}, new CurrencyBalance(0, 27)) || new CurrencyBalance(0, 27)

const currentTotalFace =
const currentFace =
transactions?.reduce((sum, trx) => {
if (trx.type === 'BORROWED') {
sum = new CurrencyBalance(sum.add(trx.amount || new CurrencyBalance(0, 27)), 27)
Expand All @@ -47,26 +47,21 @@ export function HoldingsValues({ loan: { pricing }, pool, transactions }: Props)
return (
<>
<LabelValueStack
label="Current total face"
value={`${formatBalance(new CurrencyBalance(currentTotalFace, 24), pool.currency.symbol, 6, 2)}`}
label="Current face"
value={`${formatBalance(new CurrencyBalance(currentFace, 24), pool.currency.symbol, 6, 2)}`}
/>
<LabelValueStack
label="Current holding"
value={`${formatBalance(new CurrencyBalance(currentHolding, 32), pool.currency.symbol, 6, 2)}`}
label="Net cash"
value={`${formatBalance(new CurrencyBalance(netCash, 32), pool.currency.symbol, 6, 2)}`}
/>
<LabelValueStack
label="Average price"
value={`${formatBalance(
new CurrencyBalance(currentHolding.div(currentTotalFace), 6),
pool.currency.symbol,
2,
2
)}`}
value={`${formatBalance(new CurrencyBalance(netCash.div(currentFace), 6), pool.currency.symbol, 2, 2)}`}
/>
<LabelValueStack
label="Current value"
value={`${formatBalance(
new CurrencyBalance(currentTotalFace.mul(pricing.oracle.value), 44),
new CurrencyBalance(currentFace.mul(pricing.oracle.value), 44),
pool.currency.symbol,
6,
2
Expand Down
14 changes: 10 additions & 4 deletions centrifuge-app/src/pages/Loan/TransactionTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { formatBalance } from '../../utils/formatting'
type Props = {
transactions: BorrowerTransaction[]
currency: string
loanType: 'external' | 'internal'
}

export const TransactionTable = ({ transactions, currency }: Props) => {
export const TransactionTable = ({ transactions, currency, loanType }: Props) => {
const assetTransactions = useMemo(() => {
const sortedTransactions = transactions.sort((a, b) => {
if (a.timestamp > b.timestamp) {
Expand Down Expand Up @@ -52,6 +53,13 @@ export const TransactionTable = ({ transactions, currency }: Props) => {
return 'default'
}

const getStatusText = (type: BorrowerTransactionType) => {
if (loanType === 'external' && type === 'BORROWED') return 'Purchase'
if (loanType === 'external' && type === 'REPAID') return 'Sale'

return `${type[0]}${type.slice(1).toLowerCase()}`
}

return (
<DataTable
data={assetTransactions.reverse()}
Expand All @@ -60,9 +68,7 @@ export const TransactionTable = ({ transactions, currency }: Props) => {
align: 'left',
header: 'Type',
cell: (row: { type: BorrowerTransactionType }) => (
<StatusChip status={getStatusChipType(row.type)}>{`${row.type[0]}${row.type
.slice(1)
.toLowerCase()}`}</StatusChip>
<StatusChip status={getStatusChipType(row.type)}>{getStatusText(row.type)}</StatusChip>
),
flex: '3',
},
Expand Down
10 changes: 9 additions & 1 deletion centrifuge-app/src/pages/Loan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,15 @@ const Loan: React.FC<{ setShowOraclePricing?: () => void }> = ({ setShowOraclePr
</Flex>
}
>
<TransactionTable transactions={borrowerAssetTransactions} currency={pool.currency.symbol} />
<TransactionTable
transactions={borrowerAssetTransactions}
currency={pool.currency.symbol}
loanType={
'valuationMethod' in loan.pricing && loan.pricing.valuationMethod === 'oracle'
? 'external'
: 'internal'
}
/>
</PageSection>
) : null}
</>
Expand Down

0 comments on commit 79e05c0

Please sign in to comment.