Skip to content

Commit 4c814f3

Browse files
committed
feat: enhance SmartLinkGroup to conditionally display address or ID and label; update access details functions to include app, dataset, and workerpool information
1 parent 862ea0b commit 4c814f3

File tree

5 files changed

+55
-25
lines changed

5 files changed

+55
-25
lines changed

src/components/SmartLinkGroup.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ interface SmartLinkGroupProps {
3030
addressOrId: string;
3131
label?: string;
3232
isCurrentPage?: boolean;
33+
showAddressOrIdAndLabel?: boolean;
3334
}
3435

3536
export default function SmartLinkGroup({
3637
type,
3738
addressOrId,
3839
label,
3940
isCurrentPage = false,
41+
showAddressOrIdAndLabel = false,
4042
}: SmartLinkGroupProps) {
4143
const { chainId, isConnected } = useUserStore();
4244
const basePath = {
@@ -80,12 +82,15 @@ export default function SmartLinkGroup({
8082
<Link
8183
to={`/${getChainFromId(chainId)?.slug}/${basePath[type]}/${addressOrId}`}
8284
>
83-
<span className="hidden md:inline">{label ?? addressOrId}</span>
85+
<span className="hidden md:inline">
86+
{label && !showAddressOrIdAndLabel ? label : addressOrId}
87+
</span>
8488
<span className="inline md:hidden">
8589
{(label
8690
? truncateAddress(label)
8791
: truncateAddress(addressOrId)) ?? addressOrId}
8892
</span>
93+
{showAddressOrIdAndLabel ? `(${label})` : ''}
8994
{ens ? `(${ens})` : ''}
9095
</Link>
9196
</Button>

src/modules/access/access/buildAccessDetails.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import { App } from 'iexec/IExecAppModule';
2+
import { Dataset } from 'iexec/IExecDatasetModule';
13
import {
24
PublishedApporder,
35
PublishedDatasetorder,
46
PublishedWorkerpoolorder,
57
} from 'iexec/IExecOrderbookModule';
8+
import { Workerpool } from 'iexec/IExecWorkerpoolModule';
69
import SmartLinkGroup from '@/components/SmartLinkGroup';
710
import {
811
formatDateCompact,
@@ -12,8 +15,14 @@ import { nrlcToRlc } from '@/utils/nrlcToRlc';
1215

1316
export function buildAccessDetails({
1417
access,
18+
dataset,
19+
app,
20+
workerpool,
1521
}: {
1622
access: PublishedApporder | PublishedDatasetorder | PublishedWorkerpoolorder;
23+
dataset?: Dataset;
24+
app?: App;
25+
workerpool?: Workerpool;
1726
}) {
1827
if (!access) return {};
1928

@@ -36,7 +45,8 @@ export function buildAccessDetails({
3645
<SmartLinkGroup
3746
type="dataset"
3847
addressOrId={order.dataset.toLowerCase()}
39-
label={order.dataset.toLowerCase()}
48+
label={dataset?.datasetName}
49+
showAddressOrIdAndLabel={true}
4050
/>
4151
),
4252
}),
@@ -50,7 +60,8 @@ export function buildAccessDetails({
5060
<SmartLinkGroup
5161
type="app"
5262
addressOrId={order.app.toLowerCase()}
53-
label={order.app.toLowerCase()}
63+
label={app?.appName}
64+
showAddressOrIdAndLabel={true}
5465
/>
5566
),
5667
}),
@@ -64,7 +75,8 @@ export function buildAccessDetails({
6475
<SmartLinkGroup
6576
type="workerpool"
6677
addressOrId={order.workerpool.toLowerCase()}
67-
label={order.workerpool.toLowerCase()}
78+
label={workerpool?.workerpoolDescription}
79+
showAddressOrIdAndLabel={true}
6880
/>
6981
),
7082
}),

src/routes/$chainSlug/_layout/access/app/$accessHash.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ function useAccessData(accessHash: string, chainId: number) {
3030
queryFn: async () => {
3131
const iexec = await getIExec();
3232
const access = await iexec.orderbook.fetchApporder(accessHash);
33-
return { access };
33+
const { app } = await iexec.app.showApp(access.order.app);
34+
return { access, app };
3435
},
3536
placeholderData: createPlaceholderDataFnForQueryKey(queryKey),
3637
});
3738

3839
return {
39-
data: data?.access,
40-
accessType: 'App' as const,
40+
access: data?.access,
41+
app: data?.app,
4142
isLoading,
4243
isRefetching,
4344
isError,
@@ -51,8 +52,8 @@ function AppAccessRoute() {
5152
const { chainId } = useUserStore();
5253
const { accessHash } = Route.useParams();
5354
const {
54-
data: access,
55-
accessType,
55+
access,
56+
app,
5657
isLoading,
5758
isRefetching,
5859
isError,
@@ -61,7 +62,9 @@ function AppAccessRoute() {
6162
error,
6263
} = useAccessData((accessHash as string).toLowerCase(), chainId!);
6364

64-
const accessDetails = access ? buildAccessDetails({ access }) : undefined;
65+
const accessDetails = access
66+
? buildAccessDetails({ access, app })
67+
: undefined;
6568

6669
if (!isValid) {
6770
return <ErrorAlert className="my-16" message="Invalid access address." />;
@@ -78,7 +81,7 @@ function AppAccessRoute() {
7881
<div className="space-y-2">
7982
<h1 className="flex items-center gap-2 font-sans text-2xl font-extrabold">
8083
<AccessIcon size={24} />
81-
{accessType} access details
84+
App access details
8285
{!access && isError && (
8386
<span className="text-muted-foreground text-sm font-light">
8487
(outdated)

src/routes/$chainSlug/_layout/access/dataset/$accessHash.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ function useAccessData(accessHash: string, chainId: number) {
3030
queryFn: async () => {
3131
const iexec = await getIExec();
3232
const access = await iexec.orderbook.fetchDatasetorder(accessHash);
33-
return { access };
33+
const { dataset } = await iexec.dataset.showDataset(
34+
access.order.dataset
35+
);
36+
return { access, dataset };
3437
},
3538
placeholderData: createPlaceholderDataFnForQueryKey(queryKey),
3639
});
3740

3841
return {
39-
data: data?.access,
40-
accessType: 'Dataset' as const,
42+
access: data?.access,
43+
dataset: data?.dataset,
4144
isLoading,
4245
isRefetching,
4346
isError,
@@ -51,8 +54,8 @@ function DatasetAccessRoute() {
5154
const { chainId } = useUserStore();
5255
const { accessHash } = Route.useParams();
5356
const {
54-
data: access,
55-
accessType,
57+
access,
58+
dataset,
5659
isLoading,
5760
isRefetching,
5861
isError,
@@ -61,7 +64,9 @@ function DatasetAccessRoute() {
6164
error,
6265
} = useAccessData((accessHash as string).toLowerCase(), chainId!);
6366

64-
const accessDetails = access ? buildAccessDetails({ access }) : undefined;
67+
const accessDetails = access
68+
? buildAccessDetails({ access, dataset })
69+
: undefined;
6570

6671
if (!isValid) {
6772
return <ErrorAlert className="my-16" message="Invalid access address." />;
@@ -78,7 +83,7 @@ function DatasetAccessRoute() {
7883
<div className="space-y-2">
7984
<h1 className="flex items-center gap-2 font-sans text-2xl font-extrabold">
8085
<AccessIcon size={24} />
81-
{accessType} access details
86+
Dataset access details
8287
{!access && isError && (
8388
<span className="text-muted-foreground text-sm font-light">
8489
(outdated)

src/routes/$chainSlug/_layout/access/workerpool/$accessHash.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ function useAccessData(accessHash: string, chainId: number) {
3030
queryFn: async () => {
3131
const iexec = await getIExec();
3232
const access = await iexec.orderbook.fetchWorkerpoolorder(accessHash);
33-
return { access };
33+
const { workerpool } = await iexec.workerpool.showWorkerpool(
34+
access.order.workerpool
35+
);
36+
return { access, workerpool };
3437
},
3538
placeholderData: createPlaceholderDataFnForQueryKey(queryKey),
3639
});
3740

3841
return {
39-
data: data?.access,
40-
accessType: 'Workerpool' as const,
42+
access: data?.access,
43+
workerpool: data?.workerpool,
4144
isLoading,
4245
isRefetching,
4346
isError,
@@ -51,8 +54,8 @@ function WorkerpoolAccessRoute() {
5154
const { chainId } = useUserStore();
5255
const { accessHash } = Route.useParams();
5356
const {
54-
data: access,
55-
accessType,
57+
access,
58+
workerpool,
5659
isLoading,
5760
isRefetching,
5861
isError,
@@ -61,7 +64,9 @@ function WorkerpoolAccessRoute() {
6164
error,
6265
} = useAccessData((accessHash as string).toLowerCase(), chainId!);
6366

64-
const accessDetails = access ? buildAccessDetails({ access }) : undefined;
67+
const accessDetails = access
68+
? buildAccessDetails({ access, workerpool })
69+
: undefined;
6570

6671
if (!isValid) {
6772
return <ErrorAlert className="my-16" message="Invalid access address." />;
@@ -78,7 +83,7 @@ function WorkerpoolAccessRoute() {
7883
<div className="space-y-2">
7984
<h1 className="flex items-center gap-2 font-sans text-2xl font-extrabold">
8085
<AccessIcon size={24} />
81-
{accessType} access details
86+
Workerpool access details
8287
{!access && isError && (
8388
<span className="text-muted-foreground text-sm font-light">
8489
(outdated)

0 commit comments

Comments
 (0)