1+ import SvgCircle from '@/features/common/components/svg/circle'
12import { cn } from '@/features/common/utils'
3+ import { useMemo , useState } from 'react'
4+
5+ type AccountFoo = {
6+ account : string
7+ // the status for the arrow only
8+ status : 'from' | 'to' | 'middle' | 'outside'
9+ }
210
311type TransactionTrProps = {
412 transaction : Transaction
@@ -20,6 +28,30 @@ function TransactionTr({
2028 indentLevel = 0 ,
2129 verticalBars,
2230} : TransactionTrProps ) {
31+ const accountsWithStatus = useMemo ( ( ) => {
32+ let a = false
33+ return accounts . map < AccountFoo > ( ( account ) => {
34+ if ( transaction . sender === account ) {
35+ a = ! a
36+ return {
37+ account : account ,
38+ status : 'from' ,
39+ }
40+ }
41+ if ( transaction . receiver === account ) {
42+ a = ! a
43+ return {
44+ account : account ,
45+ status : 'to' ,
46+ }
47+ }
48+ return {
49+ account : account ,
50+ status : a ? 'middle' : 'outside' ,
51+ }
52+ } )
53+ } , [ accounts , transaction . receiver , transaction . sender ] )
54+
2355 return (
2456 < >
2557 < tr >
@@ -44,9 +76,25 @@ function TransactionTr({
4476 ) }
4577 </ div >
4678 </ td >
47- { accounts . map ( ( account , index ) => (
79+ { accountsWithStatus . map ( ( account , index ) => (
4880 < td key = { index } className = { cn ( 'p-0 relative' ) } >
49- < div className = { cn ( 'h-10 border-l-2 border-muted border-dashed absolute left-[50%]' ) } > </ div >
81+ { /* TODO: fix the calc, it doesn't look good */ }
82+ < div className = { cn ( 'h-10 border-l-2 border-muted border-dashed absolute left-[calc(50%-1px)] -z-10' ) } > </ div >
83+ { account . status === 'from' && (
84+ < div className = { cn ( 'h-10 absolute left-[50%] translate-x-[-50%] translate-y-[-25%] z-10' ) } >
85+ < SvgCircle />
86+ </ div >
87+ ) }
88+ { account . status === 'from' && < div className = { cn ( 'border-primary w-[50%] border-b-2 translate-x-[100%]' ) } > </ div > }
89+
90+ < div className = { cn ( 'flex justify-center items-center relative' ) } >
91+ { account . status === 'to' && (
92+ < div >
93+ < SvgCircle />
94+ </ div >
95+ ) }
96+ { account . status === 'middle' && < div className = { cn ( 'border-primary w-full border-b-2' ) } > </ div > }
97+ </ div >
5098 </ td >
5199 ) ) }
52100 </ tr >
0 commit comments