Skip to content

Commit 2c1c543

Browse files
committed
chore: wip - group transaction
1 parent dd50145 commit 2c1c543

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

src/assets/svg/circle.svg

Lines changed: 6 additions & 0 deletions
Loading
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as React from "react";
2+
import type { SVGProps } from "react";
3+
const SvgCircle = (props: SVGProps<SVGSVGElement>) => <svg xmlnsXlink="http://www.w3.org/1999/xlink" width="21px" height="21px" viewBox="0 0 21 21" xmlns="http://www.w3.org/2000/svg" {...props}><g transform="matrix(1 0 0 1 -153 -143 )"><path d="M 163.5 143 C 169.38 143 174 147.62 174 153.5 C 174 159.38 169.38 164 163.5 164 C 157.62 164 153 159.38 153 153.5 C 153 147.62 157.62 143 163.5 143 Z " fillRule="nonzero" fill="currentColor" stroke="none" /></g></svg>;
4+
export default SvgCircle;

src/features/transactions/pages/group-page.tsx

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
import SvgCircle from '@/features/common/components/svg/circle'
12
import { 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

311
type 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

Comments
 (0)