Skip to content

Commit dd47f8e

Browse files
committed
Add embeddable receipts
1 parent 8adbe8b commit dd47f8e

File tree

5 files changed

+707
-26
lines changed

5 files changed

+707
-26
lines changed

apps/explorer/src/components/Address.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,26 @@ import type { Address as AddressType } from 'ox'
33
import { HexFormatter } from '#lib/formatting'
44

55
export function Address(props: Address.Props) {
6-
const { address, chars, self, className } = props
6+
const { address, chars, self, className, framed = false } = props
77
return (
88
<>
9-
<Link
10-
to="/account/$address"
11-
params={{ address }}
12-
title={address}
13-
className={className}
14-
>
15-
{HexFormatter.shortenHex(address, chars)}
16-
</Link>
9+
{framed ? (
10+
<span
11+
title={address}
12+
className={className}
13+
>
14+
{HexFormatter.shortenHex(address, chars)}
15+
</span>
16+
) : (
17+
<Link
18+
to="/account/$address"
19+
params={{ address }}
20+
title={address}
21+
className={className}
22+
>
23+
{HexFormatter.shortenHex(address, chars)}
24+
</Link>
25+
)}
1726
{self && <span className="text-tertiary"> (self)</span>}
1827
</>
1928
)
@@ -25,5 +34,6 @@ export namespace Address {
2534
chars?: number
2635
self?: boolean
2736
className?: string
37+
framed?: boolean
2838
}
2939
}

apps/explorer/src/components/EventDescription.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Address } from './Address.tsx'
88
import { Amount } from './Receipt/Amount.tsx'
99

1010
export function EventDescription(props: EventDescription.Props) {
11-
const { event, seenAs, className } = props
11+
const { event, seenAs, className, framed = false } = props
1212

1313
return (
1414
<div
@@ -55,6 +55,7 @@ export function EventDescription(props: EventDescription.Props) {
5555
address={part.value}
5656
className="text-accent items-end active:translate-y-[.5px] whitespace-nowrap"
5757
self={seenAs ? isAddressEqual(part.value, seenAs) : false}
58+
framed={framed}
5859
/>
5960
)
6061
case 'hex':
@@ -98,5 +99,6 @@ export namespace EventDescription {
9899
event: KnownEvent
99100
seenAs?: AddressType.Address
100101
className?: string | undefined
102+
framed?: boolean
101103
}
102104
}

apps/explorer/src/components/Receipt/Receipt.tsx

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Link } from '@tanstack/react-router'
22
import { type Address, Hex } from 'ox'
33
import { useState } from 'react'
4+
import ExternalLink from '~icons/lucide/external-link'
45
import { EventDescription } from '#components/EventDescription'
56
import { DateFormatter, HexFormatter, PriceFormatter } from '#lib/formatting'
67
import { useCopy } from '#lib/hooks'
@@ -16,6 +17,7 @@ export function Receipt(props: Receipt.Props) {
1617
events = [],
1718
fee,
1819
total,
20+
framed = false,
1921
} = props
2022
const [hashExpanded, setHashExpanded] = useState(false)
2123
const { copy, notifying } = useCopy()
@@ -29,24 +31,39 @@ export function Receipt(props: Receipt.Props) {
2931
<div className="flex flex-col gap-[8px] font-mono text-[13px] leading-[16px] flex-1">
3032
<div className="flex justify-between items-end">
3133
<span className="text-tertiary capitalize">Block</span>
32-
<Link
33-
to={'/block/$id'}
34-
params={{ id: Hex.fromNumber(blockNumber) }}
35-
className="text-accent text-right before:content-['#'] active:translate-y-[.5px]"
36-
>
37-
{String(blockNumber)}
38-
</Link>
34+
{framed ? (
35+
<span className="text-accent text-right before:content-['#']">
36+
{String(blockNumber)}
37+
</span>
38+
) : (
39+
<Link
40+
to={'/block/$id'}
41+
params={{ id: Hex.fromNumber(blockNumber) }}
42+
className="text-accent text-right before:content-['#'] active:translate-y-[.5px]"
43+
>
44+
{String(blockNumber)}
45+
</Link>
46+
)}
3947
</div>
4048
<div className="flex justify-between items-end">
4149
<span className="text-tertiary capitalize">Sender</span>
42-
<Link
43-
to={'/account/$address'}
44-
params={{ address: sender }}
45-
className="text-accent text-right active:translate-y-[.5px]"
46-
title={sender}
47-
>
48-
{HexFormatter.shortenHex(sender)}
49-
</Link>
50+
{framed ? (
51+
<span
52+
className="text-accent text-right"
53+
title={sender}
54+
>
55+
{HexFormatter.shortenHex(sender)}
56+
</span>
57+
) : (
58+
<Link
59+
to={'/account/$address'}
60+
params={{ address: sender }}
61+
className="text-accent text-right active:translate-y-[.5px]"
62+
title={sender}
63+
>
64+
{HexFormatter.shortenHex(sender)}
65+
</Link>
66+
)}
5067
</div>
5168
<div className="flex justify-between items-start">
5269
<div className="relative">
@@ -125,7 +142,7 @@ export function Receipt(props: Receipt.Props) {
125142
<div className="flex flex-row justify-between items-start gap-[10px]">
126143
<div className="flex flex-row items-start gap-[4px] grow min-w-0">
127144
<div className="flex items-center text-tertiary before:content-[counter(event)_'.'] shrink-0 leading-[24px]"></div>
128-
<EventDescription event={event} />
145+
<EventDescription event={event} framed={framed} />
129146
</div>
130147
<div className="flex items-center text-right shrink-0 leading-[24px]">
131148
{totalAmountBigInt > 0n && (
@@ -186,6 +203,23 @@ export function Receipt(props: Receipt.Props) {
186203
</div>
187204
</>
188205
)}
206+
{framed && (
207+
<>
208+
<div className="border-t border-dashed border-base-border" />
209+
<div className="flex justify-center px-[20px] py-[16px]">
210+
<Link
211+
to={'/tx/$hash'}
212+
params={{ hash }}
213+
target="_blank"
214+
rel="noopener noreferrer"
215+
className="text-accent text-[13px] font-mono active:translate-y-[.5px] flex items-center gap-[6px]"
216+
>
217+
View in Explorer
218+
<ExternalLink className="w-[14px] h-[14px]" />
219+
</Link>
220+
</div>
221+
</>
222+
)}
189223
</div>
190224
)
191225
}
@@ -199,5 +233,6 @@ export namespace Receipt {
199233
events?: KnownEvent[]
200234
fee?: number
201235
total?: number
236+
framed?: boolean
202237
}
203238
}

apps/explorer/src/routeTree.gen.ts

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)