Skip to content

Commit 47dccef

Browse files
authored
Merge pull request #39 from Quantus-Network/feat/some-updates
Some updates
2 parents 25589be + f0422ba commit 47dccef

11 files changed

Lines changed: 280 additions & 118 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
You are an Expert Staff Frontend Engineer performing a code review. Your goal is to ensure the code is robust, performant, accessible, and maintainable. You balance rigorous engineering standards with pragmatic delivery.
2+
3+
TECH STACK CONTEXT:
4+
5+
- Web Development (HTML5, CSS3, Modern Browser APIs)
6+
- TypeScript (Strict Mode)
7+
- JavaScript (ES6+)
8+
- React Ecosystem (Functional components, Hooks, Context)
9+
10+
REVIEW GUIDELINES:
11+
12+
1. TypeScript Rigor:
13+
14+
- Flag any use of `any`. Suggest specific types, `unknown`, or generics.
15+
- Catch overly permissive types or missing return types on complex functions.
16+
- If a custom type/interface is missing from the provided context, point it out only if it obscures a potential bug.
17+
18+
2. React Best Practices:
19+
20+
- Enforce the Rules of Hooks (e.g., missing dependencies in `useEffect` or `useCallback`).
21+
- Identify unnecessary re-renders. Suggest `useMemo` or `useCallback` ONLY where it objectively improves performance. Do not prematurely optimize.
22+
- Flag anti-patterns (e.g., using indexes as keys, mutating state directly, derived state).
23+
24+
3. Architecture & Clean Code:
25+
26+
- Highlight components violating the Single Responsibility Principle.
27+
- Catch duplicated logic that should be extracted into custom hooks or utilities.
28+
- Flag "magic strings/numbers" and suggest constants.
29+
30+
4. Web Vitals & Accessibility (a11y):
31+
32+
- Flag missing `alt` tags, incorrect ARIA attributes, or non-semantic HTML.
33+
- Note potential performance bottlenecks (e.g., missing lazy loading for heavy components).
34+
35+
5. Testing & Security:
36+
37+
- If tests are provided, flag tests that check implementation details rather than user behavior.
38+
- Flag potential XSS vulnerabilities (e.g., `dangerouslySetInnerHTML`).
39+
40+
OUTPUT FORMAT:
41+
Provide your review in structured Markdown. Use the following severity tags:
42+
43+
- [BLOCKER]: Critical bug, security flaw, or massive anti-pattern. Must fix.
44+
- [SUGGESTION]: Strong recommendation for better performance, typing, or readability.
45+
- [NITPICK]: Minor styling, naming conventions, or formatting.
46+
- [QUESTION]: Use this if the provided code snippet is missing critical context (e.g., an imported hook or state shape) needed to accurately review it.
47+
48+
For every issue found, provide:
49+
50+
1. File name and line number (if applicable).
51+
2. A brief, objective explanation of _why_ it is an issue.
52+
3. A short, corrected code snippet demonstrating the fix (only the modified lines).
53+
54+
TONE & BEHAVIOR:
55+
56+
- Be objective, constructive, and concise.
57+
- UNDER NO CIRCUMSTANCES should you include introductory or concluding conversational filler (e.g., "Here is your review," "Great job," or "Let me know if you need help").
58+
- Output ONLY the structured review.

src/components/common/table-columns/BLOCK_COLUMNS.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const BLOCK_COLUMNS = [
3535
id: 'extrinsicsCount',
3636
header: 'Extrinsics',
3737
cell: (props) => props.getValue(),
38-
enableSorting: false
38+
enableSorting: true
3939
}),
4040
columnHelper.accessor('reward', {
4141
id: 'reward',

src/components/common/table-columns/EXTRINSIC_COLUMNS.tsx

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TimestampDisplay } from '@/components/ui/timestamp-display';
55
import { RESOURCES } from '@/constants/resources';
66
import { cn } from '@/lib/utils';
77
import type { BlockExtrinsic } from '@/schemas/blocks';
8+
import { getExtrinsicDetailPath } from '@/utils/get-extrinsic-detail-path';
89
import { formatMonetaryValue, formatTxAddress } from '@/utils/formatter';
910

1011
const columnHelper = createColumnHelper<BlockExtrinsic>();
@@ -26,32 +27,7 @@ export const createExtrinsicColumns = () => {
2627
cell: (props) => {
2728
const hash = props.getValue();
2829
const { pallet, call } = props.row.original;
29-
30-
// Determine the appropriate resource based on pallet
31-
let href = '';
32-
if (pallet === 'Wormhole') {
33-
href = `${RESOURCES.wormhole}/${hash}`;
34-
} else if (pallet === 'Balances') {
35-
href = `${RESOURCES.transactions}/${hash}`;
36-
} else if (
37-
pallet === 'ReversibleTransfers' &&
38-
call === 'schedule_transfer'
39-
) {
40-
href = `${RESOURCES.scheduledReversibleTransactions}/${hash}`;
41-
} else if (
42-
pallet === 'ReversibleTransfers' &&
43-
call === 'execute_transfer'
44-
) {
45-
href = `${RESOURCES.executedReversibleTransactions}/${hash}`;
46-
} else if (
47-
pallet === 'ReversibleTransfers' &&
48-
call === 'cancel_transfer'
49-
) {
50-
href = `${RESOURCES.cancelledReversibleTransactions}/${hash}`;
51-
} else {
52-
// Default to transactions for now
53-
href = `${RESOURCES.transactions}/${hash}`;
54-
}
30+
const href = getExtrinsicDetailPath({ id: hash, pallet, call });
5531

5632
return (
5733
<LinkWithCopy

src/components/common/table-columns/TRANSACTION_COLUMNS.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { LinkWithCopy } from '@/components/ui/composites/link-with-copy/LinkWith
44
import { TimestampDisplay } from '@/components/ui/timestamp-display';
55
import { RESOURCES } from '@/constants/resources';
66
import type { Transaction } from '@/schemas';
7+
import { getExtrinsicDetailPath } from '@/utils/get-extrinsic-detail-path';
78
import { formatMonetaryValue, formatTxAddress } from '@/utils/formatter';
89

910
const columnHelper = createColumnHelper<Transaction>();
@@ -12,16 +13,26 @@ export const TRANSACTION_COLUMNS = [
1213
columnHelper.accessor('extrinsic.id', {
1314
id: 'tx-hash',
1415
header: 'Hash',
15-
cell: (props) =>
16-
props.getValue() ? (
16+
cell: (props) => {
17+
const extrinsicId = props.getValue();
18+
const extrinsic = props.row.original.extrinsic;
19+
20+
if (!extrinsicId || !extrinsic?.pallet || !extrinsic?.call) {
21+
return 'Is not available';
22+
}
23+
24+
return (
1725
<LinkWithCopy
18-
href={`${RESOURCES.transactions}/${props.getValue()}`}
19-
text={formatTxAddress(props.getValue() ?? '-')}
20-
textCopy={props.getValue() ?? ''}
26+
href={getExtrinsicDetailPath({
27+
id: extrinsicId,
28+
pallet: extrinsic.pallet,
29+
call: extrinsic.call
30+
})}
31+
text={formatTxAddress(extrinsicId)}
32+
textCopy={extrinsicId}
2133
/>
22-
) : (
23-
'Is not available'
24-
),
34+
);
35+
},
2536
enableSorting: false
2637
}),
2738
columnHelper.accessor('block.height', {

src/components/features/block-listing/blocks-table/hook.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import useApiClient from '@/api';
55
import { BLOCK_COLUMNS } from '@/components/common/table-columns/BLOCK_COLUMNS';
66
import { DATA_POOL_INTERVAL } from '@/constants/data-pool-interval';
77
import { QUERY_DEFAULT_LIMIT } from '@/constants/query-default-limit';
8-
import type { BlockSorts } from '@/constants/query-sorts';
9-
import { useOrderBy } from '@/hooks/useOrderBy';
8+
import { transformBlockOrderBy } from '@/constants/query-sorts';
109
import { useTableState } from '@/hooks/useTableState';
1110
import type { Block } from '@/schemas';
1211
import { transformSortLiteral } from '@/utils/transform-sort';
@@ -22,7 +21,10 @@ export const useBlocksTable = () => {
2221
paginationValue
2322
} = useTableState('timestamp:desc', QUERY_DEFAULT_LIMIT);
2423

25-
const orderByObject = useOrderBy<BlockSorts>(orderBy ?? 'timestamp:desc');
24+
const orderByObject = useMemo(
25+
() => transformBlockOrderBy(orderBy ?? 'timestamp:desc'),
26+
[orderBy]
27+
);
2628
const sortingValue = transformSortLiteral(orderBy);
2729

2830
const {

src/components/features/landing/block-tables/hook.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { useMemo } from 'react';
44
import useApiClient from '@/api';
55
import { BLOCK_COLUMNS } from '@/components/common/table-columns/BLOCK_COLUMNS';
66
import { DATA_POOL_INTERVAL } from '@/constants/data-pool-interval';
7-
import type { BlockSorts } from '@/constants/query-sorts';
8-
import { useOrderBy } from '@/hooks/useOrderBy';
7+
import { transformBlockOrderBy } from '@/constants/query-sorts';
98
import { useTableState } from '@/hooks/useTableState';
109
import type { Block } from '@/schemas';
1110
import { transformSortLiteral } from '@/utils/transform-sort';
@@ -21,7 +20,10 @@ export const useBlocksTable = () => {
2120
paginationValue
2221
} = useTableState('timestamp:desc');
2322

24-
const orderByObject = useOrderBy<BlockSorts>(orderBy ?? 'timestamp:desc');
23+
const orderByObject = useMemo(
24+
() => transformBlockOrderBy(orderBy ?? 'timestamp:desc'),
25+
[orderBy]
26+
);
2527
const sortingValue = transformSortLiteral(orderBy);
2628

2729
const {

src/components/features/transaction-details/transaction-information/TransactionInformation.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { notFound } from '@tanstack/react-router';
1+
import { notFound, useNavigate } from '@tanstack/react-router';
22
import { getCoreRowModel, useReactTable } from '@tanstack/react-table';
33
import * as React from 'react';
44

@@ -12,6 +12,7 @@ import { RESOURCES } from '@/constants/resources';
1212
import { cn } from '@/lib/utils';
1313
import type { ExtrinsicDetail, ExtrinsicTransfer } from '@/schemas';
1414
import { formatMonetaryValue, formatTimestamp } from '@/utils/formatter';
15+
import { isWormholeExtrinsic } from '@/utils/get-extrinsic-detail-path';
1516

1617
export interface TransactionInformationProps {
1718
hash: string;
@@ -21,16 +22,29 @@ export const TransactionInformation: React.FC<TransactionInformationProps> = ({
2122
hash
2223
}) => {
2324
const api = useApiClient();
25+
const navigate = useNavigate();
2426
const { data, loading } = api.transactions.getByHash().useQuery(hash);
2527

26-
if (!loading && (!data || data.extrinsics.length === 0)) throw notFound();
28+
const extrinsic = data?.extrinsics[0];
29+
30+
const isRedirectingToWormhole =
31+
!loading && !!extrinsic && isWormholeExtrinsic(extrinsic);
32+
33+
React.useEffect(() => {
34+
if (!isRedirectingToWormhole) return;
35+
36+
navigate({
37+
to: '/wormhole/$id',
38+
params: { id: hash },
39+
replace: true
40+
});
41+
}, [isRedirectingToWormhole, hash, navigate]);
2742

2843
const extrinsicTransactionColumns = React.useMemo(
2944
() => EXTRINSIC_TRANSACTION_COLUMNS,
3045
[]
3146
);
3247

33-
const extrinsic = data?.extrinsics[0];
3448
const transfers = data?.transfers ?? [];
3549
const table = useReactTable<ExtrinsicTransfer>({
3650
data: transfers,
@@ -40,6 +54,12 @@ export const TransactionInformation: React.FC<TransactionInformationProps> = ({
4054
manualPagination: true
4155
});
4256

57+
if (!loading && (!data || data.extrinsics.length === 0)) throw notFound();
58+
59+
if (isRedirectingToWormhole) {
60+
return null;
61+
}
62+
4363
const extrinsicInfo: Partial<ExtrinsicDetail>[] = [
4464
{
4565
id: extrinsic?.id,

0 commit comments

Comments
 (0)