Skip to content

Commit e04c340

Browse files
authored
chore: tweaks as part of checking ACs (#15)
* chore: change from/to -> sender/receiver * chore: handle id shortening differently to address shortening * chore: a few different tweak I noticed * chore: bage multisig and logicSig transactions * chore: handle close remainder
1 parent 340a3a1 commit e04c340

18 files changed

+224
-145
lines changed

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
1515
"lint:fix": "eslint . --ext ts,tsx --fix",
1616
"preview": "vite preview",
17-
"test": "vitest",
17+
"test": "vitest run",
18+
"test:watch": "vitest watch",
1819
"audit": "better-npm-audit audit",
1920
"check-types": "tsc --noEmit && npx --yes madge src/App.tsx --circular",
20-
"tauri": "tauri"
21+
"tauri": "tauri",
22+
"pre-commit": "run-s check-types lint:fix audit test"
2123
},
2224
"dependencies": {
2325
"@algorandfoundation/algokit-subscriber": "^1.2.0",
@@ -138,4 +140,4 @@
138140
"semantic-release-export-data"
139141
]
140142
}
141-
}
143+
}

src/features/common/components/badge.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { cva, type VariantProps } from 'class-variance-authority'
44
import { cn } from '@/features/common/utils'
55

66
const badgeVariants = cva(
7-
'inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2',
7+
'inline-flex items-center rounded-full border px-2 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2',
88
{
99
variants: {
1010
variant: {

src/features/explore/pages/explore-page.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
import { LatestBlocks } from '@/features/blocks/components/latest-blocks'
22
import { cn } from '@/features/common/utils'
33
import { TemplatedNavLink } from '@/features/routing/components/templated-nav-link/templated-nav-link'
4+
import { TransactionIdLink } from '@/features/transactions/components/transaction-id-link'
45
import { Urls } from '@/routes/urls'
56

67
export function ExplorePage() {
78
return (
89
<div className={cn('grid')}>
9-
<TemplatedNavLink
10-
urlTemplate={Urls.Explore.Transaction.ById}
11-
urlParams={{ transactionId: 'QOOBRVQMX4HW5QZ2EGLQDQCQTKRF3UP3JKDGKYPCXMI6AVV35KQA' }}
12-
>
13-
View sample transaction
14-
</TemplatedNavLink>
10+
<TransactionIdLink transactionId="ILDCD5Z64CYSLEZIHBG5DVME2ITJI2DIVZAPDPEWPCYMTRA5SVGA">View sample transaction</TransactionIdLink>
1511
<TemplatedNavLink urlTemplate={Urls.Explore.Group.ById} urlParams={{ groupId: 'foo' }}>
1612
View sample group
1713
</TemplatedNavLink>
18-
1914
<LatestBlocks />
2015
</div>
2116
)

src/features/transactions/components/__snapshots__/transaction-view-visual.FBORGSDC4ULLWHWZUMUFIYQLSDC26HGLTFD7EATQDY37FHCIYBBQ.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
class="inline"
7171
style="margin-left: 16px;"
7272
>
73-
FBOR...YBBQ
73+
FBORGSD...
7474
</div>
7575
</div>
7676
</div>

src/features/transactions/components/__snapshots__/transaction-view-visual.ILDCD5Z64CYSLEZIHBG5DVME2ITJI2DIVZAPDPEWPCYMTRA5SVGA.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
class="inline"
5454
style="margin-left: 16px;"
5555
>
56-
ILDC...SVGA
56+
ILDCD5Z...
5757
</div>
5858
</div>
5959
</div>

src/features/transactions/components/payment-transaction.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TransactionResult } from '@algorandfoundation/algokit-utils/types/index
1010
import { DescriptionList } from '@/features/common/components/description-list'
1111
import { TransactionViewVisual } from './transaction-view-visual'
1212
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/features/common/components/tabs'
13-
import { TransactionViewTable } from './transaction-view-table'
13+
import { TransactionViewTable, transactionAmountLabel, transactionReceiverLabel, transactionSenderLabel } from './transaction-view-table'
1414
import { Multisig } from './multisig'
1515
import { Logicsig } from './logicsig'
1616

@@ -24,32 +24,50 @@ const tableTransactionDetailsTabId = 'table'
2424
export const transactionDetailsLabel = 'View Transaction Details'
2525
export const visualTransactionDetailsTabLabel = 'Visual'
2626
export const tableTransactionDetailsTabLabel = 'Table'
27+
export const transactionCloseRemainderToLabel = 'Close Remainder To'
28+
export const transactionCloseRemainderAmountLabel = 'Close Remainder Amount'
2729

2830
export function PaymentTransaction({ transaction, rawTransaction }: PaymentTransactionProps) {
2931
const paymentTransactionItems = useMemo(
3032
() => [
3133
{
32-
dt: 'Sender',
34+
dt: transactionSenderLabel,
3335
dd: (
3436
<a href="#" className={cn('text-primary underline')}>
3537
{transaction.sender}
3638
</a>
3739
),
3840
},
3941
{
40-
dt: 'Receiver',
42+
dt: transactionReceiverLabel,
4143
dd: (
4244
<a href="#" className={cn('text-primary underline')}>
4345
{transaction.receiver}
4446
</a>
4547
),
4648
},
4749
{
48-
dt: 'Amount',
50+
dt: transactionAmountLabel,
4951
dd: <DisplayAlgo amount={transaction.amount} />,
5052
},
53+
...(transaction.closeRemainder
54+
? [
55+
{
56+
dt: transactionCloseRemainderToLabel,
57+
dd: (
58+
<a href="#" className={cn('text-primary underline')}>
59+
{transaction.closeRemainder.to}
60+
</a>
61+
),
62+
},
63+
{
64+
dt: transactionCloseRemainderAmountLabel,
65+
dd: <DisplayAlgo amount={transaction.closeRemainder.amount} />,
66+
},
67+
]
68+
: []),
5169
],
52-
[transaction.sender, transaction.receiver, transaction.amount]
70+
[transaction.sender, transaction.receiver, transaction.amount, transaction.closeRemainder]
5371
)
5472

5573
return (
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { TemplatedNavLink } from '@/features/routing/components/templated-nav-link/templated-nav-link'
2+
import { Urls } from '@/routes/urls'
3+
import { ellipseId } from '@/utils/ellipse-id'
4+
import { PropsWithChildren } from 'react'
5+
6+
type Props = PropsWithChildren<{
7+
transactionId: string
8+
short?: boolean
9+
}>
10+
11+
export function TransactionIdLink({ transactionId, short = false, children }: Props) {
12+
return (
13+
<TemplatedNavLink urlTemplate={Urls.Explore.Transaction.ById} urlParams={{ transactionId: transactionId }}>
14+
{children ? children : short ? ellipseId(transactionId) : transactionId}
15+
</TemplatedNavLink>
16+
)
17+
}

src/features/transactions/components/transaction-info.tsx

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { cn } from '@/features/common/utils'
33
import { dateFormatter } from '@/utils/format'
44
import { DisplayAlgo } from '@/features/common/components/display-algo'
55
import { useMemo } from 'react'
6-
import { PaymentTransactionModel } from '../models'
6+
import { PaymentTransactionModel, SignatureType } from '../models'
77
import { DescriptionList } from '@/features/common/components/description-list'
8-
import { isDefined } from '@/utils/is-defined'
8+
import { Badge } from '@/features/common/components/badge'
99

1010
type Props = {
1111
transaction: PaymentTransactionModel
@@ -20,44 +20,67 @@ export const transactionFeeLabel = 'Fee'
2020

2121
export function TransactionInfo({ transaction }: Props) {
2222
const transactionInfoItems = useMemo(
23-
() =>
24-
[
25-
{
26-
dt: transactionIdLabel,
27-
dd: transaction.id,
28-
},
29-
{
30-
dt: transactionTypeLabel,
31-
dd: transaction.type,
32-
},
33-
{
34-
dt: transactionTimestampLabel,
35-
dd: dateFormatter.asLongDateTime(new Date(transaction.roundTime)),
36-
},
37-
{
38-
dt: transactionBlockLabel,
39-
dd: (
40-
<a href="#" className={cn('text-primary underline')}>
41-
{transaction.confirmedRound}
42-
</a>
43-
),
44-
},
45-
transaction.group
46-
? {
23+
() => [
24+
{
25+
dt: transactionIdLabel,
26+
dd: transaction.id,
27+
},
28+
{
29+
dt: transactionTypeLabel,
30+
dd: (
31+
<>
32+
{transaction.type}
33+
{transaction.signature?.type === SignatureType.Multi && (
34+
<Badge className={cn('ml-2')} variant="outline">
35+
Multisig
36+
</Badge>
37+
)}
38+
{transaction.signature?.type === SignatureType.Logic && (
39+
<Badge className={cn('ml-2')} variant="outline">
40+
LogicSig
41+
</Badge>
42+
)}
43+
</>
44+
),
45+
},
46+
{
47+
dt: transactionTimestampLabel,
48+
dd: dateFormatter.asLongDateTime(new Date(transaction.roundTime)),
49+
},
50+
{
51+
dt: transactionBlockLabel,
52+
dd: (
53+
<a href="#" className={cn('text-primary underline')}>
54+
{transaction.confirmedRound}
55+
</a>
56+
),
57+
},
58+
...(transaction.group
59+
? [
60+
{
4761
dt: transactionGroupLabel,
4862
dd: (
4963
<a href="#" className={cn('text-primary underline')}>
5064
{transaction.group}
5165
</a>
5266
),
53-
}
54-
: undefined,
55-
{
56-
dt: transactionFeeLabel,
57-
dd: transaction.fee ? <DisplayAlgo amount={transaction.fee} /> : 'N/A',
58-
},
59-
].filter(isDefined),
60-
[transaction.confirmedRound, transaction.fee, transaction.group, transaction.id, transaction.roundTime, transaction.type]
67+
},
68+
]
69+
: []),
70+
{
71+
dt: transactionFeeLabel,
72+
dd: transaction.fee ? <DisplayAlgo amount={transaction.fee} /> : 'N/A',
73+
},
74+
],
75+
[
76+
transaction.confirmedRound,
77+
transaction.fee,
78+
transaction.group,
79+
transaction.id,
80+
transaction.roundTime,
81+
transaction.signature?.type,
82+
transaction.type,
83+
]
6184
)
6285

6386
return (

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { DisplayAlgo } from '@/features/common/components/display-algo'
44
import { ellipseAddress } from '@/utils/ellipse-address'
55
import { flattenInnerTransactions } from '@/utils/flatten-inner-transactions'
66
import { useMemo } from 'react'
7+
import { ellipseId } from '@/utils/ellipse-id'
78

89
const graphConfig = {
910
indentationWidth: 20,
@@ -13,6 +14,10 @@ type Props = {
1314
transaction: TransactionModel
1415
}
1516

17+
export const transactionSenderLabel = 'Sender'
18+
export const transactionReceiverLabel = 'Receiver'
19+
export const transactionAmountLabel = 'Amount'
20+
1621
export function TransactionViewTable({ transaction }: Props) {
1722
const flattenedTransactions = useMemo(() => flattenInnerTransactions(transaction), [transaction])
1823

@@ -21,10 +26,10 @@ export function TransactionViewTable({ transaction }: Props) {
2126
<thead>
2227
<tr>
2328
<th className={cn('border-2')}>Transaction ID</th>
24-
<th className={cn('p-2 border-2')}>From</th>
25-
<th className={cn('p-2 border-2')}>To</th>
29+
<th className={cn('p-2 border-2')}>{transactionSenderLabel}</th>
30+
<th className={cn('p-2 border-2')}>{transactionReceiverLabel}</th>
2631
<th className={cn('p-2 border-2')}>Type</th>
27-
<th className={cn('p-2 border-2')}>Amount</th>
32+
<th className={cn('p-2 border-2')}>{transactionAmountLabel}</th>
2833
</tr>
2934
</thead>
3035
<tbody>
@@ -36,7 +41,7 @@ export function TransactionViewTable({ transaction }: Props) {
3641
marginLeft: `${graphConfig.indentationWidth * nestingLevel}px`,
3742
}}
3843
>
39-
{ellipseAddress(transaction.id)}
44+
{ellipseId(transaction.id)}
4045
</div>
4146
</td>
4247
<td className={cn('p-2 border-2 text-center')}>{ellipseAddress(transaction.sender)}</td>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import { TransactionResult } from '@algorandfoundation/algokit-utils/types/index
1717
// - Update the snapshot files by running `vitest -u`. Or if the test runner is running, press `u` to update the snapshots.
1818
describe('transaction-view-visual', () => {
1919
describe.each([
20-
transactionModelMother['mainnet-FBORGSDC4ULLWHWZUMUFIYQLSDC26HGLTFD7EATQDY37FHCIYBBQ'](),
21-
transactionModelMother['mainnet-ILDCD5Z64CYSLEZIHBG5DVME2ITJI2DIVZAPDPEWPCYMTRA5SVGA'](),
22-
])('when rendering transaction %d', (transaction: TransactionResult) => {
20+
transactionModelMother['mainnet-FBORGSDC4ULLWHWZUMUFIYQLSDC26HGLTFD7EATQDY37FHCIYBBQ']().build(),
21+
transactionModelMother['mainnet-ILDCD5Z64CYSLEZIHBG5DVME2ITJI2DIVZAPDPEWPCYMTRA5SVGA']().build(),
22+
])('when rendering transaction $id', (transaction: TransactionResult) => {
2323
it('should match snapshot', () => {
2424
const model = asPaymentTransaction(transaction)
2525

0 commit comments

Comments
 (0)