Skip to content
119 changes: 119 additions & 0 deletions components/Transaction/TransactionBatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import React from 'react'
import { TData } from '../Table'

import { TransactionCard } from './TransactionCard'
import { AddressWithIconFilled, amountFormatWithIcon, shortAddress } from '../../utils/format'
import Link from 'next/link'

// Component to display transaction flags with tooltips
const TransactionFlags = ({ flags }) => {
Copy link
Member

Choose a reason for hiding this comment

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

we have the functionn in utils showFlags - please reuse it

if (!flags || typeof flags !== 'object') return <span className="grey">None</span>

const activeFlags = []

// Check each flag in the specification.flags object
Object.entries(flags).forEach(([flagName, isActive]) => {
if (isActive === true) {
activeFlags.push(flagName)
}
})

if (activeFlags.length === 0) {
return <span className="grey">None</span>
}

return (
<>
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
{activeFlags.map((flag, index) => (
<div key={index}>
<span className="no-brake">
<span className="flag">{flag}</span>
</span>
</div>
))}
</div>
</>
)
}

export const TransactionBatch = ({ data, pageFiatRate, selectedCurrency }) => {
if (!data) return null
const { specification } = data

return (
<TransactionCard
data={data}
pageFiatRate={pageFiatRate}
selectedCurrency={selectedCurrency}
notFullySupported={true}
>
<tr>
<TData>Initiated by</TData>
<TData>
<AddressWithIconFilled data={specification.source} name="address" />
Copy link
Member

Choose a reason for hiding this comment

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

that seems used wrong
it should be object and then the name of the address field

<AddressWithIconFilled data={specification} name="source" />

Copy link
Member

Choose a reason for hiding this comment

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

make sure there is specification.sourceDetails - otherwise contact Ildar to add it.

</TData>
</tr>
<tr>
<TData>Flags</TData>
<TData>
<TransactionFlags flags={specification.flags} txType={data?.tx?.TransactionType} />
</TData>
</tr>
{specification?.transactions?.map((transaction, index) => (
<React.Fragment key={transaction.id || index}>
<tr>
<TData className="bold">
Transaction {index + 1}
</TData>
</tr>
<tr>
<TData style={{ paddingLeft: '30px' }}>ID</TData>
<TData>
<Link href={`/tx/${transaction.id}`}>
Copy link
Member

Choose a reason for hiding this comment

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

Please reuse LinkTx from utils/links

{shortAddress(transaction.id)}
</Link>
</TData>
</tr>
<tr>
<TData style={{ paddingLeft: '30px' }}>Type</TData>
<TData>
<span className="bold">{transaction?.type}</span>
</TData>
</tr>
<tr>
<TData style={{ paddingLeft: '30px' }}>Sequence</TData>
<TData>
#{transaction?.sequence}
</TData>
</tr>
<tr>
<TData style={{ paddingLeft: '30px' }}>Flags</TData>
<TData>
<TransactionFlags flags={transaction.specification.flags} txType={transaction.type} />
</TData>
</tr>
{
transaction.specification.destination &&
<tr>
<TData style={{ paddingLeft: '30px' }}>Destination</TData>
<TData>
<AddressWithIconFilled data={transaction.specification.destination} name="address" />
</TData>
</tr>
}
{
transaction.specification?.source?.maxAmount &&
<tr>
<TData style={{ paddingLeft: '30px' }}>Max Amount</TData>
Copy link
Member

Choose a reason for hiding this comment

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

Why do all of them have paddingLeft: 30?

<TData>
{amountFormatWithIcon({ amount: transaction.specification?.source?.maxAmount })}
</TData>
</tr>
}
</React.Fragment>
))}
</TransactionCard>
)
}

6 changes: 6 additions & 0 deletions components/Transaction/TransactionCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,12 @@ export const TransactionCard = ({
})}
</>
)}
{outcome?.parentBatchID && (
<tr>
<TData>Parent batch ID</TData>
<TData>{addressUsernameOrServiceLink(outcome, 'parentBatchID', { short: true, url: '/tx/' })}</TData>
</tr>
)}
<tr>
<TData>Transaction link</TData>
<TData>
Expand Down
1 change: 1 addition & 0 deletions components/Transaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export { TransactionPayment } from './TransactionPayment'
export { TransactionSetRegularKey } from './TransactionSetRegularKey'
export { TransactionTrustSet } from './TransactionTrustSet'
export { TransactionEnableAmendment } from './TransactionEnableAmendment'
export { TransactionBatch } from './TransactionBatch'

//xrpl
export { TransactionAMM } from './TransactionAmm'
Expand Down
5 changes: 4 additions & 1 deletion pages/transaction/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import {
TransactionURIToken,
TransactionRemit,
TransactionEnableAmendment,
TransactionDelegateSet
TransactionDelegateSet,
TransactionBatch
} from '../../components/Transaction'
import { useEffect, useState } from 'react'
import { fetchHistoricalRate } from '../../utils/common'
Expand Down Expand Up @@ -121,6 +122,8 @@ export default function Transaction({ data, selectedCurrency }) {
TransactionComponent = TransactionRemit
} else if (txType === 'EnableAmendment') {
TransactionComponent = TransactionEnableAmendment
} else if (txType === 'Batch') {
TransactionComponent = TransactionBatch
} else {
TransactionComponent = TransactionDetails
}
Expand Down