11import { getIpfsGatewayDownloadLink , getIpfsGatewayRenderLink } from '@/utils/links.ts'
2- import { COMBINED_STEPS } from '../../constants/upload-status.tsx'
32import { INPI_ERROR_MESSAGE } from '../../hooks/use-filecoin-upload.ts'
3+ import { useStepStates } from '../../hooks/use-step-states.ts'
44import { useUploadProgress } from '../../hooks/use-upload-progress.ts'
5- import type { Progress } from '../../types/upload-progress .ts'
5+ import type { StepState } from '../../types/upload/step .ts'
66import { Alert } from '../ui/alert.tsx'
77import { Card } from '../ui/card.tsx'
88import { DownloadButton } from '../ui/download-button.tsx'
@@ -11,7 +11,7 @@ import { ProgressCard } from './progress-card.tsx'
1111import { ProgressCardCombined } from './progress-card-combined.tsx'
1212
1313interface CarUploadAndIpniCardProps {
14- progresses : Progress [ ]
14+ stepStates : StepState [ ]
1515 cid ?: string
1616 fileName : string
1717}
@@ -22,50 +22,45 @@ interface CarUploadAndIpniCardProps {
2222 * It will shrink to a single card if the uploading-car and announcing-cids steps are completed.
2323 * Otherwise, it will display the progress of the uploading-car and announcing-cids steps.
2424 */
25- export const CarUploadAndIpniCard = ( { progresses , cid, fileName } : CarUploadAndIpniCardProps ) => {
25+ export const CarUploadAndIpniCard = ( { stepStates , cid, fileName } : CarUploadAndIpniCardProps ) => {
2626 // Use the upload progress hook to calculate all progress-related values
27- const { getCombinedFirstStageProgress, getCombinedFirstStageStatus, hasIpniFailure } = useUploadProgress (
28- progresses ,
29- cid
30- )
31- const uploadingStep = progresses . find ( ( p ) => p . step === 'uploading-car' )
32- const announcingStep = progresses . find ( ( p ) => p . step === 'announcing-cids' )
27+ const { uploadOutcome } = useUploadProgress ( {
28+ stepStates,
29+ cid,
30+ } )
31+
32+ const { hasIpniAnnounceFailure } = uploadOutcome
33+
34+ const { announcingCidsStep, uploadingCarStep } = useStepStates ( stepStates )
3335
3436 const shouldShowCidCard =
35- uploadingStep ?. status === 'completed' &&
36- ( announcingStep ?. status === 'completed' || announcingStep ?. status === 'error' ) &&
37+ uploadingCarStep ?. status === 'completed' &&
38+ ( announcingCidsStep ?. status === 'completed' || announcingCidsStep ?. status === 'error' ) &&
3739 cid
3840
3941 if ( shouldShowCidCard ) {
4042 return (
4143 < Card . Wrapper >
42- { hasIpniFailure && < Alert message = { INPI_ERROR_MESSAGE } variant = "warning" /> }
44+ { hasIpniAnnounceFailure && < Alert message = { INPI_ERROR_MESSAGE } variant = "warning" /> }
4345 < Card . InfoRow
4446 subtitle = {
4547 < TextWithCopyToClipboard
4648 text = { cid }
47- { ...( ! hasIpniFailure && { href : getIpfsGatewayRenderLink ( cid , fileName ) } ) }
49+ { ...( ! hasIpniAnnounceFailure && { href : getIpfsGatewayRenderLink ( cid , fileName ) } ) }
4850 />
4951 }
5052 title = "IPFS Root CID"
5153 >
52- { ! hasIpniFailure && < DownloadButton href = { getIpfsGatewayDownloadLink ( cid , fileName ) } /> }
54+ { ! hasIpniAnnounceFailure && < DownloadButton href = { getIpfsGatewayDownloadLink ( cid , fileName ) } /> }
5355 </ Card . InfoRow >
5456 </ Card . Wrapper >
5557 )
5658 }
5759
58- // Filter progresses to only include the combined steps for ProgressCardCombined
59- const combinedProgresses = progresses . filter ( ( p ) => COMBINED_STEPS . includes ( p . step ) )
60-
6160 return (
6261 < >
63- < ProgressCardCombined
64- getCombinedFirstStageProgress = { getCombinedFirstStageProgress }
65- getCombinedFirstStageStatus = { getCombinedFirstStageStatus }
66- progresses = { combinedProgresses }
67- />
68- { announcingStep && < ProgressCard progress = { announcingStep } /> }
62+ < ProgressCardCombined stepStates = { stepStates } />
63+ { announcingCidsStep && < ProgressCard stepState = { announcingCidsStep } /> }
6964 </ >
7065 )
7166}
0 commit comments