Skip to content

Commit 2b05de2

Browse files
authored
Merge pull request #9 from MakerXStudio/transaction-to-self
chore: display transaction to self
2 parents 587c2d8 + 44c63d4 commit 2b05de2

File tree

1 file changed

+51
-20
lines changed

1 file changed

+51
-20
lines changed

src/features/transactions/components/transaction-view-visual.tsx

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,49 @@ const DisplayArrow = fixedForwardRef(
143143
}
144144
)
145145

146-
const DisplaySelfTransaction = fixedForwardRef((props: object, ref?: React.LegacyRef<HTMLDivElement>) => {
147-
return (
148-
<div ref={ref} className={cn('flex items-center justify-center')} {...props}>
149-
<SvgCircle width={graphConfig.circleDimension} height={graphConfig.circleDimension}></SvgCircle>
150-
</div>
151-
)
152-
})
146+
const DisplaySelfTransaction = fixedForwardRef(
147+
({ transaction, arrow, ...rest }: { transaction: TransactionModel; arrow: Arrow }, ref?: React.LegacyRef<HTMLDivElement>) => {
148+
const color = graphConfig.paymentTransactionColor
149+
150+
return (
151+
<div
152+
ref={ref}
153+
className={cn('flex items-center justify-center relative')}
154+
{...rest}
155+
style={{
156+
gridColumnStart: arrow.from + 2, // 2 to offset the name column
157+
gridColumnEnd: arrow.to + 4, // 4 to offset the name column and make this cell span 2 columns
158+
color: color,
159+
}}
160+
>
161+
<SvgCircle width={graphConfig.circleDimension} height={graphConfig.circleDimension}></SvgCircle>
162+
<div
163+
style={{
164+
width: `calc(50% - ${graphConfig.circleDimension / 2}px)`,
165+
height: `${graphConfig.circleDimension}px`,
166+
}}
167+
>
168+
<SvgPointerLeft className={cn('relative')} style={{ left: `calc(50% + ${graphConfig.circleDimension})px` }} />
169+
</div>
170+
<div
171+
className="absolute size-1/2"
172+
style={{
173+
borderWidth: graphConfig.lineWidth,
174+
borderColor: color,
175+
borderRadius: '4px',
176+
bottom: graphConfig.lineWidth / 2,
177+
right: `calc(25% - ${graphConfig.lineWidth * 2}px)`,
178+
}}
179+
></div>
180+
<div className={cn('absolute text-foreground right-1/4 w-[40%] flex justify-center')}>
181+
{transaction.type === TransactionType.Payment && (
182+
<DisplayAlgo className={cn('w-min pl-1 pr-1 bg-card')} amount={transaction.amount} />
183+
)}
184+
</div>
185+
</div>
186+
)
187+
}
188+
)
153189

154190
function PaymentTransactionToolTipContent({ transaction }: { transaction: TransactionModel }) {
155191
const items = useMemo(
@@ -221,22 +257,15 @@ function TransactionRow({
221257
</div>
222258
{accounts.map((_, index) => {
223259
if (index < arrow.from || index > arrow.to) return <div key={index}></div>
224-
if (index === arrow.from && index === arrow.to)
225-
return (
226-
<Tooltip key={index}>
227-
<TooltipTrigger asChild>
228-
<DisplaySelfTransaction />
229-
</TooltipTrigger>
230-
<TooltipContent>
231-
{transaction.type === TransactionType.Payment && <PaymentTransactionToolTipContent transaction={transaction} />}
232-
</TooltipContent>
233-
</Tooltip>
234-
)
235260
if (index === arrow.from)
236261
return (
237262
<Tooltip key={index}>
238263
<TooltipTrigger asChild>
239-
<DisplayArrow key={index} arrow={arrow} transaction={transaction} />
264+
{index === arrow.to ? (
265+
<DisplaySelfTransaction key={index} arrow={arrow} transaction={transaction} />
266+
) : (
267+
<DisplayArrow key={index} arrow={arrow} transaction={transaction} />
268+
)}
240269
</TooltipTrigger>
241270
<TooltipContent>
242271
{transaction.type === TransactionType.Payment && <PaymentTransactionToolTipContent transaction={transaction} />}
@@ -300,12 +329,13 @@ export function TransactionViewVisual({ transaction }: Props) {
300329
])
301330
)
302331
const maxNestingLevel = Math.max(...flattenedTransactions.map((t) => t.nestingLevel))
332+
const gridAccountColumns = accounts.length + 1 // +1 is to support transactions with the same sender and receiver
303333

304334
return (
305335
<div
306336
className={cn('relative grid')}
307337
style={{
308-
gridTemplateColumns: `minmax(${graphConfig.colWidth}px, ${graphConfig.colWidth + maxNestingLevel * graphConfig.indentationWidth}px) repeat(${accounts.length}, ${graphConfig.colWidth}px)`,
338+
gridTemplateColumns: `minmax(${graphConfig.colWidth}px, ${graphConfig.colWidth + maxNestingLevel * graphConfig.indentationWidth}px) repeat(${gridAccountColumns}, ${graphConfig.colWidth}px)`,
309339
gridTemplateRows: `repeat(${transactionCount + 1}, ${graphConfig.rowHeight}px)`,
310340
}}
311341
>
@@ -315,6 +345,7 @@ export function TransactionViewVisual({ transaction }: Props) {
315345
<AccountId id={account} />
316346
</div>
317347
))}
348+
<div>{/* The last header cell is empty to support transactions with the same sender and receiver */}</div>
318349
{/* The below div is for drawing the background dash lines */}
319350
<div className={cn('absolute right-0 -z-10')} style={{ top: `${graphConfig.rowHeight}px` }}>
320351
<div>

0 commit comments

Comments
 (0)