Skip to content

Commit 80aa415

Browse files
authored
chore(tangle-dapp): Registered blueprint chip & fix tangle-dapp blueprints page (#3022)
1 parent b59c148 commit 80aa415

File tree

14 files changed

+87
-33
lines changed

14 files changed

+87
-33
lines changed

apps/tangle-cloud/src/pages/blueprints/ConfigureBlueprintModal/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { z } from 'zod';
22

33
export const blueprintFormSchema = z.object({
4-
rpcUrl: z.string().url({ message: 'Please enter a valid URL' }).optional(),
4+
rpcUrl: z
5+
.string()
6+
.url({ message: 'Please enter a valid URL' })
7+
.or(z.literal(''))
8+
.optional(),
59
});
610

711
export type BlueprintFormSchema = z.infer<typeof blueprintFormSchema>;

apps/tangle-cloud/src/pages/blueprints/[id]/page.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import useBlueprintDetails from '@tangle-network/tangle-shared-ui/data/restake/u
66
import { ErrorFallback } from '@tangle-network/ui-components/components/ErrorFallback';
77
import SkeletonLoader from '@tangle-network/ui-components/components/SkeletonLoader';
88
import { Typography } from '@tangle-network/ui-components/typography/Typography';
9-
import { type FC, type PropsWithChildren, useState } from 'react';
9+
import { type FC, type PropsWithChildren, useMemo, useState } from 'react';
1010
import { Link, useNavigate, Navigate } from 'react-router-dom';
1111
import { PagePath, TangleDAppPagePath } from '../../../types';
1212
import ConfigureBlueprintModal from '../ConfigureBlueprintModal';
1313
import { Modal } from '@tangle-network/ui-components';
1414
import type { BlueprintFormResult } from '../ConfigureBlueprintModal/types';
1515

1616
import { SessionStorageKey } from '../../../constants';
17-
import useOperatorInfo from '../../../hooks/useOperatorInfo';
17+
import useOperatorInfo from '@tangle-network/tangle-shared-ui/hooks/useOperatorInfo';
1818
import useParamWithSchema from '@tangle-network/tangle-shared-ui/hooks/useParamWithSchema';
1919
import { z } from 'zod';
2020

@@ -36,9 +36,15 @@ const Page = () => {
3636
const navigate = useNavigate();
3737
const id = useParamWithSchema('id', z.coerce.bigint());
3838
const { result, isLoading, error } = useBlueprintDetails(id);
39-
const { isOperator } = useOperatorInfo();
39+
const { isOperator, operatorAddress } = useOperatorInfo();
4040
const [isBlueprintModalOpen, setIsBlueprintModalOpen] = useState(false);
4141

42+
const isRegistered = useMemo(() => {
43+
return result?.operators.some(
44+
(operator) => operator.address === operatorAddress,
45+
);
46+
}, [operatorAddress, result?.operators]);
47+
4248
if (isLoading) {
4349
return (
4450
<div className="space-y-5">
@@ -79,7 +85,7 @@ const Page = () => {
7985
<BlueprintHeader
8086
blueprint={result.details}
8187
enableDeploy
82-
enableRegister={isOperator}
88+
enableRegister={isOperator && !isRegistered}
8389
deployBtnProps={{
8490
onClick: (e) => {
8591
e.preventDefault();
@@ -89,6 +95,7 @@ const Page = () => {
8995
registerBtnProps={{
9096
onClick: () => setIsBlueprintModalOpen(true),
9197
}}
98+
isRegistered={isRegistered ?? false}
9299
/>
93100

94101
<div className="space-y-5">

apps/tangle-cloud/src/pages/blueprints/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { BlueprintFormResult } from './ConfigureBlueprintModal/types';
1919
import { useNavigate } from 'react-router';
2020
import { SessionStorageKey } from '../../constants';
2121
import { PagePath } from '../../types';
22-
import useOperatorInfo from '../../hooks/useOperatorInfo';
22+
import useOperatorInfo from '@tangle-network/tangle-shared-ui/hooks/useOperatorInfo';
2323

2424
const ROLE_TITLE = {
2525
[Role.OPERATOR]: 'Register Your First Blueprint',

apps/tangle-cloud/src/pages/instances/AccountStatsCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from '@tangle-network/tangle-shared-ui/utils/polkadot/identity';
1818
import { isValidUrl } from '@tangle-network/dapp-types';
1919
import useActiveAccountAddress from '@tangle-network/tangle-shared-ui/hooks/useActiveAccountAddress';
20-
import useOperatorInfo from '../../hooks/useOperatorInfo';
20+
import useOperatorInfo from '@tangle-network/tangle-shared-ui/hooks/useOperatorInfo';
2121
import { useOperatorStatsData } from '../../data/operators/useOperatorStatsData';
2222
import { useUserStatsData } from '../../data/operators/useUserStatsData';
2323

apps/tangle-cloud/src/pages/instances/BlueprintManagementSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { RegisteredBlueprintsTabs } from './RegisteredBlueprints';
22
import { InstancesTabs } from './Instances';
33
import { FC } from 'react';
4-
import useOperatorInfo from '../../hooks/useOperatorInfo';
4+
import useOperatorInfo from '@tangle-network/tangle-shared-ui/hooks/useOperatorInfo';
55

66
export const BlueprintManagementSection: FC = () => {
77
const { isOperator } = useOperatorInfo();

apps/tangle-cloud/src/pages/instances/Instances/PendingInstanceTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import useSubstrateAddress from '@tangle-network/tangle-shared-ui/hooks/useSubst
3838
import useIdentities from '@tangle-network/tangle-shared-ui/hooks/useIdentities';
3939
import useServicesRejectTx from '../../../data/services/useServicesRejectTx';
4040
import useServicesApproveTx from '../../../data/services/useServicesApproveTx';
41-
import useOperatorInfo from '../../../hooks/useOperatorInfo';
41+
import useOperatorInfo from '@tangle-network/tangle-shared-ui/hooks/useOperatorInfo';
4242

4343
const columnHelper = createColumnHelper<MonitoringServiceRequest>();
4444

apps/tangle-cloud/src/pages/instances/Instances/RunningInstanceTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import TableCellWrapper from '@tangle-network/tangle-shared-ui/components/tables
2323
import { Link } from 'react-router';
2424
import { PagePath } from '../../../types';
2525
import { MonitoringBlueprint } from '@tangle-network/tangle-shared-ui/data/blueprints/utils/type';
26-
import useOperatorInfo from '../../../hooks/useOperatorInfo';
26+
import useOperatorInfo from '@tangle-network/tangle-shared-ui/hooks/useOperatorInfo';
2727
import useMonitoringBlueprints from '@tangle-network/tangle-shared-ui/data/blueprints/useMonitoringBlueprints';
2828

2929
const columnHelper =

apps/tangle-cloud/src/pages/instances/RegisteredBlueprints/RegisteredBlueprints.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { Link } from 'react-router';
2121
import { PagePath } from '../../../types';
2222
import getTVLToDisplay from '@tangle-network/tangle-shared-ui/utils/getTVLToDisplay';
2323
import useRegisteredBlueprints from '@tangle-network/tangle-shared-ui/data/blueprints/useRegisteredBlueprints';
24-
import useOperatorInfo from '../../../hooks/useOperatorInfo';
24+
import useOperatorInfo from '@tangle-network/tangle-shared-ui/hooks/useOperatorInfo';
2525

2626
export type RegisteredBlueprintsTableProps = {
2727
blueprints: MonitoringBlueprint[];

apps/tangle-dapp/src/pages/blueprints/BlueprintListing.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ const BlueprintItemWrapper: FC<PropsWithChildren<{ id: bigint }>> = ({
1414
const BlueprintListing: FC = () => {
1515
const { blueprints, isLoading, error } = useAllBlueprints();
1616

17+
const blueprintsArray = Array.isArray(blueprints)
18+
? blueprints
19+
: Array.from(blueprints?.values() || []);
20+
1721
return (
1822
<BlueprintGallery
19-
blueprints={Object.values(blueprints).map((blueprint) => ({
23+
blueprints={blueprintsArray.map((blueprint) => ({
2024
...blueprint,
2125
renderImage(imageUrl) {
2226
return (

apps/tangle-dapp/src/pages/blueprints/[id]/index.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,24 @@ import useBlueprintDetails from '@tangle-network/tangle-shared-ui/data/restake/u
44
import { ErrorFallback } from '@tangle-network/ui-components/components/ErrorFallback';
55
import SkeletonLoader from '@tangle-network/ui-components/components/SkeletonLoader';
66
import { Typography } from '@tangle-network/ui-components/typography/Typography';
7-
import { FC } from 'react';
7+
import { FC, useMemo } from 'react';
88
import { Navigate } from 'react-router';
99
import { PagePath } from '../../../types';
1010
import useParamWithSchema from '@tangle-network/tangle-shared-ui/hooks/useParamWithSchema';
11+
import useOperatorInfo from '@tangle-network/tangle-shared-ui/hooks/useOperatorInfo';
1112
import { z } from 'zod';
1213

1314
const BlueprintDetailsPage: FC = () => {
15+
const { operatorAddress } = useOperatorInfo();
1416
const id = useParamWithSchema('id', z.coerce.bigint());
1517
const { result, isLoading, error } = useBlueprintDetails(id);
1618

19+
const isRegistered = useMemo(() => {
20+
return result?.operators.some(
21+
(operator) => operator.address === operatorAddress,
22+
);
23+
}, [operatorAddress, result?.operators]);
24+
1725
if (id === undefined) {
1826
return <Navigate to={PagePath.NOT_FOUND} />;
1927
} else if (isLoading || result === null) {
@@ -34,7 +42,10 @@ const BlueprintDetailsPage: FC = () => {
3442

3543
return (
3644
<div className="space-y-5">
37-
<BlueprintHeader blueprint={result.details} />
45+
<BlueprintHeader
46+
blueprint={result.details}
47+
isRegistered={isRegistered ?? false}
48+
/>
3849

3950
<div className="space-y-5">
4051
<Typography variant="h4" fw="bold">

0 commit comments

Comments
 (0)