diff --git a/src/components/DoAllocate/DoAllocate.tsx b/src/components/DoAllocate/DoAllocate.tsx index 593d1b8cc..63a136cde 100644 --- a/src/components/DoAllocate/DoAllocate.tsx +++ b/src/components/DoAllocate/DoAllocate.tsx @@ -31,9 +31,11 @@ interface IProps { deploymentId?: string; actionBtn?: React.ReactNode; onSuccess?: () => void; + initialStatus?: 'Add' | 'Remove'; + disabled?: boolean; } -const DoAllocate: FC = ({ projectId, deploymentId, actionBtn, onSuccess }) => { +const DoAllocate: FC = ({ projectId, deploymentId, actionBtn, onSuccess, initialStatus, disabled }) => { const { address: account } = useAccount(); const project = useProjectFromQuery(projectId ?? ''); const { data: deploymentMetadata } = useDeploymentMetadata(deploymentId); @@ -45,7 +47,7 @@ const DoAllocate: FC = ({ projectId, deploymentId, actionBtn, onSuccess const { contracts } = useWeb3Store(); const [open, setOpen] = useState(false); const [currentRewardsPerToken, setCurrentRewardsPerToken] = useState(BigNumber(0)); - const [addOrRemove, setAddOrRemove] = useState<'Add' | 'Remove'>('Add'); + const [addOrRemove, setAddOrRemove] = useState<'Add' | 'Remove'>(initialStatus || 'Add'); const runnerAllocation = useAsyncMemo(async () => { if (!account) @@ -63,6 +65,8 @@ const DoAllocate: FC = ({ projectId, deploymentId, actionBtn, onSuccess }; }, [account]); + console.warn(runnerAllocation.data?.total.toString(), runnerAllocation.data?.used.toString()); + const allocationRewardsRate = useAsyncMemo(async () => { const rewards = await contracts?.rewardsBooster.boosterQueryRewardRate( project.data?.type === ProjectType.RPC ? 1 : 0, @@ -103,6 +107,7 @@ const DoAllocate: FC = ({ projectId, deploymentId, actionBtn, onSuccess const avaibleStakeAmount = useMemo(() => { const leftAllocation = runnerAllocation.data?.left ? BigNumber(runnerAllocation.data?.left) : BigNumber(0); + return leftAllocation.toString(); }, [allocatedStake, runnerAllocation.data?.left]); @@ -170,7 +175,8 @@ const DoAllocate: FC = ({ projectId, deploymentId, actionBtn, onSuccess }; useEffect(() => { - if (open && account && deploymentId) { + if (open && account && deploymentId && !disabled) { + setAddOrRemove(initialStatus || 'Add'); getAllocatedStake({ variables: { id: `${deploymentId}:${account}`, @@ -180,14 +186,16 @@ const DoAllocate: FC = ({ projectId, deploymentId, actionBtn, onSuccess getAllocateRewardsPerBlock(); runnerAllocation.refetch(); } - }, [open, account, deploymentId]); + }, [open, account, deploymentId, disabled]); return (
{actionBtn ? (
{ - setOpen(true); + if (!disabled) { + setOpen(true); + } }} > {actionBtn} diff --git a/src/components/ProjectHeader/ProjectHeader.tsx b/src/components/ProjectHeader/ProjectHeader.tsx index ca81e8390..53bef99c6 100644 --- a/src/components/ProjectHeader/ProjectHeader.tsx +++ b/src/components/ProjectHeader/ProjectHeader.tsx @@ -3,7 +3,6 @@ import * as React from 'react'; import { useTranslation } from 'react-i18next'; -import DoAllocate from '@components/DoAllocate/DoAllocate'; import UnsafeWarn from '@components/UnsafeWarn'; import { Manifest } from '@hooks/useGetDeploymentManifest'; import { ProjectDetailsQuery } from '@hooks/useProjectFromQuery'; @@ -84,7 +83,6 @@ const ProjectHeader: React.FC = ({ {/* */} -
diff --git a/src/components/Status/Status.tsx b/src/components/Status/Status.tsx index a2efd069b..3013334a5 100644 --- a/src/components/Status/Status.tsx +++ b/src/components/Status/Status.tsx @@ -16,7 +16,7 @@ export const deploymentStatus: { [key: string]: StatusColor } = { INDEXING: StatusColor.blue, STARTED: StatusColor.blue, READY: StatusColor.green, - NOTINDEXING: StatusColor.red, + NOTINDEXING: StatusColor.gray, TERMINATED: StatusColor.red, }; diff --git a/src/hooks/useSortedIndexerDeployments.tsx b/src/hooks/useSortedIndexerDeployments.tsx index dc2cae39a..42e352fac 100644 --- a/src/hooks/useSortedIndexerDeployments.tsx +++ b/src/hooks/useSortedIndexerDeployments.tsx @@ -57,8 +57,17 @@ export function useSortedIndexerDeployments(indexer: string): AsyncData deployment?.status !== ServiceStatus.TERMINATED, ); + + // merge have allocation but not indexing project + const mergedDeployments = [ + ...filteredDeployments, + ...(allocatedProjects.data?.indexerAllocationSummaries?.nodes.filter( + (i) => !filteredDeployments.find((j) => j?.deploymentId === i?.deploymentId), + ) || []), + ]; + return await Promise.all( - filteredDeployments.map(async (indexerDeployment) => { + mergedDeployments.map(async (indexerDeployment) => { const metadata: ProjectMetadata = indexerDeployment?.deployment?.project ? await getMetadataFromCid(indexerDeployment.deployment.project.metadata) : { @@ -71,24 +80,29 @@ export function useSortedIndexerDeployments(indexer: string): AsyncData = ({ indexer, emptyList, desc }) => dataIndex: 'indexingProgress', render: (indexingProgress: number, deployment) => { // TODO: will use metric service replace it. hardcode for now. - const sortedStatus = getDeploymentStatus(deployment.status as ServiceStatus, false); + const sortedStatus = deployment.status ? getDeploymentStatus(deployment.status, false) : 'NOTINDEXING'; const { indexingErr } = deployment; if (indexingErr) @@ -121,9 +121,13 @@ export const OwnDeployments: React.FC = ({ indexer, emptyList, desc }) =>
- - Current blocks: #{deployment.lastHeight} - + {deployment.lastHeight ? ( + + Current blocks: #{deployment.lastHeight} + + ) : ( + '' + )} ); }, @@ -159,12 +163,32 @@ export const OwnDeployments: React.FC = ({ indexer, emptyList, desc }) => Update Allocation} + actionBtn={Add Allocation} + onSuccess={() => { + retry(() => { + indexerDeployments.refetch?.(); + }); + }} + initialStatus="Add" + > + + + Remove Allocation + + } onSuccess={() => { retry(() => { indexerDeployments.refetch?.(); }); }} + initialStatus="Remove" > );