diff --git a/app/src/component/fileDownloadButton/index.js b/app/src/component/fileDownloadButton/index.js
index fb7256de..c6e85634 100644
--- a/app/src/component/fileDownloadButton/index.js
+++ b/app/src/component/fileDownloadButton/index.js
@@ -17,7 +17,7 @@ const select = (state, props) => ({
});
const perform = dispatch => ({
- purchaseUri: uri => dispatch(doPurchaseUri(uri)),
+ purchaseUri: (uri, failureCallback) => dispatch(doPurchaseUri(uri, null, failureCallback)),
restartDownload: (uri, outpoint) => dispatch(doStartDownload(uri, outpoint)),
fetchCostInfo: uri => dispatch(doFetchCostInfoForUri(uri)),
});
diff --git a/app/src/component/fileDownloadButton/view.js b/app/src/component/fileDownloadButton/view.js
index 2f9fbe87..827f2f13 100644
--- a/app/src/component/fileDownloadButton/view.js
+++ b/app/src/component/fileDownloadButton/view.js
@@ -43,7 +43,8 @@ class FileDownloadButton extends React.PureComponent {
doPause,
style,
openFile,
- onButtonLayout
+ onButtonLayout,
+ onStartDownloadFailed
} = this.props;
if (loading || downloading) {
@@ -73,7 +74,7 @@ class FileDownloadButton extends React.PureComponent {
if (NativeModules.Mixpanel) {
NativeModules.Mixpanel.track('Purchase Uri', { Uri: uri });
}
- purchaseUri(uri);
+ purchaseUri(uri, onStartDownloadFailed);
if (isPlayable && onPlay) {
this.props.onPlay();
}
diff --git a/app/src/page/file/view.js b/app/src/page/file/view.js
index 98719824..2cd0d9db 100644
--- a/app/src/page/file/view.js
+++ b/app/src/page/file/view.js
@@ -397,7 +397,13 @@ class FilePage extends React.PureComponent {
this.startTime = Date.now();
this.setState({ downloadPressed: true, autoPlayMedia: true });
}}
- onButtonLayout={() => this.setState({ downloadButtonShown: true })} />}
+ onButtonLayout={() => this.setState({ downloadButtonShown: true })}
+ onStartDownloadFailed={() => {
+ this.startTime = null;
+ setTimeout(() => {
+ this.setState({ downloadPressed: false, fileViewLogged: false, mediaLoaded: false });
+ }, 500);
+ }} />}
{!fileInfo && }
{canLoadMedia && fileInfo && {
dispatch({
type: ACTIONS.LOADING_VIDEO_STARTED,
@@ -188,6 +188,10 @@ export function doLoadVideo(uri) {
message: `File timeout for uri ${uri}`,
displayType: ['toast']
}));
+
+ if (failureCallback) {
+ failureCallback();
+ }
} else {
dispatch(doDownloadFile(uri, streamInfo));
}
@@ -203,11 +207,15 @@ export function doLoadVideo(uri) {
message: `Failed to download ${uri}, please try again. If this problem persists, visit https://lbry.io/faq/support for support.`,
displayType: ['toast']
}));
+
+ if (failureCallback) {
+ failureCallback();
+ }
});
};
}
-export function doPurchaseUri(uri, specificCostInfo) {
+export function doPurchaseUri(uri, specificCostInfo, failureCallback) {
return (dispatch, getState) => {
const state = getState();
const balance = selectBalance(state);
@@ -226,11 +234,11 @@ export function doPurchaseUri(uri, specificCostInfo) {
`This will purchase "${title}" for ${formattedCost} ${unit}`,
[
{ text: 'OK', onPress: () => dispatch(doLoadVideo(uri)) },
- { text: 'Cancel', style: 'cancel' }
+ { text: 'Cancel', style: 'cancel', onPress: () => failureCallback && failureCallback() }
],
{ cancelable: true });
} else {
- dispatch(doLoadVideo(uri));
+ dispatch(doLoadVideo(uri, failureCallback));
}
}
@@ -260,6 +268,10 @@ export function doPurchaseUri(uri, specificCostInfo) {
message: 'Insufficient credits',
displayType: ['toast']
}));
+ if (failureCallback) {
+ failureCallback();
+ }
+
Promise.resolve();
return;
}