Skip to content
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
152 changes: 92 additions & 60 deletions src/components/TransactionDetails/TransactionDetailsReceipt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,46 @@ export const TransactionDetailsReceipt = ({
return rowKey === lastVisibleRow
}

// reusable helper to get the last visible row in a specific group
const getLastVisibleInGroup = (groupKeys: TransactionDetailsRowKey[]) => {
const visibleInGroup = groupKeys.filter((key) => rowVisibilityConfig[key])
return visibleInGroup[visibleInGroup.length - 1]
}

// define row groups
const rowGroups = useMemo(
() => ({
dateRows: ['createdAt', 'cancelled', 'claimed', 'completed', 'closed'] as TransactionDetailsRowKey[],
txnDetails: ['tokenAndNetwork', 'txId'] as TransactionDetailsRowKey[],
fees: ['networkFee', 'peanutFee'] as TransactionDetailsRowKey[],
}),
[]
)

// get last visible row for each group
const lastVisibleInGroups = useMemo(
() => ({
dateRows: getLastVisibleInGroup(rowGroups.dateRows),
txnDetails: getLastVisibleInGroup(rowGroups.txnDetails),
fees: getLastVisibleInGroup(rowGroups.fees),
}),
[rowVisibilityConfig]
)

// reusable helper to check if border should be hidden for a row in a specific group
const shouldHideGroupBorder = (rowKey: TransactionDetailsRowKey, groupName: keyof typeof rowGroups) => {
const isLastInGroup = rowKey === lastVisibleInGroups[groupName]
const isGlobalLast = shouldHideBorder(rowKey)

// if it's the last in its group, show border UNLESS it's also the global last
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

if (isLastInGroup) {
return isGlobalLast
}

// if not last in group, always hide border
return true
}

const isPendingRequestee = useMemo(() => {
if (!transaction) return false
return (
Expand Down Expand Up @@ -548,10 +588,46 @@ export const TransactionDetailsReceipt = ({
<PaymentInfoRow
label={'Created'}
value={formatDate(new Date(transaction.createdAt!.toString()))}
hideBottomBorder={shouldHideBorder('createdAt')}
hideBottomBorder={shouldHideGroupBorder('createdAt', 'dateRows')}
/>
)}

{rowVisibilityConfig.cancelled && (
<PaymentInfoRow
label="Cancelled"
value={formatDate(new Date(transaction.cancelledDate!))}
hideBottomBorder={shouldHideGroupBorder('cancelled', 'dateRows')}
/>
)}

{rowVisibilityConfig.claimed && (
<PaymentInfoRow
label="Claimed"
value={formatDate(new Date(transaction.claimedAt!))}
hideBottomBorder={shouldHideGroupBorder('claimed', 'dateRows')}
/>
)}

{rowVisibilityConfig.completed && (
<PaymentInfoRow
label={getLabelText(transaction)}
value={formatDate(new Date(transaction.completedAt!))}
hideBottomBorder={shouldHideGroupBorder('completed', 'dateRows')}
/>
)}

{rowVisibilityConfig.closed && (
<>
{transaction.cancelledDate && (
<PaymentInfoRow
label="Closed at"
value={formatDate(new Date(transaction.cancelledDate))}
hideBottomBorder={shouldHideBorder('closed')}
/>
)}
</>
)}

{rowVisibilityConfig.to && (
<PaymentInfoRow
label={'To'}
Expand Down Expand Up @@ -620,7 +696,7 @@ export const TransactionDetailsReceipt = ({
</div>
)
}
hideBottomBorder={shouldHideBorder('tokenAndNetwork')}
hideBottomBorder={shouldHideGroupBorder('tokenAndNetwork', 'txnDetails')}
/>
)}
</>
Expand All @@ -647,56 +723,10 @@ export const TransactionDetailsReceipt = ({
</div>
)
}
hideBottomBorder={shouldHideBorder('txId')}
hideBottomBorder={shouldHideGroupBorder('txId', 'txnDetails')}
/>
)}

{rowVisibilityConfig.cancelled && (
<>
{transaction.cancelledDate && (
<PaymentInfoRow
label="Cancelled"
value={formatDate(new Date(transaction.cancelledDate))}
hideBottomBorder={shouldHideBorder('cancelled')}
/>
)}
</>
)}

{rowVisibilityConfig.closed && (
<>
{transaction.cancelledDate && (
<PaymentInfoRow
label="Closed at"
value={formatDate(new Date(transaction.cancelledDate))}
hideBottomBorder={shouldHideBorder('closed')}
/>
)}
</>
)}

{rowVisibilityConfig.claimed && (
<>
{transaction.claimedAt && (
<PaymentInfoRow
label="Claimed"
value={formatDate(new Date(transaction.claimedAt))}
hideBottomBorder={shouldHideBorder('claimed')}
/>
)}
</>
)}

{rowVisibilityConfig.completed && (
<>
<PaymentInfoRow
label={getLabelText(transaction)}
value={formatDate(new Date(transaction.completedAt!))}
hideBottomBorder={shouldHideBorder('completed')}
/>
</>
)}

{rowVisibilityConfig.fee && (
<PaymentInfoRow label="Fee" value={feeDisplay} hideBottomBorder={shouldHideBorder('fee')} />
)}
Expand Down Expand Up @@ -739,6 +769,7 @@ export const TransactionDetailsReceipt = ({
<PaymentInfoRow
label={`Value in ${transaction.currency!.code}`}
value={`${transaction.currency!.code} ${formatCurrency(transaction.currency!.amount)}`}
hideBottomBorder
/>
)}
{/* TODO: stop using snake_case!!!!! */}
Expand Down Expand Up @@ -844,7 +875,7 @@ export const TransactionDetailsReceipt = ({
/>
</div>
}
hideBottomBorder={false}
hideBottomBorder={true}
/>
<PaymentInfoRow
label="Bank Address"
Expand Down Expand Up @@ -885,7 +916,7 @@ export const TransactionDetailsReceipt = ({
/>
</div>
}
hideBottomBorder={false}
hideBottomBorder={true}
/>
<PaymentInfoRow
label="BIC"
Expand Down Expand Up @@ -994,7 +1025,7 @@ export const TransactionDetailsReceipt = ({
/>
</div>
}
hideBottomBorder={false}
hideBottomBorder={true}
/>
)}
{transaction.extraDataForDrawer.depositInstructions
Expand Down Expand Up @@ -1028,13 +1059,6 @@ export const TransactionDetailsReceipt = ({
</>
)}

{rowVisibilityConfig.peanutFee && (
<PaymentInfoRow
label="Peanut fee"
value={'Sponsored by Peanut!'}
hideBottomBorder={shouldHideBorder('peanutFee')}
/>
)}
{rowVisibilityConfig.points && transaction.points && (
<PaymentInfoRow
label="Points earned"
Expand All @@ -1061,7 +1085,15 @@ export const TransactionDetailsReceipt = ({
label="Network fee"
value={transaction.networkFeeDetails!.amountDisplay}
moreInfoText={transaction.networkFeeDetails!.moreInfoText}
hideBottomBorder={shouldHideBorder('networkFee')}
hideBottomBorder={shouldHideGroupBorder('networkFee', 'fees')}
/>
)}

{rowVisibilityConfig.peanutFee && (
<PaymentInfoRow
label="Peanut fee"
value={'Sponsored by Peanut!'}
hideBottomBorder={shouldHideGroupBorder('peanutFee', 'fees')}
/>
)}

Expand Down
13 changes: 7 additions & 6 deletions src/components/TransactionDetails/transaction-details.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,27 @@ export type TransactionDetailsRowKey =
| 'mantecaDepositInfo'
| 'closed'

// order of the rows in the receipt
// order of the rows in the receipt (must match actual rendering order in component)
export const transactionDetailsRowKeys: TransactionDetailsRowKey[] = [
'createdAt',
'to',
'tokenAndNetwork',
'txId',
'cancelled',
'claimed',
'completed',
'closed',
'to',
'tokenAndNetwork',
'txId',
'fee',
'mantecaDepositInfo',
'exchangeRate',
'bankAccountDetails',
'transferId',
'depositInstructions',
'peanutFee',
'points',
'comment',
'networkFee',
'peanutFee',
'attachment',
'closed',
]

export const getBankAccountLabel = (type: string) => {
Expand Down
Loading