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

2526 assets transactions table #2594

Merged
merged 6 commits into from
Jan 22, 2025
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
183 changes: 92 additions & 91 deletions centrifuge-app/src/components/PoolOverview/TransactionHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,117 +46,118 @@ export const TransactionHistory = ({
)
}

export const TransactionHistoryTable = ({
transactions,
poolId,
activeAssetId,
preview = true,
}: {
poolId: string
transactions: any[]
activeAssetId?: string
preview?: boolean
}) => {
const basePath = useBasePath('/pools')
const getLabelAndAmount = (transaction: AssetTransaction) => {
const netFlow = activeAssetId
? activeAssetId === transaction.toAsset?.id.split('-')[1]
? 'positive'
: 'negative'
: 'neutral'
export const getLabelAndAmount = (transaction: AssetTransaction, activeAssetId?: string) => {
const netFlow = activeAssetId
? activeAssetId === transaction.toAsset?.id.split('-')[1]
? 'positive'
: 'negative'
: 'neutral'

if (transaction.type === 'CASH_TRANSFER') {
return {
label: 'Cash transfer from',
amount: transaction.amount,
netFlow,
}
}

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

if (transaction.type === 'WITHDRAWAL_FOR_REDEMPTIONS') {
return {
label: 'Withdrawal for redemptions',
amount: transaction.amount,
netFlow: 'negative',
}
if (transaction.type === 'DEPOSIT_FROM_INVESTMENTS') {
return {
label: 'Deposit from investments into',
amount: transaction.amount,
netFlow: 'positive',
}
}

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

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

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

if (transaction.type === 'DECREASE_DEBT') {
return {
label: 'Correction ↓ of',
amount: transaction.amount,
netFlow: 'negative',
}
if (transaction.type === 'INCREASE_DEBT') {
return {
label: 'Correction ↑ of',
amount: transaction.amount,
netFlow: 'positive',
}
}

// TODO: ideally, if both principalAmount and interestAmount are non-zero, there should be 2 separate transactions
if (
transaction.type === 'REPAID' &&
!new BN(transaction.interestAmount || 0).isZero() &&
!new BN(transaction.principalAmount || 0).isZero()
) {
return {
label: 'Principal & interest payment',
amount: new CurrencyBalance(
new BN(transaction.principalAmount || 0).add(new BN(transaction.interestAmount || 0)),
transaction.principalAmount!.decimals
),
netFlow,
}
if (transaction.type === 'DECREASE_DEBT') {
return {
label: 'Correction ↓ of',
amount: transaction.amount,
netFlow: 'negative',
}
}

if (
transaction.type === 'REPAID' &&
!new BN(transaction.interestAmount || 0).isZero() &&
new BN(transaction.principalAmount || 0).isZero()
) {
return {
label: 'Interest payment from',
amount: transaction.interestAmount,
netFlow,
}
// TODO: ideally, if both principalAmount and interestAmount are non-zero, there should be 2 separate transactions
if (
transaction.type === 'REPAID' &&
!new BN(transaction.interestAmount || 0).isZero() &&
!new BN(transaction.principalAmount || 0).isZero()
) {
return {
label: 'Principal & interest payment',
amount: new CurrencyBalance(
new BN(transaction.principalAmount || 0).add(new BN(transaction.interestAmount || 0)),
transaction.principalAmount!.decimals
),
netFlow,
}
}

if (
transaction.type === 'REPAID' &&
!new BN(transaction.interestAmount || 0).isZero() &&
new BN(transaction.principalAmount || 0).isZero()
) {
return {
label: 'Sale of',
amount: transaction.principalAmount,
label: 'Interest payment from',
amount: transaction.interestAmount,
netFlow,
sublabel: 'settled into',
}
}

return {
label: 'Sale of',
amount: transaction.principalAmount,
netFlow,
sublabel: 'settled into',
}
}

export const TransactionHistoryTable = ({
transactions,
poolId,
activeAssetId,
preview = true,
}: {
poolId: string
transactions: any[]
activeAssetId?: string
preview?: boolean
}) => {
const basePath = useBasePath('/pools')

const transformedTransactions =
transactions
?.filter(
Expand All @@ -169,7 +170,7 @@ export const TransactionHistoryTable = ({
.sort((a, b) => (a.timestamp > b.timestamp ? -1 : 1)) || []

const csvData = transformedTransactions.map((transaction) => {
const { label, amount } = getLabelAndAmount(transaction)
const { label, amount } = getLabelAndAmount(transaction, activeAssetId)
const [, id] = transaction.asset.id.split('-')
return {
Type: label,
Expand Down Expand Up @@ -197,7 +198,7 @@ export const TransactionHistoryTable = ({

const tableData =
transformedTransactions.slice(0, preview ? 8 : Infinity).map((transaction) => {
const { amount, netFlow, label, sublabel } = getLabelAndAmount(transaction)
const { amount, netFlow, label, sublabel } = getLabelAndAmount(transaction, activeAssetId)
return {
activeAssetId,
netFlow,
Expand Down
Loading
Loading