// @flow import * as ICONS from 'constants/icons'; import * as MODALS from 'constants/modal_types'; import React from 'react'; import Button from 'component/button'; import ToolTip from 'component/common/tooltip'; import analytics from 'analytics'; type Props = { claim: StreamClaim, claimIsMine: boolean, uri: string, downloading: boolean, fileInfo: ?{ written_bytes: number, total_bytes: number, outpoint: number, download_path: string, completed: boolean, status: string, }, loading: boolean, costInfo: ?{}, restartDownload: (string, number) => void, openModal: (id: string, { path: string }) => void, purchaseUri: string => void, pause: () => void, }; class FileDownloadLink extends React.PureComponent { componentDidMount() { const { fileInfo, uri, restartDownload } = this.props; if ( fileInfo && !fileInfo.completed && fileInfo.status === 'running' && fileInfo.written_bytes !== false && fileInfo.written_bytes < fileInfo.total_bytes ) { // This calls file list to show the percentage restartDownload(uri, fileInfo.outpoint); } } uri: ?string; render() { const { fileInfo, downloading, uri, openModal, purchaseUri, costInfo, loading, pause, claim, claimIsMine, } = this.props; if (loading || downloading) { const progress = fileInfo && fileInfo.written_bytes ? (fileInfo.written_bytes / fileInfo.total_bytes) * 100 : 0; const label = fileInfo ? __('Downloading: ') + progress.toFixed(0) + __('% complete') : __('Connecting...'); return {label}; } else if ((fileInfo === null && !downloading) || (fileInfo && !fileInfo.download_path)) { if (!costInfo) { return null; } return (