2017-06-06 23:19:12 +02:00
|
|
|
import * as types from "constants/action_types";
|
2017-09-08 07:03:37 +02:00
|
|
|
import * as settings from "constants/settings";
|
2017-06-06 23:19:12 +02:00
|
|
|
import lbry from "lbry";
|
|
|
|
import lbryio from "lbryio";
|
|
|
|
import lbryuri from "lbryuri";
|
2017-11-13 22:02:23 +01:00
|
|
|
import { makeSelectClientSetting } from "redux/selectors/settings";
|
|
|
|
import { selectBalance, selectTransactionItems } from "redux/selectors/wallet";
|
2017-04-28 17:14:44 +02:00
|
|
|
import {
|
2017-09-08 05:15:05 +02:00
|
|
|
makeSelectFileInfoForUri,
|
2017-07-21 10:02:29 +02:00
|
|
|
selectDownloadingByOutpoint,
|
2017-11-13 22:02:23 +01:00
|
|
|
} from "redux/selectors/file_info";
|
|
|
|
import { selectResolvingUris } from "redux/selectors/content";
|
|
|
|
import { makeSelectCostInfoForUri } from "redux/selectors/cost_info";
|
|
|
|
import { doAlertError, doOpenModal } from "redux/actions/app";
|
|
|
|
import { doClaimEligiblePurchaseRewards } from "redux/actions/rewards";
|
|
|
|
import { selectBadgeNumber } from "redux/selectors/app";
|
|
|
|
import { selectTotalDownloadProgress } from "redux/selectors/file_info";
|
2017-06-24 10:57:37 +02:00
|
|
|
import setBadge from "util/setBadge";
|
|
|
|
import setProgressBar from "util/setProgressBar";
|
2017-06-08 07:10:58 +02:00
|
|
|
import batchActions from "util/batchActions";
|
2017-07-15 20:44:50 +02:00
|
|
|
import * as modals from "constants/modal_types";
|
2017-04-23 11:56:50 +02:00
|
|
|
|
2017-06-24 18:48:01 +02:00
|
|
|
const { ipcRenderer } = require("electron");
|
|
|
|
|
2017-08-30 18:43:35 +02:00
|
|
|
const DOWNLOAD_POLL_INTERVAL = 250;
|
|
|
|
|
2017-10-09 08:23:44 +02:00
|
|
|
export function doResolveUris(uris) {
|
2017-04-26 19:08:26 +02:00
|
|
|
return function(dispatch, getState) {
|
2017-10-09 08:23:44 +02:00
|
|
|
uris = uris.map(lbryuri.normalize);
|
2017-06-06 23:19:12 +02:00
|
|
|
const state = getState();
|
2017-05-15 18:34:33 +02:00
|
|
|
|
2017-10-09 08:23:44 +02:00
|
|
|
// Filter out URIs that are already resolving
|
|
|
|
const resolvingUris = selectResolvingUris(state);
|
|
|
|
const urisToResolve = uris.filter(uri => !resolvingUris.includes(uri));
|
2017-05-15 18:34:33 +02:00
|
|
|
|
2017-10-09 08:23:44 +02:00
|
|
|
if (urisToResolve.length === 0) {
|
|
|
|
return;
|
2017-05-15 18:34:33 +02:00
|
|
|
}
|
|
|
|
|
2017-10-09 08:23:44 +02:00
|
|
|
dispatch({
|
|
|
|
type: types.RESOLVE_URIS_STARTED,
|
|
|
|
data: { uris },
|
|
|
|
});
|
2017-06-29 09:58:15 +02:00
|
|
|
|
2017-12-13 22:36:30 +01:00
|
|
|
const resolveInfo = {};
|
2017-10-09 08:23:44 +02:00
|
|
|
lbry.resolve({ uris: urisToResolve }).then(result => {
|
2017-12-13 22:36:30 +01:00
|
|
|
for (const [uri, uriResolveInfo] of Object.entries(result)) {
|
2017-10-12 16:05:18 +02:00
|
|
|
const fallbackResolveInfo = {
|
|
|
|
claim: null,
|
|
|
|
claims_in_channel: null,
|
|
|
|
certificate: null,
|
2017-10-09 08:23:44 +02:00
|
|
|
};
|
2017-10-12 16:05:18 +02:00
|
|
|
|
2017-11-21 20:51:12 +01:00
|
|
|
const { claim, certificate, claims_in_channel } =
|
|
|
|
uriResolveInfo && !uriResolveInfo.error
|
|
|
|
? uriResolveInfo
|
|
|
|
: fallbackResolveInfo;
|
2017-10-12 15:37:24 +02:00
|
|
|
resolveInfo[uri] = { claim, certificate, claims_in_channel };
|
2017-10-09 08:23:44 +02:00
|
|
|
}
|
2017-06-29 09:58:15 +02:00
|
|
|
|
|
|
|
dispatch({
|
2017-10-09 08:23:44 +02:00
|
|
|
type: types.RESOLVE_URIS_COMPLETED,
|
|
|
|
data: { resolveInfo },
|
2017-06-29 09:58:15 +02:00
|
|
|
});
|
2017-10-09 08:23:44 +02:00
|
|
|
});
|
2017-06-29 09:58:15 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-10-09 08:23:44 +02:00
|
|
|
export function doResolveUri(uri) {
|
|
|
|
return doResolveUris([uri]);
|
2017-06-29 09:58:15 +02:00
|
|
|
}
|
|
|
|
|
2017-05-04 05:44:08 +02:00
|
|
|
export function doFetchFeaturedUris() {
|
2017-04-23 11:56:50 +02:00
|
|
|
return function(dispatch, getState) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const state = getState();
|
2017-04-23 11:56:50 +02:00
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_FEATURED_CONTENT_STARTED,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-04-23 11:56:50 +02:00
|
|
|
|
2017-11-07 18:43:31 +01:00
|
|
|
const success = ({ Uris }) => {
|
2017-10-09 08:23:44 +02:00
|
|
|
let urisToResolve = [];
|
2017-12-13 22:36:30 +01:00
|
|
|
for (const category in Uris) {
|
2017-11-07 18:43:31 +01:00
|
|
|
urisToResolve = [...urisToResolve, ...Uris[category]];
|
|
|
|
}
|
2017-05-04 05:44:08 +02:00
|
|
|
|
2017-10-09 08:23:44 +02:00
|
|
|
const actions = [
|
|
|
|
doResolveUris(urisToResolve),
|
|
|
|
{
|
|
|
|
type: types.FETCH_FEATURED_CONTENT_COMPLETED,
|
|
|
|
data: {
|
2017-11-07 18:43:31 +01:00
|
|
|
uris: Uris,
|
2017-10-09 08:23:44 +02:00
|
|
|
success: true,
|
|
|
|
},
|
2017-06-06 23:19:12 +02:00
|
|
|
},
|
2017-10-09 08:23:44 +02:00
|
|
|
];
|
2017-06-08 07:10:58 +02:00
|
|
|
dispatch(batchActions(...actions));
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-23 11:56:50 +02:00
|
|
|
|
|
|
|
const failure = () => {
|
2017-05-04 05:44:08 +02:00
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_FEATURED_CONTENT_COMPLETED,
|
|
|
|
data: {
|
2017-06-06 23:19:12 +02:00
|
|
|
uris: {},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-11-07 18:43:31 +01:00
|
|
|
lbryio.call("file", "list_homepage").then(success, failure);
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-23 11:56:50 +02:00
|
|
|
}
|
2017-04-24 09:25:27 +02:00
|
|
|
|
2017-07-30 00:56:08 +02:00
|
|
|
export function doFetchRewardedContent() {
|
2017-07-25 09:07:54 +02:00
|
|
|
return function(dispatch, getState) {
|
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
const success = nameToClaimId => {
|
|
|
|
dispatch({
|
2017-07-30 00:56:08 +02:00
|
|
|
type: types.FETCH_REWARD_CONTENT_COMPLETED,
|
2017-07-25 09:07:54 +02:00
|
|
|
data: {
|
|
|
|
claimIds: Object.values(nameToClaimId),
|
|
|
|
success: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const failure = () => {
|
|
|
|
dispatch({
|
2017-07-30 00:56:08 +02:00
|
|
|
type: types.FETCH_REWARD_CONTENT_COMPLETED,
|
2017-07-25 09:07:54 +02:00
|
|
|
data: {
|
|
|
|
claimIds: [],
|
|
|
|
success: false,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
lbryio.call("reward", "list_featured").then(success, failure);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-04-26 19:08:26 +02:00
|
|
|
export function doUpdateLoadStatus(uri, outpoint) {
|
|
|
|
return function(dispatch, getState) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const state = getState();
|
2017-04-26 19:08:26 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
lbry
|
|
|
|
.file_list({
|
2017-12-13 22:36:30 +01:00
|
|
|
outpoint,
|
2017-06-06 23:19:12 +02:00
|
|
|
full_status: true,
|
|
|
|
})
|
|
|
|
.then(([fileInfo]) => {
|
|
|
|
if (!fileInfo || fileInfo.written_bytes == 0) {
|
|
|
|
// download hasn't started yet
|
|
|
|
setTimeout(() => {
|
|
|
|
dispatch(doUpdateLoadStatus(uri, outpoint));
|
2017-08-30 18:43:35 +02:00
|
|
|
}, DOWNLOAD_POLL_INTERVAL);
|
2017-06-06 23:19:12 +02:00
|
|
|
} else if (fileInfo.completed) {
|
|
|
|
// TODO this isn't going to get called if they reload the client before
|
|
|
|
// the download finished
|
|
|
|
dispatch({
|
|
|
|
type: types.DOWNLOADING_COMPLETED,
|
|
|
|
data: {
|
|
|
|
uri,
|
|
|
|
outpoint,
|
|
|
|
fileInfo,
|
|
|
|
},
|
|
|
|
});
|
2017-06-24 10:57:37 +02:00
|
|
|
|
|
|
|
const badgeNumber = selectBadgeNumber(getState());
|
|
|
|
setBadge(badgeNumber === 0 ? "" : `${badgeNumber}`);
|
2017-06-24 18:48:01 +02:00
|
|
|
|
2017-06-24 10:57:37 +02:00
|
|
|
const totalProgress = selectTotalDownloadProgress(getState());
|
|
|
|
setProgressBar(totalProgress);
|
2017-06-24 18:48:01 +02:00
|
|
|
|
2017-06-26 19:16:36 +02:00
|
|
|
const notif = new window.Notification("LBRY Download Complete", {
|
2017-06-24 18:48:01 +02:00
|
|
|
body: fileInfo.metadata.stream.metadata.title,
|
|
|
|
silent: false,
|
|
|
|
});
|
|
|
|
notif.onclick = () => {
|
|
|
|
ipcRenderer.send("focusWindow", "main");
|
|
|
|
};
|
2017-06-06 23:19:12 +02:00
|
|
|
} else {
|
|
|
|
// ready to play
|
|
|
|
const { total_bytes, written_bytes } = fileInfo;
|
|
|
|
const progress = written_bytes / total_bytes * 100;
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: types.DOWNLOADING_PROGRESSED,
|
|
|
|
data: {
|
|
|
|
uri,
|
|
|
|
outpoint,
|
|
|
|
fileInfo,
|
|
|
|
progress,
|
|
|
|
},
|
|
|
|
});
|
2017-06-24 10:57:37 +02:00
|
|
|
|
|
|
|
const totalProgress = selectTotalDownloadProgress(getState());
|
|
|
|
setProgressBar(totalProgress);
|
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
setTimeout(() => {
|
|
|
|
dispatch(doUpdateLoadStatus(uri, outpoint));
|
2017-08-30 18:43:35 +02:00
|
|
|
}, DOWNLOAD_POLL_INTERVAL);
|
2017-06-06 23:19:12 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2017-04-26 19:08:26 +02:00
|
|
|
}
|
|
|
|
|
2017-07-25 10:43:44 +02:00
|
|
|
export function doStartDownload(uri, outpoint) {
|
2017-04-26 19:08:26 +02:00
|
|
|
return function(dispatch, getState) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const state = getState();
|
2017-05-31 09:31:08 +02:00
|
|
|
|
2017-08-08 11:36:14 +02:00
|
|
|
if (!outpoint) {
|
|
|
|
throw new Error("outpoint is required to begin a download");
|
|
|
|
}
|
2017-07-30 21:20:36 +02:00
|
|
|
|
2017-07-25 10:43:44 +02:00
|
|
|
const { downloadingByOutpoint = {} } = state.fileInfo;
|
2017-04-26 19:08:26 +02:00
|
|
|
|
2017-07-25 10:43:44 +02:00
|
|
|
if (downloadingByOutpoint[outpoint]) return;
|
2017-04-26 19:08:26 +02:00
|
|
|
|
2017-07-25 10:43:44 +02:00
|
|
|
lbry.file_list({ outpoint, full_status: true }).then(([fileInfo]) => {
|
|
|
|
dispatch({
|
|
|
|
type: types.DOWNLOADING_STARTED,
|
|
|
|
data: {
|
|
|
|
uri,
|
|
|
|
outpoint,
|
|
|
|
fileInfo,
|
|
|
|
},
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-05-26 17:58:56 +02:00
|
|
|
|
2017-07-25 10:43:44 +02:00
|
|
|
dispatch(doUpdateLoadStatus(uri, outpoint));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function doDownloadFile(uri, streamInfo) {
|
|
|
|
return function(dispatch, getState) {
|
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
dispatch(doStartDownload(uri, streamInfo.outpoint));
|
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
lbryio
|
|
|
|
.call("file", "view", {
|
2017-12-13 22:36:30 +01:00
|
|
|
uri,
|
2017-06-06 23:19:12 +02:00
|
|
|
outpoint: streamInfo.outpoint,
|
|
|
|
claim_id: streamInfo.claim_id,
|
|
|
|
})
|
|
|
|
.catch(() => {});
|
2017-05-26 20:19:41 +02:00
|
|
|
|
2017-06-08 23:15:34 +02:00
|
|
|
dispatch(doClaimEligiblePurchaseRewards());
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-26 19:08:26 +02:00
|
|
|
}
|
|
|
|
|
2017-05-15 05:50:59 +02:00
|
|
|
export function doLoadVideo(uri) {
|
2017-04-26 19:08:26 +02:00
|
|
|
return function(dispatch, getState) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const state = getState();
|
2017-04-26 19:08:26 +02:00
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: types.LOADING_VIDEO_STARTED,
|
|
|
|
data: {
|
2017-06-06 23:19:12 +02:00
|
|
|
uri,
|
|
|
|
},
|
|
|
|
});
|
2017-04-26 19:08:26 +02:00
|
|
|
|
2017-08-08 11:36:14 +02:00
|
|
|
lbry
|
|
|
|
.get({ uri })
|
|
|
|
.then(streamInfo => {
|
|
|
|
const timeout =
|
|
|
|
streamInfo === null ||
|
|
|
|
typeof streamInfo !== "object" ||
|
|
|
|
streamInfo.error == "Timeout";
|
|
|
|
|
|
|
|
if (timeout) {
|
2017-10-01 07:39:00 +02:00
|
|
|
dispatch(doSetPlayingUri(null));
|
2017-08-08 11:36:14 +02:00
|
|
|
dispatch({
|
|
|
|
type: types.LOADING_VIDEO_FAILED,
|
|
|
|
data: { uri },
|
|
|
|
});
|
2017-05-02 09:07:13 +02:00
|
|
|
|
2017-09-08 05:15:05 +02:00
|
|
|
dispatch(doOpenModal(modals.FILE_TIMEOUT, { uri }));
|
2017-08-08 11:36:14 +02:00
|
|
|
} else {
|
|
|
|
dispatch(doDownloadFile(uri, streamInfo));
|
|
|
|
}
|
|
|
|
})
|
2017-12-06 21:38:07 +01:00
|
|
|
.catch(() => {
|
2017-10-01 07:39:00 +02:00
|
|
|
dispatch(doSetPlayingUri(null));
|
2017-04-26 19:08:26 +02:00
|
|
|
dispatch({
|
|
|
|
type: types.LOADING_VIDEO_FAILED,
|
2017-06-06 23:19:12 +02:00
|
|
|
data: { uri },
|
|
|
|
});
|
2017-12-06 21:38:07 +01:00
|
|
|
dispatch(
|
|
|
|
doAlertError(
|
2017-12-13 22:36:30 +01:00
|
|
|
`Failed to download ${
|
|
|
|
uri
|
|
|
|
}, please try again. If this problem persists, visit https://lbry.io/faq/support for support.`
|
2017-12-06 21:38:07 +01:00
|
|
|
)
|
|
|
|
);
|
2017-07-30 21:57:42 +02:00
|
|
|
});
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-26 19:08:26 +02:00
|
|
|
}
|
|
|
|
|
2017-09-08 05:15:05 +02:00
|
|
|
export function doPurchaseUri(uri) {
|
2017-04-26 19:08:26 +02:00
|
|
|
return function(dispatch, getState) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const state = getState();
|
|
|
|
const balance = selectBalance(state);
|
2017-09-08 05:15:05 +02:00
|
|
|
const fileInfo = makeSelectFileInfoForUri(uri)(state);
|
2017-07-21 10:02:29 +02:00
|
|
|
const downloadingByOutpoint = selectDownloadingByOutpoint(state);
|
|
|
|
const alreadyDownloading =
|
|
|
|
fileInfo && !!downloadingByOutpoint[fileInfo.outpoint];
|
2017-05-26 20:36:18 +02:00
|
|
|
|
2017-09-08 07:03:37 +02:00
|
|
|
function attemptPlay(cost, instantPurchaseMax = null) {
|
2017-09-29 02:32:59 +02:00
|
|
|
if (cost > 0 && (!instantPurchaseMax || cost > instantPurchaseMax)) {
|
2017-09-08 07:03:37 +02:00
|
|
|
dispatch(doOpenModal(modals.AFFIRM_PURCHASE, { uri }));
|
|
|
|
} else {
|
|
|
|
dispatch(doLoadVideo(uri));
|
|
|
|
}
|
2017-09-18 04:08:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// we already fully downloaded the file.
|
2017-09-08 07:03:37 +02:00
|
|
|
if (fileInfo && fileInfo.completed) {
|
|
|
|
// If written_bytes is false that means the user has deleted/moved the
|
|
|
|
// file manually on their file system, so we need to dispatch a
|
|
|
|
// doLoadVideo action to reconstruct the file from the blobs
|
|
|
|
if (!fileInfo.written_bytes) dispatch(doLoadVideo(uri));
|
|
|
|
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
// we are already downloading the file
|
|
|
|
if (alreadyDownloading) {
|
|
|
|
return Promise.resolve();
|
2017-04-27 17:10:39 +02:00
|
|
|
}
|
|
|
|
|
2017-09-08 07:03:37 +02:00
|
|
|
const costInfo = makeSelectCostInfoForUri(uri)(state);
|
|
|
|
const { cost } = costInfo;
|
|
|
|
|
2017-04-27 09:05:41 +02:00
|
|
|
if (cost > balance) {
|
2017-10-01 04:50:32 +02:00
|
|
|
dispatch(doSetPlayingUri(null));
|
2017-09-08 07:03:37 +02:00
|
|
|
dispatch(doOpenModal(modals.INSUFFICIENT_CREDITS));
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
cost == 0 ||
|
2017-09-23 01:23:51 +02:00
|
|
|
!makeSelectClientSetting(settings.INSTANT_PURCHASE_ENABLED)(state)
|
2017-09-08 07:03:37 +02:00
|
|
|
) {
|
|
|
|
attemptPlay(cost);
|
|
|
|
} else {
|
2017-09-23 01:23:51 +02:00
|
|
|
const instantPurchaseMax = makeSelectClientSetting(
|
2017-09-08 07:03:37 +02:00
|
|
|
settings.INSTANT_PURCHASE_MAX
|
2017-09-23 01:23:51 +02:00
|
|
|
)(state);
|
2017-09-08 07:03:37 +02:00
|
|
|
if (instantPurchaseMax.currency == "LBC") {
|
|
|
|
attemptPlay(cost, instantPurchaseMax.amount);
|
|
|
|
} else {
|
|
|
|
// Need to convert currency of instant purchase maximum before trying to play
|
|
|
|
lbryio.getExchangeRates().then(({ lbc_usd }) => {
|
|
|
|
attemptPlay(cost, instantPurchaseMax.amount / lbc_usd);
|
|
|
|
});
|
|
|
|
}
|
2017-04-26 19:08:26 +02:00
|
|
|
}
|
2017-06-06 23:19:12 +02:00
|
|
|
};
|
2017-04-26 19:08:26 +02:00
|
|
|
}
|
2017-05-13 00:50:51 +02:00
|
|
|
|
2017-07-17 08:06:04 +02:00
|
|
|
export function doFetchClaimsByChannel(uri, page) {
|
2017-05-13 00:50:51 +02:00
|
|
|
return function(dispatch, getState) {
|
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_CHANNEL_CLAIMS_STARTED,
|
2017-07-17 08:06:04 +02:00
|
|
|
data: { uri, page },
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-05-13 00:50:51 +02:00
|
|
|
|
2017-09-20 19:12:53 +02:00
|
|
|
lbry.claim_list_by_channel({ uri, page: page || 1 }).then(result => {
|
2017-09-30 01:15:14 +02:00
|
|
|
const claimResult = result[uri] || {};
|
|
|
|
const { claims_in_channel, returned_page } = claimResult;
|
2017-05-13 00:50:51 +02:00
|
|
|
|
|
|
|
dispatch({
|
2017-05-19 01:14:26 +02:00
|
|
|
type: types.FETCH_CHANNEL_CLAIMS_COMPLETED,
|
2017-05-13 00:50:51 +02:00
|
|
|
data: {
|
|
|
|
uri,
|
2017-10-01 18:48:31 +02:00
|
|
|
claims: claims_in_channel || [],
|
|
|
|
page: returned_page || undefined,
|
2017-06-06 23:19:12 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2017-05-19 01:14:26 +02:00
|
|
|
}
|
|
|
|
|
2017-08-24 23:12:23 +02:00
|
|
|
export function doFetchClaimCountByChannel(uri) {
|
|
|
|
return function(dispatch, getState) {
|
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_CHANNEL_CLAIM_COUNT_STARTED,
|
|
|
|
data: { uri },
|
|
|
|
});
|
|
|
|
|
|
|
|
lbry.claim_list_by_channel({ uri }).then(result => {
|
|
|
|
const claimResult = result[uri],
|
|
|
|
totalClaims = claimResult ? claimResult.claims_in_channel : 0;
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_CHANNEL_CLAIM_COUNT_COMPLETED,
|
|
|
|
data: {
|
|
|
|
uri,
|
|
|
|
totalClaims,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-05-28 15:01:11 +02:00
|
|
|
export function doFetchClaimListMine() {
|
2017-05-19 01:14:26 +02:00
|
|
|
return function(dispatch, getState) {
|
|
|
|
dispatch({
|
2017-06-06 23:19:12 +02:00
|
|
|
type: types.FETCH_CLAIM_LIST_MINE_STARTED,
|
|
|
|
});
|
2017-05-19 01:14:26 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
lbry.claim_list_mine().then(claims => {
|
2017-05-13 00:50:51 +02:00
|
|
|
dispatch({
|
2017-05-28 15:01:11 +02:00
|
|
|
type: types.FETCH_CLAIM_LIST_MINE_COMPLETED,
|
2017-05-13 00:50:51 +02:00
|
|
|
data: {
|
2017-06-06 23:19:12 +02:00
|
|
|
claims,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2017-06-06 06:21:55 +02:00
|
|
|
}
|
2017-07-10 16:49:12 +02:00
|
|
|
|
2017-09-18 04:08:43 +02:00
|
|
|
export function doPlayUri(uri) {
|
|
|
|
return function(dispatch, getState) {
|
|
|
|
dispatch(doSetPlayingUri(uri));
|
|
|
|
dispatch(doPurchaseUri(uri));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function doSetPlayingUri(uri) {
|
|
|
|
return function(dispatch, getState) {
|
|
|
|
dispatch({
|
|
|
|
type: types.SET_PLAYING_URI,
|
|
|
|
data: { uri },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-07-10 16:49:12 +02:00
|
|
|
export function doFetchChannelListMine() {
|
|
|
|
return function(dispatch, getState) {
|
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_CHANNEL_LIST_MINE_STARTED,
|
|
|
|
});
|
|
|
|
|
|
|
|
const callback = channels => {
|
|
|
|
dispatch({
|
|
|
|
type: types.FETCH_CHANNEL_LIST_MINE_COMPLETED,
|
|
|
|
data: { claims: channels },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
lbry.channel_list_mine().then(callback);
|
|
|
|
};
|
|
|
|
}
|
2017-06-17 19:59:18 +02:00
|
|
|
|
|
|
|
export function doCreateChannel(name, amount) {
|
|
|
|
return function(dispatch, getState) {
|
|
|
|
dispatch({
|
|
|
|
type: types.CREATE_CHANNEL_STARTED,
|
|
|
|
});
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
lbry
|
|
|
|
.channel_new({
|
|
|
|
channel_name: name,
|
|
|
|
amount: parseFloat(amount),
|
|
|
|
})
|
|
|
|
.then(
|
|
|
|
channelClaim => {
|
|
|
|
channelClaim.name = name;
|
|
|
|
dispatch({
|
|
|
|
type: types.CREATE_CHANNEL_COMPLETED,
|
|
|
|
data: { channelClaim },
|
|
|
|
});
|
|
|
|
resolve(channelClaim);
|
|
|
|
},
|
|
|
|
err => {
|
2017-07-11 08:01:44 +02:00
|
|
|
reject(err);
|
2017-06-17 19:59:18 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function doPublish(params) {
|
|
|
|
return function(dispatch, getState) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const success = claim => {
|
|
|
|
resolve(claim);
|
2017-07-10 16:44:49 +02:00
|
|
|
|
|
|
|
if (claim === true) dispatch(doFetchClaimListMine());
|
|
|
|
else
|
|
|
|
setTimeout(() => dispatch(doFetchClaimListMine()), 20000, {
|
|
|
|
once: true,
|
|
|
|
});
|
2017-06-17 19:59:18 +02:00
|
|
|
};
|
2017-07-10 16:44:49 +02:00
|
|
|
const failure = err => reject(err);
|
2017-06-17 19:59:18 +02:00
|
|
|
|
2017-07-10 16:44:49 +02:00
|
|
|
lbry.publishDeprecated(params, null, success, failure);
|
2017-06-17 19:59:18 +02:00
|
|
|
});
|
|
|
|
};
|
2017-07-30 21:37:44 +02:00
|
|
|
}
|
2017-10-24 15:10:27 +02:00
|
|
|
|
2017-11-01 21:23:30 +01:00
|
|
|
export function doAbandonClaim(txid, nout) {
|
2017-10-24 15:10:27 +02:00
|
|
|
return function(dispatch, getState) {
|
|
|
|
const state = getState();
|
2017-11-01 21:23:30 +01:00
|
|
|
const transactionItems = selectTransactionItems(state);
|
|
|
|
const { claim_id: claimId, claim_name: name } = transactionItems.find(
|
|
|
|
claim => claim.txid == txid && claim.nout == nout
|
|
|
|
);
|
2017-10-24 15:10:27 +02:00
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: types.ABANDON_CLAIM_STARTED,
|
|
|
|
data: {
|
2017-12-13 22:36:30 +01:00
|
|
|
claimId,
|
2017-10-24 15:10:27 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-10-30 17:25:56 +01:00
|
|
|
const errorCallback = error => {
|
|
|
|
dispatch(doOpenModal(modals.TRANSACTION_FAILED));
|
|
|
|
};
|
|
|
|
|
|
|
|
const successCallback = results => {
|
|
|
|
if (results.txid) {
|
|
|
|
dispatch({
|
|
|
|
type: types.ABANDON_CLAIM_SUCCEEDED,
|
|
|
|
data: {
|
2017-12-13 22:36:30 +01:00
|
|
|
claimId,
|
2017-10-30 17:25:56 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
dispatch(doResolveUri(lbryuri.build({ name, claimId })));
|
|
|
|
dispatch(doFetchClaimListMine());
|
|
|
|
} else {
|
|
|
|
dispatch(doOpenModal(modals.TRANSACTION_FAILED));
|
|
|
|
}
|
|
|
|
};
|
2017-10-24 15:10:27 +02:00
|
|
|
|
|
|
|
lbry
|
|
|
|
.claim_abandon({
|
2017-12-13 22:36:30 +01:00
|
|
|
txid,
|
|
|
|
nout,
|
2017-10-24 15:10:27 +02:00
|
|
|
})
|
2017-10-30 17:25:56 +01:00
|
|
|
.then(successCallback, errorCallback);
|
2017-10-24 15:10:27 +02:00
|
|
|
};
|
|
|
|
}
|