auto claim download rewards on file watch

This commit is contained in:
Sean Yesmunt 2019-08-15 10:26:20 -04:00
parent 90c219ff38
commit f99869a3dc
4 changed files with 16 additions and 4 deletions

View file

@ -1,5 +1,10 @@
import { connect } from 'react-redux';
import { makeSelectFileInfoForUri, makeSelectDownloadingForUri, makeSelectClaimIsMine } from 'lbry-redux';
import {
makeSelectFileInfoForUri,
makeSelectDownloadingForUri,
makeSelectLoadingForUri,
makeSelectClaimIsMine,
} from 'lbry-redux';
import { doOpenModal } from 'redux/actions/app';
import { doSetPlayingUri, doPlayUri } from 'redux/actions/content';
import FileDownloadLink from './view';
@ -7,6 +12,7 @@ import FileDownloadLink from './view';
const select = (state, props) => ({
fileInfo: makeSelectFileInfoForUri(props.uri)(state),
downloading: makeSelectDownloadingForUri(props.uri)(state),
loading: makeSelectLoadingForUri(props.uri)(state),
claimIsMine: makeSelectClaimIsMine(props.uri)(state),
});

View file

@ -9,6 +9,7 @@ type Props = {
uri: string,
claimIsMine: boolean,
downloading: boolean,
loading: boolean,
isStreamable: boolean,
fileInfo: ?FileListItem,
openModal: (id: string, { path: string }) => void,
@ -17,9 +18,9 @@ type Props = {
};
function FileDownloadLink(props: Props) {
const { fileInfo, downloading, openModal, pause, claimIsMine, download, uri } = props;
const { fileInfo, downloading, loading, openModal, pause, claimIsMine, download, uri } = props;
if (downloading) {
if (downloading || loading) {
const progress = fileInfo && fileInfo.written_bytes > 0 ? (fileInfo.written_bytes / fileInfo.total_bytes) * 100 : 0;
const label =
fileInfo && fileInfo.written_bytes > 0 ? progress.toFixed(0) + __('% downloaded') : __('Connecting...');

View file

@ -8,6 +8,7 @@ import {
makeSelectUriIsStreamable,
makeSelectTitleForUri,
} from 'lbry-redux';
import { doClaimEligiblePurchaseRewards } from 'lbryinc';
import { makeSelectIsPlaying, makeSelectShouldObscurePreview, selectPlayingUri } from 'redux/selectors/content';
import { makeSelectClientSetting } from 'redux/selectors/settings';
import { doSetPlayingUri } from 'redux/actions/content';
@ -34,6 +35,7 @@ const select = (state, props) => {
const perform = dispatch => ({
clearPlayingUri: () => dispatch(doSetPlayingUri(null)),
triggerAnalyticsView: (uri, timeToStart) => dispatch(doAnalyticsView(uri, timeToStart)),
claimRewards: () => dispatch(doClaimEligiblePurchaseRewards()),
});
export default withRouter(

View file

@ -29,6 +29,7 @@ type Props = {
floatingPlayerEnabled: boolean,
clearPlayingUri: () => void,
triggerAnalyticsView: (string, number) => void,
claimRewards: () => void,
};
export default function FileViewer(props: Props) {
@ -43,6 +44,7 @@ export default function FileViewer(props: Props) {
clearPlayingUri,
floatingPlayerEnabled,
triggerAnalyticsView,
claimRewards,
} = props;
const [playTime, setPlayTime] = useState();
const [fileViewerRect, setFileViewerRect] = usePersistedState('inline-file-viewer:rect');
@ -73,9 +75,10 @@ export default function FileViewer(props: Props) {
if (playTime && isReadyToPlay && wasntReadyButNowItIs) {
const timeToStart = Date.now() - playTime;
triggerAnalyticsView(uri, timeToStart);
claimRewards();
setPlayTime(null);
}
}, [setPlayTime, triggerAnalyticsView, isReadyToPlay, wasntReadyButNowItIs, playTime, uri]);
}, [setPlayTime, triggerAnalyticsView, isReadyToPlay, wasntReadyButNowItIs, playTime, uri, claimRewards]);
useEffect(() => {
function handleResize() {