Skip to content

Commit

Permalink
chore: wip - group transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickDinh committed Mar 19, 2024
1 parent dd50145 commit 2c1c543
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/assets/svg/circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/features/common/components/svg/circle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as React from "react";
import type { SVGProps } from "react";
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>;
export default SvgCircle;
52 changes: 50 additions & 2 deletions src/features/transactions/pages/group-page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import SvgCircle from '@/features/common/components/svg/circle'
import { cn } from '@/features/common/utils'
import { useMemo, useState } from 'react'

Check warning on line 3 in src/features/transactions/pages/group-page.tsx

View workflow job for this annotation

GitHub Actions / CI / node-ci

'useState' is defined but never used

type AccountFoo = {
account: string
// the status for the arrow only
status: 'from' | 'to' | 'middle' | 'outside'
}

type TransactionTrProps = {
transaction: Transaction
Expand All @@ -20,6 +28,30 @@ function TransactionTr({
indentLevel = 0,
verticalBars,
}: TransactionTrProps) {
const accountsWithStatus = useMemo(() => {
let a = false
return accounts.map<AccountFoo>((account) => {
if (transaction.sender === account) {
a = !a
return {
account: account,
status: 'from',
}
}
if (transaction.receiver === account) {
a = !a
return {
account: account,
status: 'to',
}
}
return {
account: account,
status: a ? 'middle' : 'outside',
}
})
}, [accounts, transaction.receiver, transaction.sender])

return (
<>
<tr>
Expand All @@ -44,9 +76,25 @@ function TransactionTr({
)}
</div>
</td>
{accounts.map((account, index) => (
{accountsWithStatus.map((account, index) => (
<td key={index} className={cn('p-0 relative')}>
<div className={cn('h-10 border-l-2 border-muted border-dashed absolute left-[50%]')}></div>
{/* TODO: fix the calc, it doesn't look good */}
<div className={cn('h-10 border-l-2 border-muted border-dashed absolute left-[calc(50%-1px)] -z-10')}></div>
{account.status === 'from' && (
<div className={cn('h-10 absolute left-[50%] translate-x-[-50%] translate-y-[-25%] z-10')}>
<SvgCircle />
</div>
)}
{account.status === 'from' && <div className={cn('border-primary w-[50%] border-b-2 translate-x-[100%]')}></div>}

<div className={cn('flex justify-center items-center relative')}>
{account.status === 'to' && (
<div>
<SvgCircle />
</div>
)}
{account.status === 'middle' && <div className={cn('border-primary w-full border-b-2')}></div>}
</div>
</td>
))}
</tr>
Expand Down

0 comments on commit 2c1c543

Please sign in to comment.