Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support rpc #635

Merged
merged 5 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"@subql/contract-sdk": "0.112.0",
"@subql/network-clients": "^0.112.1-1",
"@subql/network-config": "^0.112.0",
"@subql/network-query": "0.112.0",
"@subql/react-hooks": "^0.112.1-1",
"@subql/network-query": "0.112.1-0",
"@subql/react-hooks": "^0.112.1-2",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
Expand Down
15 changes: 13 additions & 2 deletions src/components/DeploymentInfo/DeploymentInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import { useTranslation } from 'react-i18next';
import UnsafeWarn from '@components/UnsafeWarn';
import { useGetIfUnsafeDeployment } from '@hooks/useGetIfUnsafeDeployment';
import { Spinner, Typography } from '@subql/components';
import { ProjectType } from '@subql/contract-sdk/types';
import { Tooltip } from 'antd';

import { useProjectMetadata } from '../../containers';
import { useAsyncMemo } from '../../hooks';
import { useDeploymentMetadata } from '../../hooks/useDeploymentMetadata';
import { ProjectMetadata } from '../../models';
import { parseError, renderAsync } from '../../utils';
import { isUndefined, parseError, renderAsync } from '../../utils';
import Copy from '../Copy';
import IPFSImage from '../IPFSImage';
import styles from './DeploymentInfo.module.css';
Expand All @@ -21,9 +22,10 @@ type Props = {
project?: ProjectMetadata;
deploymentId?: string;
deploymentVersion?: string;
type?: ProjectType;
};

export const DeploymentInfo: React.FC<Props> = ({ project, deploymentId }) => {
export const DeploymentInfo: React.FC<Props> = ({ project, deploymentId, type }) => {
const { t } = useTranslation();

const deploymentMeta = useDeploymentMetadata(deploymentId);
Expand All @@ -46,6 +48,15 @@ export const DeploymentInfo: React.FC<Props> = ({ project, deploymentId }) => {
)}
{isUnsafe && <UnsafeWarn></UnsafeWarn>}
</div>
{isUndefined(type) ? (
''
) : (
<div>
<Typography variant="small" className={styles.text}>
Type: {type === ProjectType.RPC ? 'RPC Endpoint' : 'Data Indexer'}
</Typography>
</div>
)}
<div className={project?.name ? '' : styles.deployment}>
<Typography variant="small" className={styles.text}>
{versionHeader}
Expand Down
2 changes: 0 additions & 2 deletions src/components/IndexerDetails/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ const ConnectedRow: React.FC<{
setProjectMaxTargetHeightInfo(deploymentId, maxTargetHeight);
}

console.warn(meta);

return {
startBlock: meta?.startHeight ?? 0,
targetBlock: maxTargetHeight,
Expand Down
17 changes: 14 additions & 3 deletions src/components/ProjectCard/ProjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

import * as React from 'react';
import { Manifest } from '@hooks/useGetDeploymentManifest';
import { Address, Typography } from '@subql/components';
import { ProjectFieldsFragment } from '@subql/network-query';
import { ProjectFieldsFragment, ProjectType } from '@subql/network-query';
import dayjs from 'dayjs';

import { ProjectMetadata } from 'src/models';
Expand All @@ -12,7 +13,9 @@ import IPFSImage from '../IPFSImage';
import styles from './ProjectCard.module.css';

type Props = {
project: { metadata: ProjectMetadata | undefined } & Omit<ProjectFieldsFragment, 'metadata'>;
project: { metadata: ProjectMetadata | undefined } & Omit<ProjectFieldsFragment, 'metadata'> & {
manifest?: Manifest;
};
onClick?: () => void;
};

Expand Down Expand Up @@ -40,7 +43,15 @@ const ProjectCard: React.FC<Props> = ({ project, onClick }) => {
</Typography>
</div>

<Address address={project.owner} size="small" />
{project.type === ProjectType.SUBQUERY ? (
<Address address={project.owner} size="small" />
) : (
<Typography variant="small">
{project.manifest?.rpcFamily?.[0]}
{project.manifest?.rpcFamily?.[0] && project.manifest?.nodeType && ' - '}
{project.manifest?.nodeType}
</Typography>
)}

<div className={styles.line}></div>
<div className="flex" style={{ marginBottom: 12 }}>
Expand Down
1 change: 1 addition & 0 deletions src/components/ProjectHeader/ProjectHeader.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
justify-content: center;
flex-direction: column;
padding-left: 32px;
flex: 1;
}

.upper {
Expand Down
22 changes: 21 additions & 1 deletion src/components/ProjectHeader/ProjectHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import UnsafeWarn from '@components/UnsafeWarn';
import { Manifest } from '@hooks/useGetDeploymentManifest';
import { ProjectDetailsQuery } from '@hooks/useProjectFromQuery';
import { Address, Typography } from '@subql/components';
import { ProjectType } from '@subql/network-query';
import { Button } from 'antd';
import dayjs from 'dayjs';

Expand All @@ -20,9 +22,17 @@ type Props = {
currentVersion?: string;
onChangeVersion?: (key: string) => void;
isUnsafeDeployment?: boolean;
manifest?: Manifest;
};

const ProjectHeader: React.FC<Props> = ({ project, versions, currentVersion, isUnsafeDeployment, onChangeVersion }) => {
const ProjectHeader: React.FC<Props> = ({
project,
versions,
currentVersion,
isUnsafeDeployment,
onChangeVersion,
manifest,
}) => {
const { t } = useTranslation();

const createdAtStr = React.useMemo(() => dayjs(project.createdTimestamp).fromNow(), [project]);
Expand Down Expand Up @@ -60,6 +70,10 @@ const ProjectHeader: React.FC<Props> = ({ project, versions, currentVersion, isU
</Typography>
{isUnsafeDeployment && <UnsafeWarn></UnsafeWarn>}
<VersionDropdown />
<span style={{ flex: 1 }}></span>
<Button type="primary" shape="round" size="large">
Get RPC Endpoint
</Button>
</div>
<Address address={project.owner} size="small" />

Expand All @@ -75,6 +89,12 @@ const ProjectHeader: React.FC<Props> = ({ project, versions, currentVersion, isU
</div>
</div>
<div className={styles.lower}>
{project.type === ProjectType.RPC && manifest?.rpcFamily ? (
<Detail label="Network" value={manifest?.rpcFamily[0]}></Detail>
) : (
''
)}
<Detail label="Type" value={project.type === ProjectType.RPC ? 'RPC Endpoint' : 'Data Indexer'}></Detail>
{currentVersion && <Detail label={t('projectHeader.deploymentId')} value={currentVersion} canCopy={true} />}
<Detail label={t('projectOverview.updatedAt')} value={updatedAtStr} className={styles.column} />
<Detail label={t('projectOverview.createdAt')} value={createdAtStr} className={styles.column} />
Expand Down
5 changes: 5 additions & 0 deletions src/components/ProjectOverview/ProjectOverview.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
}
}

.line {
display: flex;
gap: 8px;
}

.left {
display: flex;
flex-direction: row;
Expand Down
50 changes: 48 additions & 2 deletions src/components/ProjectOverview/ProjectOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { BsGithub, BsGlobe } from 'react-icons/bs';
import Expand from '@components/Expand/Expand';
import NewCard from '@components/NewCard';
import { useRouteQuery } from '@hooks';
import { Manifest } from '@hooks/useGetDeploymentManifest';
import { ProjectDetailsQuery } from '@hooks/useProjectFromQuery';
import { BalanceLayout } from '@pages/dashboard';
import { Markdown, Typography } from '@subql/components';
import { ProjectType } from '@subql/network-query';
import { formatSQT, useGetOfferCountByDeploymentIdLazyQuery } from '@subql/react-hooks';

import { ProjectMetadata } from '../../models';
Expand All @@ -19,6 +21,7 @@ type Props = {
project: ProjectDetailsQuery;
metadata: ProjectMetadata;
deploymentDescription?: string;
manifest?: Manifest;
};

export const ExternalLink: React.FC<{ link?: string; icon: 'globe' | 'github' }> = ({ link, icon }) => {
Expand All @@ -34,7 +37,7 @@ export const ExternalLink: React.FC<{ link?: string; icon: 'globe' | 'github' }>
);
};

const ProjectOverview: React.FC<Props> = ({ project, metadata, deploymentDescription }) => {
const ProjectOverview: React.FC<Props> = ({ project, metadata, deploymentDescription, manifest }) => {
const { t } = useTranslation();
const query = useRouteQuery();

Expand Down Expand Up @@ -82,6 +85,49 @@ const ProjectOverview: React.FC<Props> = ({ project, metadata, deploymentDescrip
</Expand>
</div>
</div>

{project.type === ProjectType.RPC && (
<>
<div style={{ height: 1, width: '100%', background: 'var(--sq-gray300)', marginBottom: 16 }}></div>
<div className={styles.column} style={{ gap: 8 }}>
<Typography variant="medium" weight={600}>
RPC Endpoint Details
</Typography>
{manifest?.chain?.chainId && (
<div className={styles.line}>
<Typography variant="medium" type="secondary">
Chain ID:{' '}
</Typography>
<Typography variant="medium">{manifest?.chain?.chainId}</Typography>
</div>
)}
{manifest?.rpcFamily && (
<div className={styles.line}>
<Typography variant="medium" type="secondary">
Family:{' '}
</Typography>
<Typography variant="medium">{manifest?.rpcFamily?.join(' ')}</Typography>
</div>
)}
{manifest?.client?.name && (
<div className={styles.line}>
<Typography variant="medium" type="secondary">
Client:{' '}
</Typography>
<Typography variant="medium">{manifest?.client?.name}</Typography>
</div>
)}
{manifest?.nodeType && (
<div className={styles.line}>
<Typography variant="medium" type="secondary">
Node type:{' '}
</Typography>
<Typography variant="medium">{manifest?.nodeType}</Typography>
</div>
)}
</div>
</>
)}
</div>

<div style={{ marginLeft: 48, width: '100%' }}>
Expand All @@ -95,7 +141,7 @@ const ProjectOverview: React.FC<Props> = ({ project, metadata, deploymentDescrip
<div className="col-flex">
<div className="flex" style={{ justifyContent: 'space-between' }}>
<Typography variant="small" type="secondary">
Total Indexers
Total {project.type === ProjectType.RPC ? 'RPC Providers' : 'Indexers'}
</Typography>
<Typography variant="small">
{project.deployments.nodes.find((i) => i?.id === deploymentId)?.indexers.totalCount || 0}
Expand Down
51 changes: 51 additions & 0 deletions src/hooks/useGetDeploymentManifest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2020-2022 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { useEffect, useState } from 'react';
import { useIPFS } from '@containers';
import yaml from 'js-yaml';

export type Manifest = {
nodeType?: string;
network?: string;
rpcFamily?: string[];
client?: {
name: string;
};
chain?: {
chainId: string;
};
};

export const useGetDeploymentManifest = (currentDeploymentId?: string) => {
const { catSingle } = useIPFS();

const [manifest, setManifest] = useState<Manifest>();

const getManifest = async (deploymentId: string) => {
try {
const res = await catSingle(deploymentId);

const result = Buffer.from(res).toString('utf8');

return yaml.load(result) as Manifest;
} catch (e) {
return {};
}
};

useEffect(() => {
const inner = async () => {
if (currentDeploymentId) {
const result = await getManifest(currentDeploymentId);
setManifest(result);
}
};
inner();
}, [currentDeploymentId]);

return {
getManifest,
manifest,
};
};
Loading
Loading