diff --git a/ui/js/actions/app.js b/ui/js/actions/app.js index bf0451c82..709d85ffb 100644 --- a/ui/js/actions/app.js +++ b/ui/js/actions/app.js @@ -1,5 +1,5 @@ -import * as types from 'constants/action_types' -import lbry from 'lbry' +import * as types from "constants/action_types"; +import lbry from "lbry"; import { selectUpdateUrl, selectUpgradeDownloadPath, @@ -8,36 +8,30 @@ import { selectPageTitle, selectCurrentPage, selectCurrentParams, -} from 'selectors/app' -import { - doSearch, -} from 'actions/search' +} from "selectors/app"; +import { doSearch } from "actions/search"; -const {remote, ipcRenderer, shell} = require('electron'); -const path = require('path'); -const app = require('electron').remote.app; -const {download} = remote.require('electron-dl'); -const fs = remote.require('fs'); +const { remote, ipcRenderer, shell } = require("electron"); +const path = require("path"); +const app = require("electron").remote.app; +const { download } = remote.require("electron-dl"); +const fs = remote.require("fs"); -const queryStringFromParams = (params) => { - return Object - .keys(params) - .map(key => `${key}=${params[key]}`) - .join('&') -} +const queryStringFromParams = params => { + return Object.keys(params).map(key => `${key}=${params[key]}`).join("&"); +}; export function doNavigate(path, params = {}) { return function(dispatch, getState) { - let url = path - if (params) - url = `${url}?${queryStringFromParams(params)}` + let url = path; + if (params) url = `${url}?${queryStringFromParams(params)}`; - dispatch(doChangePath(url)) + dispatch(doChangePath(url)); - const state = getState() - const pageTitle = selectPageTitle(state) - dispatch(doHistoryPush(params, pageTitle, url)) - } + const state = getState(); + const pageTitle = selectPageTitle(state); + dispatch(doHistoryPush(params, pageTitle, url)); + }; } export function doChangePath(path) { @@ -46,121 +40,124 @@ export function doChangePath(path) { type: types.CHANGE_PATH, data: { path, - } - }) + }, + }); - const state = getState() - const pageTitle = selectPageTitle(state) - window.document.title = pageTitle - window.scrollTo(0, 0) + const state = getState(); + const pageTitle = selectPageTitle(state); + window.document.title = pageTitle; + window.scrollTo(0, 0); - const currentPage = selectCurrentPage(state) - if (currentPage === 'search') { - const params = selectCurrentParams(state) - dispatch(doSearch(params.query)) + const currentPage = selectCurrentPage(state); + if (currentPage === "search") { + const params = selectCurrentParams(state); + dispatch(doSearch(params.query)); } - } + }; } export function doHistoryBack() { return function(dispatch, getState) { - history.back() - } + history.back(); + }; } export function doHistoryPush(params, title, relativeUrl) { return function(dispatch, getState) { - let pathParts = window.location.pathname.split('/') - pathParts[pathParts.length - 1] = relativeUrl.replace(/^\//, '') - const url = pathParts.join('/') - title += " - LBRY" - history.pushState(params, title, url) - } + let pathParts = window.location.pathname.split("/"); + pathParts[pathParts.length - 1] = relativeUrl.replace(/^\//, ""); + const url = pathParts.join("/"); + title += " - LBRY"; + history.pushState(params, title, url); + }; } export function doOpenModal(modal) { return { type: types.OPEN_MODAL, data: { - modal - } - } + modal, + }, + }; } export function doCloseModal() { return { type: types.CLOSE_MODAL, - } + }; } export function doUpdateDownloadProgress(percent) { return { type: types.UPGRADE_DOWNLOAD_PROGRESSED, data: { - percent: percent - } - } + percent: percent, + }, + }; } export function doSkipUpgrade() { return { - type: types.SKIP_UPGRADE - } + type: types.SKIP_UPGRADE, + }; } export function doStartUpgrade() { return function(dispatch, getState) { - const state = getState() - const upgradeDownloadPath = selectUpgradeDownloadPath(state) + const state = getState(); + const upgradeDownloadPath = selectUpgradeDownloadPath(state); - ipcRenderer.send('upgrade', upgradeDownloadPath) - } + ipcRenderer.send("upgrade", upgradeDownloadPath); + }; } export function doDownloadUpgrade() { return function(dispatch, getState) { - const state = getState() + const state = getState(); // Make a new directory within temp directory so the filename is guaranteed to be available - const dir = fs.mkdtempSync(app.getPath('temp') + require('path').sep); - const upgradeFilename = selectUpgradeFilename(state) + const dir = fs.mkdtempSync(app.getPath("temp") + require("path").sep); + const upgradeFilename = selectUpgradeFilename(state); let options = { - onProgress: (p) => dispatch(doUpdateDownloadProgress(Math.round(p * 100))), + onProgress: p => dispatch(doUpdateDownloadProgress(Math.round(p * 100))), directory: dir, }; - download(remote.getCurrentWindow(), selectUpdateUrl(state), options) - .then(downloadItem => { - /** + download( + remote.getCurrentWindow(), + selectUpdateUrl(state), + options + ).then(downloadItem => { + /** * TODO: get the download path directly from the download object. It should just be * downloadItem.getSavePath(), but the copy on the main process is being garbage collected * too soon. */ - dispatch({ - type: types.UPGRADE_DOWNLOAD_COMPLETED, - data: { - downloadItem, - path: path.join(dir, upgradeFilename) - } - }) + dispatch({ + type: types.UPGRADE_DOWNLOAD_COMPLETED, + data: { + downloadItem, + path: path.join(dir, upgradeFilename), + }, }); + }); dispatch({ - type: types.UPGRADE_DOWNLOAD_STARTED - }) + type: types.UPGRADE_DOWNLOAD_STARTED, + }); dispatch({ type: types.OPEN_MODAL, data: { - modal: 'downloading' - } - }) - } + modal: "downloading", + }, + }); + }; } export function doCancelUpgrade() { return function(dispatch, getState) { - const state = getState() - const upgradeDownloadItem = selectUpgradeDownloadItem(state) + const state = getState(); + const upgradeDownloadItem = selectUpgradeDownloadItem(state); if (upgradeDownloadItem) { /* @@ -171,68 +168,68 @@ export function doCancelUpgrade() { try { upgradeDownloadItem.cancel(); } catch (err) { - console.error(err) + console.error(err); // Do nothing } } - dispatch({ type: types.UPGRADE_CANCELLED }) - } + dispatch({ type: types.UPGRADE_CANCELLED }); + }; } export function doCheckUpgradeAvailable() { return function(dispatch, getState) { - const state = getState() + const state = getState(); - lbry.getAppVersionInfo().then(({remoteVersion, upgradeAvailable}) => { + lbry.getAppVersionInfo().then(({ remoteVersion, upgradeAvailable }) => { if (upgradeAvailable) { dispatch({ type: types.UPDATE_VERSION, data: { version: remoteVersion, - } - }) + }, + }); dispatch({ type: types.OPEN_MODAL, data: { - modal: 'upgrade' - } - }) + modal: "upgrade", + }, + }); } }); - } + }; } export function doAlertError(errorList) { return function(dispatch, getState) { - const state = getState() - console.log('do alert error') - console.log(errorList) + const state = getState(); + console.log("do alert error"); + console.log(errorList); dispatch({ type: types.OPEN_MODAL, data: { - modal: 'error', - extraContent: errorList - } - }) - } + modal: "error", + extraContent: errorList, + }, + }); + }; } export function doDaemonReady() { return { - type: types.DAEMON_READY - } + type: types.DAEMON_READY, + }; } export function doShowSnackBar(data) { return { type: types.SHOW_SNACKBAR, data, - } + }; } export function doRemoveSnackBarSnack() { return { type: types.REMOVE_SNACKBAR_SNACK, - } + }; } diff --git a/ui/js/actions/availability.js b/ui/js/actions/availability.js index 501a2eeda..2c7cbc3cb 100644 --- a/ui/js/actions/availability.js +++ b/ui/js/actions/availability.js @@ -1,29 +1,27 @@ -import * as types from 'constants/action_types' -import lbry from 'lbry' -import { - selectFetchingAvailability -} from 'selectors/availability' +import * as types from "constants/action_types"; +import lbry from "lbry"; +import { selectFetchingAvailability } from "selectors/availability"; export function doFetchAvailability(uri) { return function(dispatch, getState) { - const state = getState() - const alreadyFetching = !!selectFetchingAvailability(state)[uri] + const state = getState(); + const alreadyFetching = !!selectFetchingAvailability(state)[uri]; if (!alreadyFetching) { dispatch({ type: types.FETCH_AVAILABILITY_STARTED, - data: {uri} - }) + data: { uri }, + }); - lbry.get_availability({uri}).then((availability) => { + lbry.get_availability({ uri }).then(availability => { dispatch({ type: types.FETCH_AVAILABILITY_COMPLETED, data: { availability, uri, - } - }) - }) + }, + }); + }); } - } -} \ No newline at end of file + }; +} diff --git a/ui/js/actions/content.js b/ui/js/actions/content.js index a7276abf9..f9fe0b02b 100644 --- a/ui/js/actions/content.js +++ b/ui/js/actions/content.js @@ -1,47 +1,35 @@ -import * as types from 'constants/action_types' -import lbry from 'lbry' -import lbryio from 'lbryio' -import lbryuri from 'lbryuri' -import rewards from 'rewards' -import { - selectBalance, -} from 'selectors/wallet' +import * as types from "constants/action_types"; +import lbry from "lbry"; +import lbryio from "lbryio"; +import lbryuri from "lbryuri"; +import rewards from "rewards"; +import { selectBalance } from "selectors/wallet"; import { selectFileInfoForUri, selectUrisDownloading, -} from 'selectors/file_info' -import { - selectResolvingUris -} from 'selectors/content' -import { - selectCostInfoForUri, -} from 'selectors/cost_info' -import { - selectClaimsByUri, -} from 'selectors/claims' -import { - doOpenModal, -} from 'actions/app' +} from "selectors/file_info"; +import { selectResolvingUris } from "selectors/content"; +import { selectCostInfoForUri } from "selectors/cost_info"; +import { selectClaimsByUri } from "selectors/claims"; +import { doOpenModal } from "actions/app"; export function doResolveUri(uri) { return function(dispatch, getState) { + uri = lbryuri.normalize(uri); - uri = lbryuri.normalize(uri) - - const state = getState() - const alreadyResolving = selectResolvingUris(state).indexOf(uri) !== -1 + const state = getState(); + const alreadyResolving = selectResolvingUris(state).indexOf(uri) !== -1; if (!alreadyResolving) { dispatch({ type: types.RESOLVE_URI_STARTED, - data: { uri } - }) + data: { uri }, + }); - lbry.resolve({ uri }).then((resolutionInfo) => { - const { - claim, - certificate, - } = resolutionInfo ? resolutionInfo : { claim : null, certificate: null } + lbry.resolve({ uri }).then(resolutionInfo => { + const { claim, certificate } = resolutionInfo + ? resolutionInfo + : { claim: null, certificate: null }; dispatch({ type: types.RESOLVE_URI_COMPLETED, @@ -49,246 +37,252 @@ export function doResolveUri(uri) { uri, claim, certificate, - } - }) - }) + }, + }); + }); } - } + }; } export function doCancelResolveUri(uri) { return function(dispatch, getState) { - lbry.cancelResolve({ uri }) + lbry.cancelResolve({ uri }); dispatch({ type: types.RESOLVE_URI_CANCELED, - data: { uri } - }) - } + data: { uri }, + }); + }; } export function doFetchFeaturedUris() { return function(dispatch, getState) { - const state = getState() + const state = getState(); dispatch({ type: types.FETCH_FEATURED_CONTENT_STARTED, - }) + }); const success = ({ Categories, Uris }) => { + let featuredUris = {}; - let featuredUris = {} - - Categories.forEach((category) => { + Categories.forEach(category => { if (Uris[category] && Uris[category].length) { - featuredUris[category] = Uris[category] + featuredUris[category] = Uris[category]; } - }) + }); dispatch({ type: types.FETCH_FEATURED_CONTENT_COMPLETED, data: { categories: Categories, uris: featuredUris, - } - }) - } + }, + }); + }; const failure = () => { dispatch({ type: types.FETCH_FEATURED_CONTENT_COMPLETED, data: { categories: [], - uris: {} - } - }) - } + uris: {}, + }, + }); + }; - lbryio.call('discover', 'list', { version: "early-access" } ) - .then(success, failure) - } + lbryio + .call("discover", "list", { version: "early-access" }) + .then(success, failure); + }; } export function doUpdateLoadStatus(uri, outpoint) { return function(dispatch, getState) { - const state = getState() + const state = getState(); - lbry.file_list({ - outpoint: outpoint, - full_status: true, - }).then(([fileInfo]) => { - if(!fileInfo || fileInfo.written_bytes == 0) { - // download hasn't started yet - setTimeout(() => { dispatch(doUpdateLoadStatus(uri, outpoint)) }, 250) - } 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, - } - }) - } else { - // ready to play - const { - total_bytes, - written_bytes, - } = fileInfo - const progress = (written_bytes / total_bytes) * 100 + lbry + .file_list({ + outpoint: outpoint, + full_status: true, + }) + .then(([fileInfo]) => { + if (!fileInfo || fileInfo.written_bytes == 0) { + // download hasn't started yet + setTimeout(() => { + dispatch(doUpdateLoadStatus(uri, outpoint)); + }, 250); + } 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, + }, + }); + } 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, - } - }) - setTimeout(() => { dispatch(doUpdateLoadStatus(uri, outpoint)) }, 250) - } - }) - } + dispatch({ + type: types.DOWNLOADING_PROGRESSED, + data: { + uri, + outpoint, + fileInfo, + progress, + }, + }); + setTimeout(() => { + dispatch(doUpdateLoadStatus(uri, outpoint)); + }, 250); + } + }); + }; } export function doDownloadFile(uri, streamInfo) { return function(dispatch, getState) { - const state = getState() + const state = getState(); - lbry.file_list({ outpoint: streamInfo.outpoint, full_status: true }).then(([fileInfo]) => { - dispatch({ - type: types.DOWNLOADING_STARTED, - data: { - uri, - outpoint: streamInfo.outpoint, - fileInfo, - } + lbry + .file_list({ outpoint: streamInfo.outpoint, full_status: true }) + .then(([fileInfo]) => { + dispatch({ + type: types.DOWNLOADING_STARTED, + data: { + uri, + outpoint: streamInfo.outpoint, + fileInfo, + }, + }); + + dispatch(doUpdateLoadStatus(uri, streamInfo.outpoint)); + }); + + lbryio + .call("file", "view", { + uri: uri, + outpoint: streamInfo.outpoint, + claim_id: streamInfo.claim_id, }) + .catch(() => {}); - dispatch(doUpdateLoadStatus(uri, streamInfo.outpoint)) - }) - - lbryio.call('file', 'view', { - uri: uri, - outpoint: streamInfo.outpoint, - claim_id: streamInfo.claim_id, - }).catch(() => {}) - - rewards.claimEligiblePurchaseRewards() - - } + rewards.claimEligiblePurchaseRewards(); + }; } export function doLoadVideo(uri) { return function(dispatch, getState) { - const state = getState() + const state = getState(); dispatch({ type: types.LOADING_VIDEO_STARTED, data: { - uri - } - }) + uri, + }, + }); lbry.get({ uri }).then(streamInfo => { - const timeout = streamInfo === null || - typeof streamInfo !== 'object' || - streamInfo.error == 'Timeout' + const timeout = + streamInfo === null || + typeof streamInfo !== "object" || + streamInfo.error == "Timeout"; - if(timeout) { + if (timeout) { dispatch({ type: types.LOADING_VIDEO_FAILED, - data: { uri } - }) - dispatch(doOpenModal('timedOut')) + data: { uri }, + }); + dispatch(doOpenModal("timedOut")); } else { - dispatch(doDownloadFile(uri, streamInfo)) + dispatch(doDownloadFile(uri, streamInfo)); } - }) - } + }); + }; } export function doPurchaseUri(uri, purchaseModalName) { return function(dispatch, getState) { - const state = getState() - const balance = selectBalance(state) - const fileInfo = selectFileInfoForUri(state, { uri }) - const downloadingByUri = selectUrisDownloading(state) - const alreadyDownloading = !!downloadingByUri[uri] + const state = getState(); + const balance = selectBalance(state); + const fileInfo = selectFileInfoForUri(state, { uri }); + const downloadingByUri = selectUrisDownloading(state); + const alreadyDownloading = !!downloadingByUri[uri]; // we already fully downloaded the file. 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)) + if (!fileInfo.written_bytes) dispatch(doLoadVideo(uri)); - return Promise.resolve() + return Promise.resolve(); } // we are already downloading the file if (alreadyDownloading) { - return Promise.resolve() + return Promise.resolve(); } - const costInfo = selectCostInfoForUri(state, { uri }) - const { cost } = costInfo + const costInfo = selectCostInfoForUri(state, { uri }); + const { cost } = costInfo; // the file is free or we have partially downloaded it if (cost <= 0.01 || (fileInfo && fileInfo.download_directory)) { - dispatch(doLoadVideo(uri)) - return Promise.resolve() + dispatch(doLoadVideo(uri)); + return Promise.resolve(); } if (cost > balance) { - dispatch(doOpenModal('notEnoughCredits')) + dispatch(doOpenModal("notEnoughCredits")); } else { - dispatch(doOpenModal(purchaseModalName)) + dispatch(doOpenModal(purchaseModalName)); } - return Promise.resolve() - } + return Promise.resolve(); + }; } export function doFetchClaimsByChannel(uri) { return function(dispatch, getState) { dispatch({ type: types.FETCH_CHANNEL_CLAIMS_STARTED, - data: { uri } - }) + data: { uri }, + }); - lbry.resolve({ uri }).then((resolutionInfo) => { - const { - claims_in_channel, - } = resolutionInfo ? resolutionInfo : { claims_in_channel: [] } + lbry.resolve({ uri }).then(resolutionInfo => { + const { claims_in_channel } = resolutionInfo + ? resolutionInfo + : { claims_in_channel: [] }; dispatch({ type: types.FETCH_CHANNEL_CLAIMS_COMPLETED, data: { uri, - claims: claims_in_channel - } - }) - }) - } + claims: claims_in_channel, + }, + }); + }); + }; } export function doFetchClaimListMine() { return function(dispatch, getState) { dispatch({ - type: types.FETCH_CLAIM_LIST_MINE_STARTED - }) + type: types.FETCH_CLAIM_LIST_MINE_STARTED, + }); - - lbry.claim_list_mine().then((claims) => { + lbry.claim_list_mine().then(claims => { dispatch({ type: types.FETCH_CLAIM_LIST_MINE_COMPLETED, data: { - claims - } - }) - }) - } -} \ No newline at end of file + claims, + }, + }); + }); + }; +} diff --git a/ui/js/actions/cost_info.js b/ui/js/actions/cost_info.js index dbad86f33..e8485deff 100644 --- a/ui/js/actions/cost_info.js +++ b/ui/js/actions/cost_info.js @@ -1,48 +1,40 @@ - import * as types from 'constants/action_types' -import lbry from 'lbry' -import lbryio from 'lbryio' -import { - doResolveUri -} from 'actions/content' -import { - selectResolvingUris, -} from 'selectors/content' -import { - selectClaimsByUri -} from 'selectors/claims' -import { - selectSettingsIsGenerous -} from 'selectors/settings' +import * as types from "constants/action_types"; +import lbry from "lbry"; +import lbryio from "lbryio"; +import { doResolveUri } from "actions/content"; +import { selectResolvingUris } from "selectors/content"; +import { selectClaimsByUri } from "selectors/claims"; +import { selectSettingsIsGenerous } from "selectors/settings"; export function doFetchCostInfoForUri(uri) { return function(dispatch, getState) { const state = getState(), - claim = selectClaimsByUri(state)[uri], - isResolving = selectResolvingUris(state).indexOf(uri) !== -1, - isGenerous = selectSettingsIsGenerous(state) + claim = selectClaimsByUri(state)[uri], + isResolving = selectResolvingUris(state).indexOf(uri) !== -1, + isGenerous = selectSettingsIsGenerous(state); - if (claim === null) { //claim doesn't exist, nothing to fetch a cost for - return + if (claim === null) { + //claim doesn't exist, nothing to fetch a cost for + return; } if (!claim) { setTimeout(() => { - dispatch(doFetchCostInfoForUri(uri)) - }, 1000) + dispatch(doFetchCostInfoForUri(uri)); + }, 1000); if (!isResolving) { - dispatch(doResolveUri(uri)) + dispatch(doResolveUri(uri)); } - return + return; } - function begin() { dispatch({ type: types.FETCH_COST_INFO_STARTED, data: { uri, - } - }) + }, + }); } function resolve(costInfo) { @@ -51,27 +43,26 @@ export function doFetchCostInfoForUri(uri) { data: { uri, costInfo, - } - }) + }, + }); } if (isGenerous && claim) { - let cost + let cost; const fee = claim.value.stream.metadata.fee; - if (fee === undefined ) { - resolve({ cost: 0, includesData: true }) - } else if (fee.currency == 'LBC') { - resolve({ cost: fee.amount, includesData: true }) + if (fee === undefined) { + resolve({ cost: 0, includesData: true }); + } else if (fee.currency == "LBC") { + resolve({ cost: fee.amount, includesData: true }); } else { - begin() - lbryio.getExchangeRates().then(({lbc_usd}) => { - resolve({ cost: fee.amount / lbc_usd, includesData: true }) + begin(); + lbryio.getExchangeRates().then(({ lbc_usd }) => { + resolve({ cost: fee.amount / lbc_usd, includesData: true }); }); } } else { - begin() - lbry.getCostInfo(uri).then(resolve) + begin(); + lbry.getCostInfo(uri).then(resolve); } - } + }; } - diff --git a/ui/js/actions/file_info.js b/ui/js/actions/file_info.js index 44d76885c..d379db625 100644 --- a/ui/js/actions/file_info.js +++ b/ui/js/actions/file_info.js @@ -1,121 +1,113 @@ -import * as types from 'constants/action_types' -import lbry from 'lbry' -import { - doFetchClaimListMine -} from 'actions/content' +import * as types from "constants/action_types"; +import lbry from "lbry"; +import { doFetchClaimListMine } from "actions/content"; import { selectClaimsByUri, selectClaimListMineIsPending, -} from 'selectors/claims' +} from "selectors/claims"; import { selectFileListIsPending, selectAllFileInfos, selectUrisLoading, -} from 'selectors/file_info' -import { - doCloseModal, -} from 'actions/app' +} from "selectors/file_info"; +import { doCloseModal } from "actions/app"; -const { - shell, -} = require('electron') +const { shell } = require("electron"); export function doFetchFileInfo(uri) { return function(dispatch, getState) { - const state = getState() - const claim = selectClaimsByUri(state)[uri] - const outpoint = claim ? `${claim.txid}:${claim.nout}` : null - const alreadyFetching = !!selectUrisLoading(state)[uri] + const state = getState(); + const claim = selectClaimsByUri(state)[uri]; + const outpoint = claim ? `${claim.txid}:${claim.nout}` : null; + const alreadyFetching = !!selectUrisLoading(state)[uri]; if (!alreadyFetching) { dispatch({ type: types.FETCH_FILE_INFO_STARTED, data: { outpoint, - } - }) + }, + }); - lbry.file_list({outpoint: outpoint, full_status: true}).then(fileInfos => { - - dispatch({ - type: types.FETCH_FILE_INFO_COMPLETED, - data: { - outpoint, - fileInfo: fileInfos && fileInfos.length ? fileInfos[0] : null, - } - }) - }) + lbry + .file_list({ outpoint: outpoint, full_status: true }) + .then(fileInfos => { + dispatch({ + type: types.FETCH_FILE_INFO_COMPLETED, + data: { + outpoint, + fileInfo: fileInfos && fileInfos.length ? fileInfos[0] : null, + }, + }); + }); } - } + }; } export function doFileList() { return function(dispatch, getState) { - const state = getState() - const isPending = selectFileListIsPending(state) + const state = getState(); + const isPending = selectFileListIsPending(state); if (!isPending) { dispatch({ type: types.FILE_LIST_STARTED, - }) + }); - lbry.file_list().then((fileInfos) => { + lbry.file_list().then(fileInfos => { dispatch({ type: types.FILE_LIST_COMPLETED, data: { fileInfos, - } - }) - }) + }, + }); + }); } - } + }; } export function doOpenFileInShell(fileInfo) { return function(dispatch, getState) { - shell.openItem(fileInfo.download_path) - } + shell.openItem(fileInfo.download_path); + }; } export function doOpenFileInFolder(fileInfo) { return function(dispatch, getState) { - shell.showItemInFolder(fileInfo.download_path) - } + shell.showItemInFolder(fileInfo.download_path); + }; } export function doDeleteFile(outpoint, deleteFromComputer) { return function(dispatch, getState) { - dispatch({ type: types.FILE_DELETE, data: { - outpoint - } - }) + outpoint, + }, + }); lbry.file_delete({ outpoint: outpoint, delete_target_file: deleteFromComputer, - }) + }); - dispatch(doCloseModal()) - } + dispatch(doCloseModal()); + }; } - export function doFetchFileInfosAndPublishedClaims() { return function(dispatch, getState) { const state = getState(), - isClaimListMinePending = selectClaimListMineIsPending(state), - isFileInfoListPending = selectFileListIsPending(state) + isClaimListMinePending = selectClaimListMineIsPending(state), + isFileInfoListPending = selectFileListIsPending(state); if (isClaimListMinePending === undefined) { - dispatch(doFetchClaimListMine()) + dispatch(doFetchClaimListMine()); } if (isFileInfoListPending === undefined) { - dispatch(doFileList()) + dispatch(doFileList()); } - } + }; } - diff --git a/ui/js/actions/rewards.js b/ui/js/actions/rewards.js index 84f65047f..4c12d9c20 100644 --- a/ui/js/actions/rewards.js +++ b/ui/js/actions/rewards.js @@ -1,36 +1,35 @@ -import * as types from 'constants/action_types' -import lbry from 'lbry' -import lbryio from 'lbryio'; -import rewards from 'rewards' +import * as types from "constants/action_types"; +import lbry from "lbry"; +import lbryio from "lbryio"; +import rewards from "rewards"; export function doFetchRewards() { return function(dispatch, getState) { - const state = getState() + const state = getState(); dispatch({ type: types.FETCH_REWARDS_STARTED, - }) + }); - lbryio.call('reward', 'list', {}).then(function(userRewards) { + lbryio.call("reward", "list", {}).then(function(userRewards) { dispatch({ type: types.FETCH_REWARDS_COMPLETED, - data: { userRewards } - }) + data: { userRewards }, + }); }); - } + }; } export function doClaimReward(rewardType) { return function(dispatch, getState) { try { - rewards.claimReward(rewards[rewardType]) + rewards.claimReward(rewards[rewardType]); dispatch({ type: types.REWARD_CLAIMED, data: { - reward: rewards[rewardType] - } - }) - } catch(err) { - } - } + reward: rewards[rewardType], + }, + }); + } catch (err) {} + }; } diff --git a/ui/js/actions/search.js b/ui/js/actions/search.js index 149aa78ea..ab844df03 100644 --- a/ui/js/actions/search.js +++ b/ui/js/actions/search.js @@ -1,35 +1,28 @@ -import * as types from 'constants/action_types' -import lbryuri from 'lbryuri' -import lighthouse from 'lighthouse' -import { - doResolveUri, -} from 'actions/content' -import { - doNavigate, - doHistoryPush -} from 'actions/app' -import { - selectCurrentPage, -} from 'selectors/app' +import * as types from "constants/action_types"; +import lbryuri from "lbryuri"; +import lighthouse from "lighthouse"; +import { doResolveUri } from "actions/content"; +import { doNavigate, doHistoryPush } from "actions/app"; +import { selectCurrentPage } from "selectors/app"; export function doSearch(query) { return function(dispatch, getState) { - const state = getState() - const page = selectCurrentPage(state) + const state = getState(); + const page = selectCurrentPage(state); if (!query) { return dispatch({ type: types.SEARCH_CANCELLED, - }) + }); } dispatch({ type: types.SEARCH_STARTED, - data: { query } - }) + data: { query }, + }); - if(page != 'search') { - dispatch(doNavigate('search', { query: query })) + if (page != "search") { + dispatch(doNavigate("search", { query: query })); } else { lighthouse.search(query).then(results => { results.forEach(result => { @@ -37,18 +30,18 @@ export function doSearch(query) { channelName: result.channel_name, contentName: result.name, claimId: result.channel_id || result.claim_id, - }) - dispatch(doResolveUri(uri)) - }) + }); + dispatch(doResolveUri(uri)); + }); dispatch({ type: types.SEARCH_COMPLETED, data: { query, results, - } - }) - }) + }, + }); + }); } - } + }; } diff --git a/ui/js/actions/settings.js b/ui/js/actions/settings.js index a0742d377..8268989d8 100644 --- a/ui/js/actions/settings.js +++ b/ui/js/actions/settings.js @@ -1,31 +1,31 @@ -import * as types from 'constants/action_types' -import lbry from 'lbry' +import * as types from "constants/action_types"; +import lbry from "lbry"; export function doFetchDaemonSettings() { return function(dispatch, getState) { - lbry.settings_get().then((settings) => { + lbry.settings_get().then(settings => { dispatch({ type: types.DAEMON_SETTINGS_RECEIVED, data: { - settings - } - }) - }) - } + settings, + }, + }); + }); + }; } export function doSetDaemonSetting(key, value) { return function(dispatch, getState) { let settings = {}; settings[key] = value; - lbry.settings_set(settings).then(settings) - lbry.settings_get().then((settings) => { + lbry.settings_set(settings).then(settings); + lbry.settings_get().then(settings => { dispatch({ type: types.DAEMON_SETTINGS_RECEIVED, data: { - settings - } - }) - }) - } -} \ No newline at end of file + settings, + }, + }); + }); + }; +} diff --git a/ui/js/actions/wallet.js b/ui/js/actions/wallet.js index 53eccfa67..def93cf68 100644 --- a/ui/js/actions/wallet.js +++ b/ui/js/actions/wallet.js @@ -1,125 +1,127 @@ -import * as types from 'constants/action_types' -import lbry from 'lbry' +import * as types from "constants/action_types"; +import lbry from "lbry"; import { selectDraftTransaction, selectDraftTransactionAmount, selectBalance, -} from 'selectors/wallet' -import { - doOpenModal, -} from 'actions/app' +} from "selectors/wallet"; +import { doOpenModal } from "actions/app"; export function doUpdateBalance(balance) { return { type: types.UPDATE_BALANCE, data: { - balance: balance - } - } + balance: balance, + }, + }; } export function doFetchTransactions() { return function(dispatch, getState) { dispatch({ - type: types.FETCH_TRANSACTIONS_STARTED - }) + type: types.FETCH_TRANSACTIONS_STARTED, + }); - lbry.call('transaction_list', {}, (results) => { + lbry.call("transaction_list", {}, results => { dispatch({ type: types.FETCH_TRANSACTIONS_COMPLETED, data: { - transactions: results - } - }) - }) - } + transactions: results, + }, + }); + }); + }; } export function doGetNewAddress() { return function(dispatch, getState) { dispatch({ - type: types.GET_NEW_ADDRESS_STARTED - }) + type: types.GET_NEW_ADDRESS_STARTED, + }); lbry.wallet_new_address().then(function(address) { - localStorage.setItem('wallet_address', address); + localStorage.setItem("wallet_address", address); dispatch({ type: types.GET_NEW_ADDRESS_COMPLETED, - data: { address } - }) - }) - } + data: { address }, + }); + }); + }; } export function doCheckAddressIsMine(address) { return function(dispatch, getState) { dispatch({ - type: types.CHECK_ADDRESS_IS_MINE_STARTED - }) + type: types.CHECK_ADDRESS_IS_MINE_STARTED, + }); - lbry.checkAddressIsMine(address, (isMine) => { - if (!isMine) dispatch(doGetNewAddress()) + lbry.checkAddressIsMine(address, isMine => { + if (!isMine) dispatch(doGetNewAddress()); dispatch({ - type: types.CHECK_ADDRESS_IS_MINE_COMPLETED - }) - }) - } + type: types.CHECK_ADDRESS_IS_MINE_COMPLETED, + }); + }); + }; } export function doSendDraftTransaction() { return function(dispatch, getState) { - const state = getState() - const draftTx = selectDraftTransaction(state) - const balance = selectBalance(state) - const amount = selectDraftTransactionAmount(state) + const state = getState(); + const draftTx = selectDraftTransaction(state); + const balance = selectBalance(state); + const amount = selectDraftTransactionAmount(state); if (balance - amount < 1) { - return dispatch(doOpenModal('insufficientBalance')) + return dispatch(doOpenModal("insufficientBalance")); } dispatch({ type: types.SEND_TRANSACTION_STARTED, - }) + }); - const successCallback = (results) => { - if(results === true) { + const successCallback = results => { + if (results === true) { dispatch({ type: types.SEND_TRANSACTION_COMPLETED, - }) - dispatch(doOpenModal('transactionSuccessful')) - } - else { + }); + dispatch(doOpenModal("transactionSuccessful")); + } else { dispatch({ type: types.SEND_TRANSACTION_FAILED, - data: { error: results } - }) - dispatch(doOpenModal('transactionFailed')) + data: { error: results }, + }); + dispatch(doOpenModal("transactionFailed")); } - } + }; - const errorCallback = (error) => { + const errorCallback = error => { dispatch({ type: types.SEND_TRANSACTION_FAILED, - data: { error: error.message } - }) - dispatch(doOpenModal('transactionFailed')) - } + data: { error: error.message }, + }); + dispatch(doOpenModal("transactionFailed")); + }; - lbry.sendToAddress(draftTx.amount, draftTx.address, successCallback, errorCallback); - } + lbry.sendToAddress( + draftTx.amount, + draftTx.address, + successCallback, + errorCallback + ); + }; } export function doSetDraftTransactionAmount(amount) { return { type: types.SET_DRAFT_TRANSACTION_AMOUNT, - data: { amount } - } + data: { amount }, + }; } export function doSetDraftTransactionAddress(address) { return { type: types.SET_DRAFT_TRANSACTION_ADDRESS, - data: { address } - } + data: { address }, + }; } diff --git a/ui/js/app.js b/ui/js/app.js index 2f94dc302..1f1f32ecd 100644 --- a/ui/js/app.js +++ b/ui/js/app.js @@ -3,20 +3,26 @@ import lbry from './lbry.js'; const env = ENV; const config = require(`./config/${env}`); -const language = lbry.getClientSetting('language') ? lbry.getClientSetting('language') : 'en'; -const i18n = require('y18n')({directory: 'app/locales', updateFiles: false, locale: language}); +const language = lbry.getClientSetting('language') + ? lbry.getClientSetting('language') + : 'en'; +const i18n = require('y18n')({ + directory: 'app/locales', + updateFiles: false, + locale: language +}); const logs = []; const app = { - env: env, - config: config, - store: store, - i18n: i18n, - logs: logs, - log: function(message) { - console.log(message); - logs.push(message); - } -} + env: env, + config: config, + store: store, + i18n: i18n, + logs: logs, + log: function(message) { + console.log(message); + logs.push(message); + } +}; window.__ = i18n.__; window.__n = i18n.__n; diff --git a/ui/js/component/app/index.js b/ui/js/component/app/index.js index 5de84e28f..4c966cb56 100644 --- a/ui/js/component/app/index.js +++ b/ui/js/component/app/index.js @@ -1,26 +1,19 @@ -import React from 'react'; -import { connect } from 'react-redux' +import React from "react"; +import { connect } from "react-redux"; -import { - selectCurrentModal, -} from 'selectors/app' -import { - doCheckUpgradeAvailable, - doAlertError, -} from 'actions/app' -import { - doUpdateBalance, -} from 'actions/wallet' -import App from './view' +import { selectCurrentModal } from "selectors/app"; +import { doCheckUpgradeAvailable, doAlertError } from "actions/app"; +import { doUpdateBalance } from "actions/wallet"; +import App from "./view"; -const select = (state) => ({ +const select = state => ({ modal: selectCurrentModal(state), -}) +}); -const perform = (dispatch) => ({ - alertError: (errorList) => dispatch(doAlertError(errorList)), +const perform = dispatch => ({ + alertError: errorList => dispatch(doAlertError(errorList)), checkUpgradeAvailable: () => dispatch(doCheckUpgradeAvailable()), - updateBalance: (balance) => dispatch(doUpdateBalance(balance)) -}) + updateBalance: balance => dispatch(doUpdateBalance(balance)), +}); -export default connect(select, perform)(App) +export default connect(select, perform)(App); diff --git a/ui/js/component/app/view.jsx b/ui/js/component/app/view.jsx index 1c7ff4eb4..176c04785 100644 --- a/ui/js/component/app/view.jsx +++ b/ui/js/component/app/view.jsx @@ -1,42 +1,42 @@ -import React from 'react' -import Router from 'component/router' -import Header from 'component/header'; -import ErrorModal from 'component/errorModal' -import DownloadingModal from 'component/downloadingModal' -import UpgradeModal from 'component/upgradeModal' -import lbry from 'lbry' -import {Line} from 'rc-progress' +import React from "react"; +import Router from "component/router"; +import Header from "component/header"; +import ErrorModal from "component/errorModal"; +import DownloadingModal from "component/downloadingModal"; +import UpgradeModal from "component/upgradeModal"; +import lbry from "lbry"; +import { Line } from "rc-progress"; class App extends React.Component { componentWillMount() { - document.addEventListener('unhandledError', (event) => { + document.addEventListener("unhandledError", event => { this.props.alertError(event.detail); }); if (!this.props.upgradeSkipped) { - this.props.checkUpgradeAvailable() + this.props.checkUpgradeAvailable(); } - lbry.balanceSubscribe((balance) => { - this.props.updateBalance(balance) - }) + lbry.balanceSubscribe(balance => { + this.props.updateBalance(balance); + }); } render() { - const { - modal, - } = this.props + const { modal } = this.props; - return
{__("Using LBRY is like dating a centaur. Totally normal up top, and way different underneath.")}
++ {__( + "Using LBRY is like dating a centaur. Totally normal up top, and way different underneath." + )} +
{__("Up top, LBRY is similar to popular media sites.")}
-{__("Below, LBRY is controlled by users -- you -- via blockchain and decentralization.")}
-{__("Thank you for making content freedom possible! Here's a nickel, kid.")}
-+ {__( + "Below, LBRY is controlled by users -- you -- via blockchain and decentralization." + )} +
++ {__( + "Thank you for making content freedom possible! Here's a nickel, kid." + )} +
+{__("You earned a reward of ")}
{__("This reward will show in your Wallet momentarily, probably while you are reading this message.")}
-{__("LBC is used to compensate creators, to publish, and to have say in how the network works.")}
-{__("No need to understand it all just yet! Try watching or downloading something next.")}
-{__("Finally, know that LBRY is an early beta and that it earns the name.")}
+
+ {__("You earned a reward of ")}
+ {" "}
+
+ {__( + "This reward will show in your Wallet momentarily, probably while you are reading this message." + )} +
++ {__( + "LBC is used to compensate creators, to publish, and to have say in how the network works." + )} +
++ {__( + "No need to understand it all just yet! Try watching or downloading something next." + )} +
++ {__( + "Finally, know that LBRY is an early beta and that it earns the name." + )} +
{__("An error was encountered that we cannot continue from.")}
-{__("At least we're earning the name beta.")}
- { props.errorText ?{__("Message:")} {props.errorText}
: '' } - { window.location.reload() } } /> -{__("Preparing for first access")}
-{__("An error was encountered that we cannot continue from.")}
+{__("At least we're earning the name beta.")}
+ {props.errorText ?{__("Message:")} {props.errorText}
: ""} + { + window.location.reload(); + }} + /> ++ {__("Preparing for first access")} +
+{__("Access to LBRY is restricted as we build and scale the network.")}
++ {__( + "Access to LBRY is restricted as we build and scale the network." + )} +
{__("There are two ways in:")}
{__("If you own at least 1 LBC, you can get in right now.")}
-{ setLocal('auth_bypassed', true); this.props.setStage(null); }} - disabled={disabled} label={__("Let Me In")} button={ disabled ? "alt" : "primary" } />
-{__("Your balance is ")}
+ { + setLocal("auth_bypassed", true); + this.props.setStage(null); + }} + disabled={disabled} + label={__("Let Me In")} + button={disabled ? "alt" : "primary"} + /> +
+
+ {__("Your balance is ")}
+
+{__("If you don't understand how to send credits, then...")}
{__("If you provide your email, you'll automatically receive a notification when the system is open.")}
-{ this.props.setStage("email"); }} label={__("Return")} />
++ {__( + "If you provide your email, you'll automatically receive a notification when the system is open." + )} +
++ { + this.props.setStage("email"); + }} + label={__("Return")} + /> +
{__("Click \"Begin Upgrade\" to start the upgrade process.")}
-{__("The app will close, and you will be prompted to install the latest version of LBRY.")}
-{__("After the install is complete, please reopen the app.")}
-{__('Click "Begin Upgrade" to start the upgrade process.')}
++ {__( + "The app will close, and you will be prompted to install the latest version of LBRY." + )} +
++ {__("After the install is complete, please reopen the app.")} +
+{val}
{val}
{__("We're sorry that LBRY has encountered an error. This has been reported and we will investigate the problem.")}
++ {__( + "We're sorry that LBRY has encountered an error. This has been reported and we will investigate the problem." + )} +
{__("Are you sure you'd like to remove")} {title} {__("from LBRY?")}
++ {__("Are you sure you'd like to remove")} {title} + {" "}{__("from LBRY?")} +
- +- {__("This content is Not Safe For Work. To view adult content, please change your")} navigate('settings')} label={__("Settings")} />. -
-+ {__( + "This content is Not Safe For Work. To view adult content, please change your" + )} + {" "} + navigate("settings")} + label={__("Settings")} + />. +
+- {__("This content is Not Safe For Work. To view adult content, please change your")} navigate('/settings')} label={__("Settings")} />. -
-+ {__( + "This content is Not Safe For Work. To view adult content, please change your" + )} + {" "} + navigate("/settings")} + label={__("Settings")} + />. +
+{__("Your file has been published to LBRY at the address")} lbry://{this.state.name}
!
{__('The file will take a few minutes to appear for other LBRY users. Until then it will be listed as "pending" under your published files.')}
+
+ {__("Your file has been published to LBRY at the address")}
+ {" "}lbry://{this.state.name}
!
+
+ {__( + 'The file will take a few minutes to appear for other LBRY users. Until then it will be listed as "pending" under your published files.' + )} +
{__("Please describe the problem you experienced and any information you think might be useful to us. Links to screenshots are great!")}
++ {__( + "Please describe the problem you experienced and any information you think might be useful to us. Links to screenshots are great!" + )} +