diff --git a/src/components/TransactionDetails/TransactionDetailsReceipt.tsx b/src/components/TransactionDetails/TransactionDetailsReceipt.tsx index 02a1c649e..304c1542b 100644 --- a/src/components/TransactionDetails/TransactionDetailsReceipt.tsx +++ b/src/components/TransactionDetails/TransactionDetailsReceipt.tsx @@ -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 + if (isLastInGroup) { + return isGlobalLast + } + + // if not last in group, always hide border + return true + } + const isPendingRequestee = useMemo(() => { if (!transaction) return false return ( @@ -548,10 +588,46 @@ export const TransactionDetailsReceipt = ({ + )} + + {rowVisibilityConfig.cancelled && ( + + )} + + {rowVisibilityConfig.claimed && ( + + )} + + {rowVisibilityConfig.completed && ( + )} + {rowVisibilityConfig.closed && ( + <> + {transaction.cancelledDate && ( + + )} + + )} + {rowVisibilityConfig.to && ( ) } - hideBottomBorder={shouldHideBorder('tokenAndNetwork')} + hideBottomBorder={shouldHideGroupBorder('tokenAndNetwork', 'txnDetails')} /> )} @@ -647,56 +723,10 @@ export const TransactionDetailsReceipt = ({ ) } - hideBottomBorder={shouldHideBorder('txId')} + hideBottomBorder={shouldHideGroupBorder('txId', 'txnDetails')} /> )} - {rowVisibilityConfig.cancelled && ( - <> - {transaction.cancelledDate && ( - - )} - - )} - - {rowVisibilityConfig.closed && ( - <> - {transaction.cancelledDate && ( - - )} - - )} - - {rowVisibilityConfig.claimed && ( - <> - {transaction.claimedAt && ( - - )} - - )} - - {rowVisibilityConfig.completed && ( - <> - - - )} - {rowVisibilityConfig.fee && ( )} @@ -739,6 +769,7 @@ export const TransactionDetailsReceipt = ({ )} {/* TODO: stop using snake_case!!!!! */} @@ -844,7 +875,7 @@ export const TransactionDetailsReceipt = ({ /> } - hideBottomBorder={false} + hideBottomBorder={true} /> } - hideBottomBorder={false} + hideBottomBorder={true} /> } - hideBottomBorder={false} + hideBottomBorder={true} /> )} {transaction.extraDataForDrawer.depositInstructions @@ -1028,13 +1059,6 @@ export const TransactionDetailsReceipt = ({ )} - {rowVisibilityConfig.peanutFee && ( - - )} {rowVisibilityConfig.points && transaction.points && ( + )} + + {rowVisibilityConfig.peanutFee && ( + )} diff --git a/src/components/TransactionDetails/transaction-details.utils.ts b/src/components/TransactionDetails/transaction-details.utils.ts index 73fa42274..e1b93915b 100644 --- a/src/components/TransactionDetails/transaction-details.utils.ts +++ b/src/components/TransactionDetails/transaction-details.utils.ts @@ -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) => {