Skip to content

Commit 1e76e84

Browse files
feat: enhance address and id validation, fix status color, save tabs in URL (#43)
* feat: enhance address and id validation and refactor related functions * style: update color variables for danger, warning, and info states to improve accessibility and visual consistency * fix: StatusCell in buildTaskDetails was not showing the good color * feat: add useTabParam hook for managing tab state and navigation in AddressRoute * feat: integrate useTabParam for tab state management in account and deal routes * style: update color classes in StatusCell for improved visual consistency * refactor: simplify search parameter handling in useTabParam for improved readability * style: reduce padding in SearcherBar across multiple layout components for improved consistency * chore: add .nvmrc file to specify Node.js version 22 * fix: update address validation logic in SmartLinkGroup to use isValidAddress utility * fix: comment for isValidId function Co-authored-by: Copilot <[email protected]> * fix: remove unused import of ADDRESS_LENGTH in SmartLinkGroup component * fix: update address validation logic in SearcherBar to use isValidAddress and isValidId utilities * refactor: remove unused SUPPORTED_CHAINS import and clean up disabled tab logic in account layout * refactor: remove constants for address and ID lengths from config and update validation functions to use hardcoded values * refactor: rename taskAddress to taskId in route definitions and related components for consistency * refactor: rename dealAddress to dealId in route definitions, queries, and components for consistency * refactor: rename transactionAddress to transactionHash in queries and route definitions for consistency * refactor: update isValidId and isValidAddress functions to use regex for validation and improve comments --------- Co-authored-by: Copilot <[email protected]>
1 parent 4a5155e commit 1e76e84

File tree

32 files changed

+242
-272
lines changed

32 files changed

+242
-272
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22

src/components/SmartLinkGroup.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import CopyButton from '@/components/CopyButton';
55
import { Button } from '@/components/ui/button';
66
import { getIExec, getReadonlyIExec } from '@/externals/iexecSdkClient';
77
import useUserStore from '@/stores/useUser.store';
8+
import { isValidAddress } from '@/utils/addressOrIdCheck';
89
import { getBlockExplorerUrl, getChainFromId } from '@/utils/chain.utils';
910
import { truncateAddress } from '@/utils/truncateAddress';
1011
import {
@@ -57,7 +58,7 @@ export default function SmartLinkGroup({
5758
}
5859
return resolved;
5960
},
60-
enabled: !!chainId && !!addressOrId && addressOrId.length === 42,
61+
enabled: !!chainId && isValidAddress(addressOrId),
6162
staleTime: Infinity,
6263
});
6364

src/hooks/usePageParam.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,34 @@ export function usePageParam(paramName: string, defaultValue = 1) {
2121

2222
return [page, setPage] as const;
2323
}
24+
25+
export function useTabParam(
26+
paramName: string,
27+
tabLabels: string[],
28+
defaultIndex = 0
29+
) {
30+
const search = useSearch({ strict: false });
31+
const navigate = useNavigate();
32+
33+
const labelFromUrl = search?.[paramName];
34+
const tabIndex = labelFromUrl
35+
? tabLabels.indexOf(labelFromUrl)
36+
: defaultIndex;
37+
const currentTab = tabIndex >= 0 ? tabIndex : defaultIndex;
38+
39+
const setTab = (newTabIndex: number) => {
40+
const newLabel = tabLabels[newTabIndex];
41+
if (newLabel && newTabIndex !== currentTab) {
42+
navigate({
43+
search: (prev) => ({
44+
...prev,
45+
[paramName]: newLabel,
46+
}),
47+
replace: true,
48+
resetScroll: false,
49+
});
50+
}
51+
};
52+
53+
return [currentTab, setTab] as const;
54+
}

src/index.css

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,17 @@
175175
--color-success-foreground: var(--color-green-600);
176176
--color-success-border: var(--color-green-600);
177177

178-
--color-danger: var(--color-red-900);
179-
--color-danger-foreground: var(--color-red-100);
180-
--color-danger-border: var(--color-red-500);
178+
--color-danger: var(--color-red-100);
179+
--color-danger-foreground: var(--color-red-300);
180+
--color-danger-border: var(--color-red-300);
181181

182182
--color-warning: var(--color-orange-100);
183-
--color-warning-foreground: var(--color-orange-600);
184-
--color-warning-border: var(--color-orange-500);
183+
--color-warning-foreground: var(--color-orange-300);
184+
--color-warning-border: var(--color-orange-300);
185185

186186
--color-info: var(--color-blue-100);
187-
--color-info-foreground: var(--color-blue-600);
188-
--color-info-border: var(--color-blue-600);
187+
--color-info-foreground: var(--color-blue-300);
188+
--color-info-border: var(--color-blue-300);
189189

190190
--color-sidebar-foreground: var(--sidebar-foreground);
191191
--color-sidebar-primary: var(--sidebar-primary);

src/modules/addresses/address/workers/beneficiaryDeals/columns.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ export const columns: ColumnDef<AddressContribution>[] = [
1414
accessorKey: 'taskid',
1515
header: 'Task',
1616
cell: ({ row }) => {
17-
const taskAddress = row.original.task.taskid;
17+
const taskId = row.original.task.taskid;
1818
return (
1919
<CopyButton
20-
displayText={truncateAddress(taskAddress, {
20+
displayText={truncateAddress(taskId, {
2121
startLen: 8,
2222
})}
23-
textToCopy={taskAddress}
23+
textToCopy={taskId}
2424
/>
2525
);
2626
},

src/modules/deals/deal/DealTasksTable.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ import useUserStore from '@/stores/useUser.store';
88
import { createPlaceholderDataFnForQueryKey } from '@/utils/createPlaceholderDataFnForQueryKey';
99
import { dealTasksQuery } from './dealTasksQuery';
1010

11-
function useDealTasksData({ dealAddress }: { dealAddress: string }) {
11+
function useDealTasksData({ dealId }: { dealId: string }) {
1212
const { chainId } = useUserStore();
1313

14-
const queryKey = [chainId, 'deal', 'tasks', dealAddress];
14+
const queryKey = [chainId, 'deal', 'tasks', dealId];
1515
const { data, isLoading, isRefetching, isError, errorUpdateCount } = useQuery(
1616
{
1717
queryKey,
1818
queryFn: () =>
1919
execute(dealTasksQuery, chainId, {
2020
length: DETAIL_TABLE_LENGTH,
21-
dealAddress,
21+
dealId,
2222
}),
2323
refetchInterval: TABLE_REFETCH_INTERVAL,
2424
placeholderData: createPlaceholderDataFnForQueryKey(queryKey),
@@ -40,8 +40,8 @@ function useDealTasksData({ dealAddress }: { dealAddress: string }) {
4040
};
4141
}
4242

43-
export function DealTasksTable({ dealAddress }: { dealAddress: string }) {
44-
const { data: tasks, hasPastError } = useDealTasksData({ dealAddress });
43+
export function DealTasksTable({ dealId }: { dealId: string }) {
44+
const { data: tasks, hasPastError } = useDealTasksData({ dealId });
4545

4646
// TODO: handle loading state
4747

src/modules/deals/deal/dealQuery.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { graphql } from '@/graphql/gql';
22

33
export const dealQuery = graphql(`
4-
query Deal($dealAddress: ID!) {
5-
deal(id: $dealAddress) {
4+
query Deal($dealId: ID!) {
5+
deal(id: $dealId) {
66
dealid: id
77
timestamp
88
startTime

src/modules/deals/deal/dealTasksQuery.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { graphql } from '@/graphql/gql';
22

33
export const dealTasksQuery = graphql(`
4-
query DealTasks($dealAddress: ID!) {
5-
deal(id: $dealAddress) {
4+
query DealTasks($dealId: ID!) {
5+
deal(id: $dealId) {
66
tasks(orderBy: index, orderDirection: asc) {
77
taskid: id
88
index

src/modules/deals/dealsTable/columns.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ export const columns: ColumnDef<Deal>[] = [
1919
accessorKey: 'dealid',
2020
header: 'Deal',
2121
cell: ({ row }) => {
22-
const dealAddress = row.original.dealid;
22+
const dealId = row.original.dealid;
2323
return (
2424
<CopyButton
25-
displayText={truncateAddress(dealAddress, {
25+
displayText={truncateAddress(dealId, {
2626
startLen: 8,
2727
})}
28-
textToCopy={dealAddress}
28+
textToCopy={dealId}
2929
/>
3030
);
3131
},

src/modules/search/SearcherBar.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Button } from '@/components/ui/button';
99
import { Input } from '@/components/ui/input';
1010
import { getIExec, getReadonlyIExec } from '@/externals/iexecSdkClient';
1111
import useUserStore from '@/stores/useUser.store';
12+
import { isValidAddress, isValidId } from '@/utils/addressOrIdCheck';
1213
import { getChainFromId, getChainFromSlug } from '@/utils/chain.utils';
1314
import { searchQuery } from './searchQuery';
1415

@@ -59,9 +60,7 @@ export function SearcherBar({
5960
mutationKey: ['search', inputValue],
6061
mutationFn: async (value: string) => {
6162
const isValid =
62-
value.length === 42 || // address
63-
value.length === 66 || // tx, deal, task hash
64-
value.endsWith('.eth'); // ENS
63+
isValidAddress(value) || isValidId(value) || value.endsWith('.eth'); // ENS
6564

6665
if (!isValid) {
6766
throw new Error('Invalid value');

0 commit comments

Comments
 (0)