// @flow import React from 'react'; import Button from 'component/button'; import * as icons from 'constants/icons'; import ToolTip from 'component/common/tooltip'; import analytics from 'analytics'; import type { Claim } from 'types/claim'; type Props = { claim: Claim, uri: string, downloading: boolean, fileInfo: ?{ written_bytes: number, total_bytes: number, outpoint: number, download_path: string, completed: boolean, }, loading: boolean, costInfo: ?{}, restartDownload: (string, number) => void, openInShell: string => void, purchaseUri: string => void, pause: () => void, }; class FileDownloadLink extends React.PureComponent { componentWillUpdate() { const { downloading, fileInfo, uri, restartDownload } = this.props; if ( !downloading && fileInfo && !fileInfo.completed && fileInfo.written_bytes !== false && fileInfo.written_bytes < fileInfo.total_bytes ) { restartDownload(uri, fileInfo.outpoint); } } uri: ?string; render() { const { fileInfo, downloading, uri, openInShell, purchaseUri, costInfo, loading, pause, claim, } = this.props; const openFile = () => { if (fileInfo) { openInShell(fileInfo.download_path); pause(); } }; 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) { if (!costInfo) { return null; } return (