Apply ESLint auto fixing

This commit is contained in:
Igor Gassmann 2017-12-13 18:36:30 -03:00
parent 040b57352f
commit a40aecfb68
64 changed files with 729 additions and 722 deletions

View file

@ -1,52 +1,63 @@
// Module imports
const {app, BrowserWindow, ipcMain, Menu, Tray, globalShortcut} = require('electron');
const path = require('path');
const url = require('url');
const jayson = require('jayson');
const semver = require('semver');
const https = require('https');
const keytar = require('keytar');
const {
app,
BrowserWindow,
ipcMain,
Menu,
Tray,
globalShortcut,
} = require("electron");
const path = require("path");
const url = require("url");
const jayson = require("jayson");
const semver = require("semver");
const https = require("https");
const keytar = require("keytar");
// tree-kill has better cross-platform handling of
// killing a process. child-process.kill was unreliable
const kill = require('tree-kill');
const child_process = require('child_process');
const assert = require('assert');
const kill = require("tree-kill");
const child_process = require("child_process");
const assert = require("assert");
const localVersion = app.getVersion();
const setMenu = require('./menu/main-menu.js');
export const contextMenu = require('./menu/context-menu');
const setMenu = require("./menu/main-menu.js");
export const contextMenu = require("./menu/context-menu");
// Debug configs
const isDevelopment = process.env.NODE_ENV === 'development';
const isDevelopment = process.env.NODE_ENV === "development";
if (isDevelopment) {
try
{
const { default: installExtension, REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS } = require('electron-devtools-installer');
app.on('ready', () => {
try {
const {
default: installExtension,
REACT_DEVELOPER_TOOLS,
REDUX_DEVTOOLS,
} = require("electron-devtools-installer");
app.on("ready", () => {
[REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS].forEach(extension => {
installExtension(extension)
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.log('An error occurred: ', err));
.then(name => console.log(`Added Extension: ${name}`))
.catch(err => console.log("An error occurred: ", err));
});
});
}
catch (err)
{
console.error(err)
} catch (err) {
console.error(err);
}
}
// Misc constants
const LATEST_RELEASE_API_URL = 'https://api.github.com/repos/lbryio/lbry-app/releases/latest';
const DAEMON_PATH = process.env.LBRY_DAEMON || path.join(__static, 'daemon/lbrynet-daemon');
const LATEST_RELEASE_API_URL =
"https://api.github.com/repos/lbryio/lbry-app/releases/latest";
const DAEMON_PATH =
process.env.LBRY_DAEMON || path.join(__static, "daemon/lbrynet-daemon");
const rendererUrl = isDevelopment
? `http://localhost:${process.env.ELECTRON_WEBPACK_WDS_PORT}`
: `file://${__dirname}/index.html`;
let client = jayson.client.http({
host: 'localhost',
const client = jayson.client.http({
host: "localhost",
port: 5279,
path: '/',
timeout: 1000
path: "/",
timeout: 1000,
});
// Keep a global reference of the window object, if you don't, the window will
@ -84,11 +95,10 @@ function processRequestedUri(uri) {
// lbry://channel/#claimid. We remove the slash here as well.
// On Linux and Mac, we just return the URI as given.
if (process.platform === 'win32') {
return uri.replace(/\/$/, '').replace('/#', '#');
} else {
return uri;
if (process.platform === "win32") {
return uri.replace(/\/$/, "").replace("/#", "#");
}
return uri;
}
/*
@ -97,69 +107,85 @@ function processRequestedUri(uri) {
* when no windows are open.
*/
function openItem(fullPath) {
const subprocOptions = {
detached: true,
stdio: 'ignore',
};
const subprocOptions = {
detached: true,
stdio: "ignore",
};
let child;
if (process.platform === 'darwin') {
child = child_process.spawn('open', [fullPath], subprocOptions);
} else if (process.platform === 'linux') {
child = child_process.spawn('xdg-open', [fullPath], subprocOptions);
} else if (process.platform === 'win32') {
child = child_process.spawn(fullPath, Object.assign({}, subprocOptions, {shell: true}));
}
let child;
if (process.platform === "darwin") {
child = child_process.spawn("open", [fullPath], subprocOptions);
} else if (process.platform === "linux") {
child = child_process.spawn("xdg-open", [fullPath], subprocOptions);
} else if (process.platform === "win32") {
child = child_process.spawn(
fullPath,
Object.assign({}, subprocOptions, { shell: true })
);
}
// Causes child process reference to be garbage collected, allowing main process to exit
child.unref();
// Causes child process reference to be garbage collected, allowing main process to exit
child.unref();
}
function getPidsForProcessName(name) {
if (process.platform === 'win32') {
const tasklistOut = child_process.execSync(`tasklist /fi "Imagename eq ${name}.exe" /nh`, {encoding: 'utf8'});
if (tasklistOut.startsWith('INFO')) {
if (process.platform === "win32") {
const tasklistOut = child_process.execSync(
`tasklist /fi "Imagename eq ${name}.exe" /nh`,
{ encoding: "utf8" }
);
if (tasklistOut.startsWith("INFO")) {
return [];
} else {
return tasklistOut.match(/[^\r\n]+/g).map((line) => line.split(/\s+/)[1]); // Second column of every non-empty line
}
} else {
const pgrepOut = child_process.spawnSync('pgrep', ['-x', name], {encoding: 'utf8'}).stdout;
return pgrepOut.match(/\d+/g);
return tasklistOut.match(/[^\r\n]+/g).map(line => line.split(/\s+/)[1]); // Second column of every non-empty line
}
const pgrepOut = child_process.spawnSync("pgrep", ["-x", name], {
encoding: "utf8",
}).stdout;
return pgrepOut.match(/\d+/g);
}
function createWindow () {
function createWindow() {
// Disable renderer process's webSecurity on development to enable CORS.
win = isDevelopment
? new BrowserWindow({backgroundColor: '#155B4A', minWidth: 800, minHeight: 600, webPreferences: {webSecurity: false}})
: new BrowserWindow({backgroundColor: '#155B4A', minWidth: 800, minHeight: 600});
? new BrowserWindow({
backgroundColor: "#155B4A",
minWidth: 800,
minHeight: 600,
webPreferences: { webSecurity: false },
})
: new BrowserWindow({
backgroundColor: "#155B4A",
minWidth: 800,
minHeight: 600,
});
win.webContents.session.setUserAgent(`LBRY/${localVersion}`);
win.maximize()
win.maximize();
if (isDevelopment) {
win.webContents.openDevTools();
}
win.loadURL(rendererUrl)
if (openUri) { // We stored and received a URI that an external app requested before we had a window object
win.webContents.on('did-finish-load', () => {
win.webContents.send('open-uri-requested', openUri);
win.loadURL(rendererUrl);
if (openUri) {
// We stored and received a URI that an external app requested before we had a window object
win.webContents.on("did-finish-load", () => {
win.webContents.send("open-uri-requested", openUri);
});
}
win.removeAllListeners();
win.on('close', function(event) {
win.on("close", event => {
if (minimize) {
event.preventDefault();
win.hide();
}
})
});
win.on('closed', () => {
win = null
})
win.on("closed", () => {
win = null;
});
win.on("hide", () => {
// Checks what to show in the tray icon menu
@ -176,7 +202,7 @@ function createWindow () {
if (minimize) updateTray();
// Unregisters Alt+F4 shortcut
globalShortcut.unregister('Alt+F4');
globalShortcut.unregister("Alt+F4");
});
win.on("focus", () => {
@ -184,23 +210,22 @@ function createWindow () {
if (minimize) updateTray();
// Registers shortcut for closing(quitting) the app
globalShortcut.register('Alt+F4', () => safeQuit());
globalShortcut.register("Alt+F4", () => safeQuit());
win.webContents.send('window-is-focused', null);
win.webContents.send("window-is-focused", null);
});
// Menu bar
win.setAutoHideMenuBar(true);
win.setMenuBarVisibility(isDevelopment);
setMenu();
}
};
function createTray () {
function createTray() {
// Minimize to tray logic follows:
// Set the tray icon
let iconPath;
if (process.platform === 'darwin') {
if (process.platform === "darwin") {
// Using @2x for mac retina screens so the icon isn't blurry
// file name needs to include "Template" at the end for dark menu bar
iconPath = path.join(__static, "/img/fav/macTemplate@2x.png");
@ -211,14 +236,14 @@ function createTray () {
tray = new Tray(iconPath);
tray.setToolTip("LBRY App");
tray.setTitle("LBRY");
tray.on('double-click', () => {
win.show()
})
tray.on("double-click", () => {
win.show();
});
}
// This needs to be done as for linux the context menu doesn't update automatically(docs)
function updateTray() {
let contextMenu = Menu.buildFromTemplate(getMenuTemplate());
const contextMenu = Menu.buildFromTemplate(getMenuTemplate());
if (tray) {
tray.setContextMenu(contextMenu);
} else {
@ -226,28 +251,26 @@ function updateTray() {
}
}
function getMenuTemplate () {
function getMenuTemplate() {
return [
getToggleItem(),
{
label: "Quit",
click: () => safeQuit(),
},
]
];
function getToggleItem () {
function getToggleItem() {
if (win.isVisible() && win.isFocused()) {
return {
label: 'Hide LBRY App',
click: () => win.hide()
}
} else {
return {
label: 'Show LBRY App',
click: () => win.show()
}
label: "Hide LBRY App",
click: () => win.hide(),
};
}
return {
label: "Show LBRY App",
click: () => win.show(),
};
}
}
@ -256,20 +279,19 @@ function handleOpenUriRequested(uri) {
// Window not created yet, so store up requested URI for when it is
openUri = processRequestedUri(uri);
} else {
if (win.isMinimized()) {
win.restore()
win.restore();
} else if (!win.isVisible()) {
win.show()
win.show();
}
win.focus();
win.webContents.send('open-uri-requested', processRequestedUri(uri));
win.webContents.send("open-uri-requested", processRequestedUri(uri));
}
}
function handleDaemonSubprocessExited() {
console.log('The daemon has exited.');
console.log("The daemon has exited.");
daemonSubprocess = null;
if (!daemonStopRequested) {
// We didn't request to stop the daemon, so display a
@ -277,27 +299,31 @@ function handleDaemonSubprocessExited() {
//
// TODO: maybe it would be better to restart the daemon?
if (win) {
console.log('Did not request daemon stop, so quitting in 5 seconds.');
console.log("Did not request daemon stop, so quitting in 5 seconds.");
win.loadURL(`file://${__static}/warning.html`);
setTimeout(quitNow, 5000);
} else {
console.log('Did not request daemon stop, so quitting.');
console.log("Did not request daemon stop, so quitting.");
quitNow();
}
}
}
function launchDaemon() {
assert(!daemonSubprocess, 'Tried to launch daemon twice');
assert(!daemonSubprocess, "Tried to launch daemon twice");
console.log('Launching daemon:', DAEMON_PATH)
daemonSubprocess = child_process.spawn(DAEMON_PATH)
console.log("Launching daemon:", DAEMON_PATH);
daemonSubprocess = child_process.spawn(DAEMON_PATH);
// Need to handle the data event instead of attaching to
// process.stdout because the latter doesn't work. I believe on
// windows it buffers stdout and we don't get any meaningful output
daemonSubprocess.stdout.on('data', (buf) => {console.log(String(buf).trim());});
daemonSubprocess.stderr.on('data', (buf) => {console.log(String(buf).trim());});
daemonSubprocess.on('exit', handleDaemonSubprocessExited);
daemonSubprocess.stdout.on("data", buf => {
console.log(String(buf).trim());
});
daemonSubprocess.stderr.on("data", buf => {
console.log(String(buf).trim());
});
daemonSubprocess.on("exit", handleDaemonSubprocessExited);
}
/*
@ -318,7 +344,7 @@ function quitNow() {
safeQuit();
}
const isSecondaryInstance = app.makeSingleInstance((argv) => {
const isSecondaryInstance = app.makeSingleInstance(argv => {
if (argv.length >= 2) {
handleOpenUriRequested(argv[1]); // This will handle restoring and focusing the window
} else if (win) {
@ -331,25 +357,23 @@ const isSecondaryInstance = app.makeSingleInstance((argv) => {
}
});
if (isSecondaryInstance) { // We're not in the original process, so quit
if (isSecondaryInstance) {
// We're not in the original process, so quit
quitNow();
}
function launchDaemonIfNotRunning() {
// Check if the daemon is already running. If we get
// an error its because its not running
console.log('Checking for lbrynet daemon');
client.request(
'status', [],
function (err, res) {
if (err) {
console.log('lbrynet daemon needs to be launched')
launchDaemon();
} else {
console.log('lbrynet daemon is already running')
}
console.log("Checking for lbrynet daemon");
client.request("status", [], (err, res) => {
if (err) {
console.log("lbrynet daemon needs to be launched");
launchDaemon();
} else {
console.log("lbrynet daemon is already running");
}
);
});
}
/*
@ -358,21 +382,31 @@ function launchDaemonIfNotRunning() {
* tries to force kill them.
*/
function forceKillAllDaemonsAndQuit() {
console.log('Attempting to force kill any running lbrynet-daemon instances...');
console.log(
"Attempting to force kill any running lbrynet-daemon instances..."
);
const daemonPids = getPidsForProcessName('lbrynet-daemon');
const daemonPids = getPidsForProcessName("lbrynet-daemon");
if (!daemonPids) {
console.log('No lbrynet-daemon found running.');
console.log("No lbrynet-daemon found running.");
quitNow();
} else {
console.log(`Found ${daemonPids.length} running daemon instances. Attempting to force kill...`);
console.log(
`Found ${
daemonPids.length
} running daemon instances. Attempting to force kill...`
);
for (const pid of daemonPids) {
let daemonKillAttemptsComplete = 0;
kill(pid, 'SIGKILL', (err) => {
kill(pid, "SIGKILL", err => {
daemonKillAttemptsComplete++;
if (err) {
console.log(`Failed to force kill daemon task with pid ${pid}. Error message: ${err.message}`);
console.log(
`Failed to force kill daemon task with pid ${pid}. Error message: ${
err.message
}`
);
} else {
console.log(`Force killed daemon task with pid ${pid}.`);
}
@ -384,15 +418,15 @@ function forceKillAllDaemonsAndQuit() {
}
}
app.setAsDefaultProtocolClient('lbry');
app.setAsDefaultProtocolClient("lbry");
app.on('ready', function() {
app.on("ready", () => {
launchDaemonIfNotRunning();
if (process.platform === "linux") {
checkLinuxTraySupport( err => {
checkLinuxTraySupport(err => {
if (!err) createTray();
else minimize = false;
})
});
} else {
createTray();
}
@ -400,36 +434,35 @@ app.on('ready', function() {
});
// Quit when all windows are closed.
app.on('window-all-closed', () => {
app.on("window-all-closed", () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
if (process.platform !== "darwin") {
app.quit();
}
})
});
app.on('before-quit', (event) => {
app.on("before-quit", event => {
if (!readyToQuit) {
// We need to shutdown the daemon before we're ready to actually quit. This
// event will be triggered re-entrantly once preparation is done.
event.preventDefault();
shutdownDaemonAndQuit();
} else {
console.log('Quitting.')
console.log("Quitting.");
}
});
app.on('activate', () => {
app.on("activate", () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow()
createWindow();
}
});
if (process.platform === 'darwin') {
app.on('open-url', (event, uri) => {
if (process.platform === "darwin") {
app.on("open-url", (event, uri) => {
handleOpenUriRequested(uri);
});
} else if (process.argv.length >= 2) {
@ -440,14 +473,18 @@ if (process.platform === 'darwin') {
// then calls quitNow() to quit for real.
function shutdownDaemonAndQuit(evenIfNotStartedByApp = false) {
function doShutdown() {
console.log('Shutting down daemon');
console.log("Shutting down daemon");
daemonStopRequested = true;
client.request('daemon_stop', [], (err, res) => {
client.request("daemon_stop", [], (err, res) => {
if (err) {
console.log(`received error when stopping lbrynet-daemon. Error message: ${err.message}\n`);
console.log('You will need to manually kill the daemon.');
console.log(
`received error when stopping lbrynet-daemon. Error message: ${
err.message
}\n`
);
console.log("You will need to manually kill the daemon.");
} else {
console.log('Successfully stopped daemon via RPC call.')
console.log("Successfully stopped daemon via RPC call.");
quitNow();
}
});
@ -456,7 +493,7 @@ function shutdownDaemonAndQuit(evenIfNotStartedByApp = false) {
if (daemonSubprocess) {
doShutdown();
} else if (!evenIfNotStartedByApp) {
console.log('Not killing lbrynet-daemon because app did not start it');
console.log("Not killing lbrynet-daemon because app did not start it");
quitNow();
} else {
doShutdown();
@ -467,24 +504,27 @@ function shutdownDaemonAndQuit(evenIfNotStartedByApp = false) {
}
// Taken from webtorrent-desktop
function checkLinuxTraySupport (cb) {
function checkLinuxTraySupport(cb) {
// Check that we're on Ubuntu (or another debian system) and that we have
// libappindicator1.
child_process.exec('dpkg --get-selections libappindicator1', function (err, stdout) {
if (err) return cb(err)
// Unfortunately there's no cleaner way, as far as I can tell, to check
// whether a debian package is installed:
if (stdout.endsWith('\tinstall\n')) {
cb(null)
} else {
cb(new Error('debian package not installed'))
child_process.exec(
"dpkg --get-selections libappindicator1",
(err, stdout) => {
if (err) return cb(err);
// Unfortunately there's no cleaner way, as far as I can tell, to check
// whether a debian package is installed:
if (stdout.endsWith("\tinstall\n")) {
cb(null);
} else {
cb(new Error("debian package not installed"));
}
}
})
);
}
ipcMain.on('upgrade', (event, installerPath) => {
app.on('quit', () => {
console.log('Launching upgrade installer at', installerPath);
ipcMain.on("upgrade", (event, installerPath) => {
app.on("quit", () => {
console.log("Launching upgrade installer at", installerPath);
// This gets triggered called after *all* other quit-related events, so
// we'll only get here if we're fully prepared and quitting for real.
openItem(installerPath);
@ -497,58 +537,77 @@ ipcMain.on('upgrade', (event, installerPath) => {
shutdownDaemonAndQuit(true);
// wait for daemon to shut down before upgrading
// what to do if no shutdown in a long time?
console.log('Update downloaded to', installerPath);
console.log('The app will close, and you will be prompted to install the latest version of LBRY.');
console.log('After the install is complete, please reopen the app.');
console.log("Update downloaded to", installerPath);
console.log(
"The app will close, and you will be prompted to install the latest version of LBRY."
);
console.log("After the install is complete, please reopen the app.");
});
ipcMain.on('version-info-requested', () => {
ipcMain.on("version-info-requested", () => {
function formatRc(ver) {
// Adds dash if needed to make RC suffix semver friendly
return ver.replace(/([^-])rc/, '$1-rc');
return ver.replace(/([^-])rc/, "$1-rc");
}
let result = '';
let result = "";
const opts = {
headers: {
'User-Agent': `LBRY/${localVersion}`,
}
"User-Agent": `LBRY/${localVersion}`,
},
};
const req = https.get(Object.assign(opts, url.parse(LATEST_RELEASE_API_URL)), (res) => {
res.on('data', (data) => {
result += data;
});
res.on('end', () => {
const tagName = JSON.parse(result).tag_name;
const [_, remoteVersion] = tagName.match(/^v([\d.]+(?:-?rc\d+)?)$/);
if (!remoteVersion) {
if (win) {
win.webContents.send('version-info-received', null);
const req = https.get(
Object.assign(opts, url.parse(LATEST_RELEASE_API_URL)),
res => {
res.on("data", data => {
result += data;
});
res.on("end", () => {
const tagName = JSON.parse(result).tag_name;
const [_, remoteVersion] = tagName.match(/^v([\d.]+(?:-?rc\d+)?)$/);
if (!remoteVersion) {
if (win) {
win.webContents.send("version-info-received", null);
}
} else {
const upgradeAvailable = semver.gt(
formatRc(remoteVersion),
formatRc(localVersion)
);
if (win) {
win.webContents.send("version-info-received", {
remoteVersion,
localVersion,
upgradeAvailable,
});
}
}
} else {
const upgradeAvailable = semver.gt(formatRc(remoteVersion), formatRc(localVersion));
if (win) {
win.webContents.send('version-info-received', {remoteVersion, localVersion, upgradeAvailable});
}
}
})
});
});
}
);
req.on('error', (err) => {
console.log('Failed to get current version from GitHub. Error:', err);
req.on("error", err => {
console.log("Failed to get current version from GitHub. Error:", err);
if (win) {
win.webContents.send('version-info-received', null);
win.webContents.send("version-info-received", null);
}
});
});
ipcMain.on('get-auth-token', (event) => {
ipcMain.on("get-auth-token", event => {
keytar.getPassword("LBRY", "auth_token").then(token => {
event.sender.send('auth-token-response', token ? token.toString().trim() : null)
event.sender.send(
"auth-token-response",
token ? token.toString().trim() : null
);
});
});
ipcMain.on('set-auth-token', (event, token) => {
keytar.setPassword("LBRY", "auth_token", token ? token.toString().trim() : null);
ipcMain.on("set-auth-token", (event, token) => {
keytar.setPassword(
"LBRY",
"auth_token",
token ? token.toString().trim() : null
);
});

View file

@ -1,34 +1,33 @@
const {Menu} = require('electron');
const electron = require('electron');
const { Menu } = require("electron");
const electron = require("electron");
const app = electron.app;
const contextMenuTemplate = [
{
role: 'cut',
role: "cut",
},
{
role: 'copy',
role: "copy",
},
{
role: 'paste',
role: "paste",
},
];
module.exports = {
showContextMenu(win, posX, posY, showDevItems) {
let template = contextMenuTemplate.slice();
const template = contextMenuTemplate.slice();
if (showDevItems) {
template.push({
type: 'separator',
type: "separator",
});
template.push({
label: "Inspect Element",
click() {
win.inspectElement(posX, posY);
},
});
template.push(
{
label: 'Inspect Element',
click() {
win.inspectElement(posX, posY);
}
}
);
}
Menu.buildFromTemplate(template).popup(win);

View file

@ -1,136 +1,136 @@
const { app, shell, Menu } = require('electron');
const { safeQuit } = require('../index.js');
const { app, shell, Menu } = require("electron");
const { safeQuit } = require("../index.js");
const baseTemplate = [
{
label: 'File',
label: "File",
submenu: [
{
label: 'Quit',
label: "Quit",
accelerator: "CommandOrControl+Q",
click: () => safeQuit(),
},
]
],
},
{
label: 'Edit',
label: "Edit",
submenu: [
{
role: 'undo',
role: "undo",
},
{
role: 'redo',
role: "redo",
},
{
type: 'separator',
type: "separator",
},
{
role: 'cut',
role: "cut",
},
{
role: 'copy',
role: "copy",
},
{
role: 'paste',
role: "paste",
},
{
role: 'selectall',
role: "selectall",
},
]
],
},
{
label: 'View',
label: "View",
submenu: [
{
role: 'reload'
role: "reload",
},
{
label: 'Developer',
label: "Developer",
submenu: [
{
role: 'forcereload'
role: "forcereload",
},
{
role: 'toggledevtools'
role: "toggledevtools",
},
]
],
},
{
type: 'separator'
type: "separator",
},
{
role: 'togglefullscreen'
}
]
role: "togglefullscreen",
},
],
},
{
role: 'help',
role: "help",
submenu: [
{
label: 'Learn More',
label: "Learn More",
click(item, focusedWindow) {
if (focusedWindow) {
focusedWindow.webContents.send('open-menu', '/help');
focusedWindow.webContents.send("open-menu", "/help");
}
}
},
},
{
label: 'Frequently Asked Questions',
click(item, focusedWindow){
shell.openExternal('https://lbry.io/faq')
}
label: "Frequently Asked Questions",
click(item, focusedWindow) {
shell.openExternal("https://lbry.io/faq");
},
},
{
type: 'separator'
type: "separator",
},
{
label: 'Report Issue',
click(item, focusedWindow){
shell.openExternal('https://lbry.io/faq/contributing#report-a-bug');
}
label: "Report Issue",
click(item, focusedWindow) {
shell.openExternal("https://lbry.io/faq/contributing#report-a-bug");
},
},
{
type: 'separator'
type: "separator",
},
{
label: 'Developer API Guide',
click(item, focusedWindow){
shell.openExternal('https://lbry.io/quickstart')
}
label: "Developer API Guide",
click(item, focusedWindow) {
shell.openExternal("https://lbry.io/quickstart");
},
},
]
}
],
},
];
const macOSAppMenuTemplate = {
label: app.getName(),
submenu: [
{
role: 'about',
role: "about",
},
{
type: 'separator',
type: "separator",
},
{
role: 'hide',
role: "hide",
},
{
role: 'hideothers',
role: "hideothers",
},
{
role: 'unhide',
role: "unhide",
},
{
type: 'separator',
type: "separator",
},
{
role: 'quit',
role: "quit",
},
]
],
};
module.exports = () => {
let template = baseTemplate.slice();
(process.platform === 'darwin') && template.unshift(macOSAppMenuTemplate);
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
const template = baseTemplate.slice();
process.platform === "darwin" && template.unshift(macOSAppMenuTemplate);
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
};

View file

@ -6,18 +6,19 @@ const config = {
...require(`./config/${env}`),
};
const i18n = require("y18n")({
directory: remote.app.getAppPath() + "/locales",
directory: `${remote.app.getAppPath()}/locales`,
updateFiles: false,
locale: "en",
});
const logs = [];
const app = {
env: env,
config: config,
store: store,
i18n: i18n,
logs: logs,
log: function(message) {
env,
config,
store,
i18n,
logs,
log(message) {
logs.push(message);
},
};

View file

@ -3,7 +3,7 @@ import PropTypes from "prop-types";
import { formatCredits, formatFullPrice } from "util/formatCredits";
import lbry from "../lbry.js";
//component/icon.js
// component/icon.js
export class Icon extends React.PureComponent {
static propTypes = {
icon: PropTypes.string.isRequired,
@ -13,12 +13,9 @@ export class Icon extends React.PureComponent {
render() {
const { fixed, className } = this.props;
const spanClassName =
"icon " +
("fixed" in this.props ? "icon-fixed-width " : "") +
this.props.icon +
" " +
(this.props.className || "");
const spanClassName = `icon ${
"fixed" in this.props ? "icon-fixed-width " : ""
}${this.props.icon} ${this.props.className || ""}`;
return <span className={spanClassName} />;
}
}
@ -90,14 +87,14 @@ export class CreditAmount extends React.PureComponent {
const { amount, precision, showFullPrice } = this.props;
let formattedAmount;
let fullPrice = formatFullPrice(amount, 2);
const fullPrice = formatFullPrice(amount, 2);
if (showFullPrice) {
formattedAmount = fullPrice;
} else {
formattedAmount =
amount > 0 && amount < minimumRenderableAmount
? "<" + minimumRenderableAmount
? `<${minimumRenderableAmount}`
: formatCredits(amount, precision);
}
@ -111,12 +108,12 @@ export class CreditAmount extends React.PureComponent {
? this.props.label
: parseFloat(amount) == 1 ? __("credit") : __("credits");
amountText = formattedAmount + " " + label;
amountText = `${formattedAmount} ${label}`;
} else {
amountText = formattedAmount;
}
if (this.props.showPlus && amount > 0) {
amountText = "+" + amountText;
amountText = `+${amountText}`;
}
}

View file

@ -2,6 +2,7 @@ import React from "react";
import PropTypes from "prop-types";
const { remote } = require("electron");
class FileSelector extends React.PureComponent {
static propTypes = {
type: PropTypes.oneOf(["file", "directory"]),
@ -40,7 +41,7 @@ class FileSelector extends React.PureComponent {
const path = paths[0];
this.setState({
path: path,
path,
});
if (this.props.onFileChosen) {
this.props.onFileChosen(path);

View file

@ -8,7 +8,7 @@ import FileActions from "./view";
const select = (state, props) => ({
fileInfo: makeSelectFileInfoForUri(props.uri)(state),
/*availability check is disabled due to poor performance, TBD if it dies forever or requires daemon fix*/
/* availability check is disabled due to poor performance, TBD if it dies forever or requires daemon fix */
costInfo: makeSelectCostInfoForUri(props.uri)(state),
claimIsMine: makeSelectClaimIsMine(props.uri)(state),
});

View file

@ -13,7 +13,7 @@ import FileDownloadLink from "./view";
const select = (state, props) => ({
fileInfo: makeSelectFileInfoForUri(props.uri)(state),
/*availability check is disabled due to poor performance, TBD if it dies forever or requires daemon fix*/
/* availability check is disabled due to poor performance, TBD if it dies forever or requires daemon fix */
downloading: makeSelectDownloadingForUri(props.uri)(state),
costInfo: makeSelectCostInfoForUri(props.uri)(state),
loading: makeSelectLoadingForUri(props.uri)(state),

View file

@ -8,7 +8,7 @@ let formFieldCounter = 0;
export const formFieldNestedLabelTypes = ["radio", "checkbox"];
export function formFieldId() {
return "form-field-" + ++formFieldCounter;
return `form-field-${++formFieldCounter}`;
}
export class Form extends React.PureComponent {
@ -129,21 +129,19 @@ export class FormRow extends React.PureComponent {
return (
<div
className={"form-row" + (this.state.isFocus ? " form-row--focus" : "")}
className={`form-row${this.state.isFocus ? " form-row--focus" : ""}`}
>
{this.props.label && !renderLabelInFormField ? (
<div
className={
"form-row__label-row " +
(this.props.labelPrefix ? "form-row__label-row--prefix" : "")
}
className={`form-row__label-row ${
this.props.labelPrefix ? "form-row__label-row--prefix" : ""
}`}
>
<label
htmlFor={elementId}
className={
"form-field__label " +
(this.state.isError ? "form-field__label--error" : " ")
}
className={`form-field__label ${
this.state.isError ? "form-field__label--error" : " "
}`}
>
{this.props.label}
</label>
@ -178,16 +176,14 @@ export class FormRow extends React.PureComponent {
export const Submit = props => {
const { title, label, icon, disabled } = props;
const className =
"button-block" +
const className = `${"button-block" +
" button-primary" +
" button-set-item" +
" button--submit" +
(disabled ? " disabled" : "");
" button--submit"}${disabled ? " disabled" : ""}`;
const content = (
<span className="button__content">
{"icon" in props ? <Icon icon={icon} fixed={true} /> : null}
{"icon" in props ? <Icon icon={icon} fixed /> : null}
{label ? <span className="button-label">{label}</span> : null}
</span>
);

View file

@ -37,15 +37,14 @@ class LoadScreen extends React.PureComponent {
) : (
<span>
<Icon icon="icon-warning" />
{" " + this.props.message}
{` ${this.props.message}`}
</span>
)}
</h3>
<span
className={
"load-screen__details " +
(this.props.isWarning ? "load-screen__details--warning" : "")
}
className={`load-screen__details ${
this.props.isWarning ? "load-screen__details--warning" : ""
}`}
>
{this.props.details}
</span>

View file

@ -16,7 +16,7 @@ export class DropDownMenuItem extends React.PureComponent {
};
render() {
var icon = this.props.icon ? <Icon icon={this.props.icon} fixed /> : null;
const icon = this.props.icon ? <Icon icon={this.props.icon} fixed /> : null;
return (
<a
@ -70,7 +70,7 @@ export class DropDownMenu extends React.PureComponent {
});
}
/*this will force "this" to always be the class, even when passed to an event listener*/
/* this will force "this" to always be the class, even when passed to an event listener */
handleWindowClick = e => {
if (
this.state.menuOpen &&

View file

@ -8,12 +8,10 @@ import {
import { doCheckDaemonVersion } from "redux/actions/app";
import SplashScreen from "./view";
const select = state => {
return {
modal: selectCurrentModal(state),
daemonVersionMatched: selectDaemonVersionMatched(state),
};
};
const select = state => ({
modal: selectCurrentModal(state),
daemonVersionMatched: selectDaemonVersionMatched(state),
});
const perform = dispatch => ({
checkDaemonVersion: () => dispatch(doCheckDaemonVersion()),

View file

@ -3,7 +3,8 @@ import {
doChannelSubscribe,
doChannelUnsubscribe,
} from "redux/actions/subscriptions";
import { selectSubscriptions } from "redux/selectors/subscriptions";;
import { selectSubscriptions } from "redux/selectors/subscriptions";
import SubscribeButton from "./view";
const select = (state, props) => ({
@ -12,5 +13,5 @@ const select = (state, props) => ({
export default connect(select, {
doChannelSubscribe,
doChannelUnsubscribe
doChannelUnsubscribe,
})(SubscribeButton);

View file

@ -29,7 +29,7 @@ export class ToolTip extends React.PureComponent {
render() {
return (
<span className={"tooltip " + (this.props.className || "")}>
<span className={`tooltip ${this.props.className || ""}`}>
<a
className="tooltip__link"
onClick={() => {
@ -39,9 +39,7 @@ export class ToolTip extends React.PureComponent {
{this.props.label}
</a>
<div
className={
"tooltip__body " + (this.state.showTooltip ? "" : " hidden")
}
className={`tooltip__body ${this.state.showTooltip ? "" : " hidden"}`}
onMouseOut={() => {
this.handleTooltipMouseOut();
}}

View file

@ -141,7 +141,7 @@ export const CLAIM_REWARD_FAILURE = "CLAIM_REWARD_FAILURE";
export const CLAIM_REWARD_CLEAR_ERROR = "CLAIM_REWARD_CLEAR_ERROR";
export const FETCH_REWARD_CONTENT_COMPLETED = "FETCH_REWARD_CONTENT_COMPLETED";
//Language
// Language
export const DOWNLOAD_LANGUAGE_SUCCEEDED = "DOWNLOAD_LANGUAGE_SUCCEEDED";
export const DOWNLOAD_LANGUAGE_FAILED = "DOWNLOAD_LANGUAGE_FAILED";

View file

@ -1,6 +1,6 @@
/*hardcoded names still exist for these in reducers/settings.js - only discovered when debugging*/
/*Many settings are stored in the localStorage by their name -
be careful about changing the value of a settings constant, as doing so can invalidate existing settings*/
/* hardcoded names still exist for these in reducers/settings.js - only discovered when debugging */
/* Many settings are stored in the localStorage by their name -
be careful about changing the value of a settings constant, as doing so can invalidate existing settings */
export const CREDIT_REQUIRED_ACKNOWLEDGED = "credit_required_acknowledged";
export const NEW_USER_ACKNOWLEDGED = "welcome_acknowledged";
export const EMAIL_COLLECTION_ACKNOWLEDGED = "email_collection_acknowledged";

View file

@ -1,18 +1,18 @@
var extract = require("i18n-extract");
const extract = require("i18n-extract");
const fs = require("fs");
var dir = __dirname + "/../../dist/locales";
var path = dir + "/en.json";
const dir = `${__dirname}/../../dist/locales`;
const path = `${dir}/en.json`;
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
fs.writeFile(path, "{}", "utf8", function(err) {
fs.writeFile(path, "{}", "utf8", err => {
if (err) {
return console.log(err);
}
var enLocale = require(path);
const enLocale = require(path);
const keys = extract.extractFromFiles(["js/**/*.{js,jsx}"], {
marker: "__",
@ -22,21 +22,21 @@ fs.writeFile(path, "{}", "utf8", function(err) {
reports = reports.concat(extract.findMissing(enLocale, keys));
if (reports.length > 0) {
fs.readFile(path, "utf8", function readFileCallback(err, data) {
fs.readFile(path, "utf8", (err, data) => {
if (err) {
console.log(err);
} else {
localeObj = JSON.parse(data);
for (var i = 0; i < reports.length; i++) {
for (let i = 0; i < reports.length; i++) {
// no need to care for other types than MISSING because starting file will always be empty
if (reports[i].type === "MISSING") {
localeObj[reports[i].key] = reports[i].key;
}
}
var json = JSON.stringify(localeObj, null, "\t"); //convert it back to json-string
fs.writeFile(path, json, "utf8", function callback(err) {
const json = JSON.stringify(localeObj, null, "\t"); // convert it back to json-string
fs.writeFile(path, json, "utf8", err => {
if (err) {
throw err;
}

View file

@ -15,12 +15,15 @@ import "scss/all.scss";
const env = process.env.NODE_ENV || "production";
const { remote, ipcRenderer, shell } = require("electron");
const contextMenu = remote.require("./main.js").contextMenu;
const app = require("./app");
// Workaround for https://github.com/electron-userland/electron-webpack/issues/52
if (process.env.NODE_ENV !== 'development') {
window.staticResourcesPath = require("path").join(remote.app.getAppPath(), "../static").replace(/\\/g, "\\\\");
if (process.env.NODE_ENV !== "development") {
window.staticResourcesPath = require("path")
.join(remote.app.getAppPath(), "../static")
.replace(/\\/g, "\\\\");
} else {
window.staticResourcesPath = "";
}
@ -56,12 +59,12 @@ ipcRenderer.on("window-is-focused", (event, data) => {
});
document.addEventListener("click", event => {
var target = event.target;
let target = event.target;
while (target && target !== document) {
if (target.matches("a") || target.matches("button")) {
// TODO: Look into using accessiblity labels (this would also make the app more accessible)
let hrefParts = window.location.href.split("#");
let element = target.title || (target.text && target.text.trim());
const hrefParts = window.location.href.split("#");
const element = target.title || (target.text && target.text.trim());
if (element) {
amplitude.getInstance().logEvent("CLICK", {
target: element,
@ -89,7 +92,7 @@ document.addEventListener("click", event => {
const initialState = app.store.getState();
var init = function() {
const init = function() {
app.store.dispatch(doDownloadLanguages());
function onDaemonReady() {
@ -99,8 +102,8 @@ var init = function() {
"0b130efdcbdbf86ec2f7f9eff354033e",
info.lbry_id,
null,
function() {
window.sessionStorage.setItem("loaded", "y"); //once we've made it here once per session, we don't need to show splash again
() => {
window.sessionStorage.setItem("loaded", "y"); // once we've made it here once per session, we don't need to show splash again
app.store.dispatch(doDaemonReady());
ReactDOM.render(
@ -110,7 +113,7 @@ var init = function() {
<SnackBar />
</div>
</Provider>,
document.getElementById('app')
document.getElementById("app")
);
}
);
@ -124,7 +127,7 @@ var init = function() {
<Provider store={store}>
<SplashScreen onReadyToLaunch={onDaemonReady} />
</Provider>,
document.getElementById('app')
document.getElementById("app")
);
}
};

View file

@ -12,8 +12,10 @@ jsonrpc.call = function(
function checkAndParse(response) {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
return response.json().then(json => {
}
return response
.json()
.then(json => {
let error;
if (json.error) {
error = new Error(json.error);
@ -21,10 +23,10 @@ jsonrpc.call = function(
error = new Error("Protocol error with unknown response signature");
}
return Promise.reject(error);
}).catch(e => {
})
.catch(e => {
console.error(e);
});
}
}
function makeRequest(url, options) {
@ -35,9 +37,7 @@ jsonrpc.call = function(
if (timeout) {
const e = new Error(__("Protocol request timed out"));
setTimeout(() => {
return reject(e);
}, timeout);
setTimeout(() => reject(e), timeout);
}
});
}
@ -48,8 +48,8 @@ jsonrpc.call = function(
method: "POST",
body: JSON.stringify({
jsonrpc: "2.0",
method: method,
params: params,
method,
params,
id: counter,
}),
};
@ -70,11 +70,11 @@ jsonrpc.call = function(
return errorCallback(error);
}
var errorEvent = new CustomEvent("unhandledError", {
const errorEvent = new CustomEvent("unhandledError", {
detail: {
connectionString: connectionString,
method: method,
params: params,
connectionString,
method,
params,
code: error.code,
message: error.message || error,
data: error.data,
@ -87,11 +87,11 @@ jsonrpc.call = function(
return connectFailedCallback(e);
}
var errorEvent = new CustomEvent("unhandledError", {
const errorEvent = new CustomEvent("unhandledError", {
detail: {
connectionString: connectionString,
method: method,
params: params,
connectionString,
method,
params,
code: e.response && e.response.status,
message: __("Connection to API server failed"),
},

View file

@ -39,17 +39,17 @@ function savePendingPublish({ name, channel_name }) {
if (channel_name) {
uri = lbryuri.build({ name: channel_name, path: name }, false);
} else {
uri = lbryuri.build({ name: name }, false);
uri = lbryuri.build({ name }, false);
}
++pendingId;
const pendingPublishes = getLocal("pendingPublishes") || [];
const newPendingPublish = {
name,
channel_name,
claim_id: "pending-" + pendingId,
txid: "pending-" + pendingId,
claim_id: `pending-${pendingId}`,
txid: `pending-${pendingId}`,
nout: 0,
outpoint: "pending-" + pendingId + ":0",
outpoint: `pending-${pendingId}:0`,
time: Date.now(),
};
setLocal("pendingPublishes", [...pendingPublishes, newPendingPublish]);
@ -119,7 +119,7 @@ function pendingPublishToDummyFileInfo({ name, outpoint, claim_id }) {
return { name, outpoint, claim_id, metadata: null };
}
//core
// core
lbry._connectPromise = null;
lbry.connect = function() {
if (lbry._connectPromise === null) {
@ -203,19 +203,19 @@ lbry.publishDeprecated = function(
};
lbry.imagePath = function(file) {
return staticResourcesPath + "/img/" + file;
return `${staticResourcesPath}/img/${file}`;
};
lbry.getMediaType = function(contentType, fileName) {
if (contentType) {
return /^[^/]+/.exec(contentType)[0];
} else if (fileName) {
var dotIndex = fileName.lastIndexOf(".");
const dotIndex = fileName.lastIndexOf(".");
if (dotIndex == -1) {
return "unknown";
}
var ext = fileName.substr(dotIndex + 1);
const ext = fileName.substr(dotIndex + 1);
if (/^mp4|m4v|webm|flv|f4v|ogv$/i.test(ext)) {
return "video";
} else if (/^mp3|m4a|aac|wav|flac|ogg|opus$/i.test(ext)) {
@ -224,12 +224,10 @@ lbry.getMediaType = function(contentType, fileName) {
/^html|htm|xml|pdf|odf|doc|docx|md|markdown|txt|epub|org$/i.test(ext)
) {
return "document";
} else {
return "unknown";
}
} else {
return "unknown";
}
return "unknown";
};
lbry.getAppVersionInfo = function() {
@ -273,7 +271,7 @@ lbry.file_list = function(params = {}) {
fileInfos => {
removePendingPublishIfNeeded({ name, channel_name, outpoint });
//if a naked file_list call, append the pending file infos
// if a naked file_list call, append the pending file infos
if (!name && !channel_name && !outpoint) {
const dummyFileInfos = lbry
.getPendingPublishes()
@ -295,11 +293,11 @@ lbry.claim_list_mine = function(params = {}) {
"claim_list_mine",
params,
claims => {
for (let { name, channel_name, txid, nout } of claims) {
for (const { name, channel_name, txid, nout } of claims) {
removePendingPublishIfNeeded({
name,
channel_name,
outpoint: txid + ":" + nout,
outpoint: `${txid}:${nout}`,
});
}
@ -318,7 +316,7 @@ lbry.resolve = function(params = {}) {
apiCall(
"resolve",
params,
function(data) {
data => {
if ("uri" in params) {
// If only a single URI was requested, don't nest the results in an object
resolve(data && data[params.uri] ? data[params.uri] : {});
@ -332,7 +330,7 @@ lbry.resolve = function(params = {}) {
};
lbry = new Proxy(lbry, {
get: function(target, name) {
get(target, name) {
if (name in target) {
return target[name];
}

View file

@ -48,18 +48,17 @@ lbryio.call = function(resource, action, params = {}, method = "get") {
function checkAndParse(response) {
if (response.status >= 200 && response.status < 300) {
return response.json();
} else {
return response.json().then(json => {
let error;
if (json.error) {
error = new Error(json.error);
} else {
error = new Error("Unknown API error signature");
}
error.response = response; //this is primarily a hack used in actions/user.js
return Promise.reject(error);
});
}
return response.json().then(json => {
let error;
if (json.error) {
error = new Error(json.error);
} else {
error = new Error("Unknown API error signature");
}
error.response = response; // this is primarily a hack used in actions/user.js
return Promise.reject(error);
});
}
function makeRequest(url, options) {
@ -92,8 +91,8 @@ lbryio.call = function(resource, action, params = {}, method = "get") {
lbryio._authToken = null;
lbryio.getAuthToken = () => {
return new Promise((resolve, reject) => {
lbryio.getAuthToken = () =>
new Promise((resolve, reject) => {
if (lbryio._authToken) {
resolve(lbryio._authToken);
} else {
@ -104,16 +103,13 @@ lbryio.getAuthToken = () => {
ipcRenderer.send("get-auth-token");
}
});
};
lbryio.setAuthToken = token => {
lbryio._authToken = token ? token.toString().trim() : null;
ipcRenderer.send("set-auth-token", token);
};
lbryio.getCurrentUser = () => {
return lbryio.call("user", "me");
};
lbryio.getCurrentUser = () => lbryio.call("user", "me");
lbryio.authenticate = function() {
if (!lbryio.enabled) {
@ -141,12 +137,8 @@ lbryio.authenticate = function() {
// check that token works
return lbryio
.getCurrentUser()
.then(() => {
return true;
})
.catch(() => {
return false;
});
.then(() => true)
.catch(() => false);
})
.then(isTokenValid => {
if (isTokenValid) {
@ -155,8 +147,8 @@ lbryio.authenticate = function() {
return lbry
.status()
.then(status => {
return lbryio.call(
.then(status =>
lbryio.call(
"user",
"new",
{
@ -165,8 +157,8 @@ lbryio.authenticate = function() {
app_id: status.installation_id,
},
"post"
);
})
)
)
.then(response => {
if (!response.auth_token) {
throw new Error(__("auth_token is missing from response"));
@ -182,10 +174,9 @@ lbryio.authenticate = function() {
return lbryio._authenticationPromise;
};
lbryio.getStripeToken = () => {
return CONNECTION_STRING.startsWith("http://localhost:")
lbryio.getStripeToken = () =>
CONNECTION_STRING.startsWith("http://localhost:")
? "pk_test_NoL1JWL7i1ipfhVId5KfDZgo"
: "pk_live_e8M4dRNnCCbmpZzduEUZBgJO";
};
export default lbryio;

View file

@ -103,7 +103,7 @@ lbryuri.parse = function(uri, requireProto = false) {
if (
claimId &&
(claimId.length > CLAIM_ID_MAX_LEN || !claimId.match(/^[0-9a-f]+$/)) &&
!claimId.match(/^pending/) //ought to be dropped when savePendingPublish drops hack
!claimId.match(/^pending/) // ought to be dropped when savePendingPublish drops hack
) {
throw new Error(__(`Invalid claim ID %s.`, claimId));
}
@ -166,7 +166,7 @@ lbryuri.build = function(uriObj, includeProto = true, allowExtraProps = false) {
if (channelName) {
const channelNameFormatted = channelName.startsWith("@")
? channelName
: "@" + channelName;
: `@${channelName}`;
if (!name) {
name = channelNameFormatted;
} else if (name !== channelNameFormatted) {

View file

@ -30,7 +30,7 @@ export class Modal extends React.PureComponent {
<ReactModal
onCloseRequested={this.props.onAborted || this.props.onConfirmed}
{...this.props}
className={(this.props.className || "") + " modal"}
className={`${this.props.className || ""} modal`}
overlayClassName={
![null, undefined, ""].includes(this.props.overlayClassName)
? this.props.overlayClassName

View file

@ -24,18 +24,16 @@ const select = (state, props) => {
};
};
const perform = dispatch => () => {
return {
addBalance: () => {
dispatch(doSetClientSetting(settings.CREDIT_REQUIRED_ACKNOWLEDGED, true));
dispatch(doNavigate("/getcredits"));
dispatch(doCloseModal());
},
closeModal: () => {
dispatch(doSetClientSetting(settings.CREDIT_REQUIRED_ACKNOWLEDGED, true));
dispatch(doCloseModal());
},
};
};
const perform = dispatch => () => ({
addBalance: () => {
dispatch(doSetClientSetting(settings.CREDIT_REQUIRED_ACKNOWLEDGED, true));
dispatch(doNavigate("/getcredits"));
dispatch(doCloseModal());
},
closeModal: () => {
dispatch(doSetClientSetting(settings.CREDIT_REQUIRED_ACKNOWLEDGED, true));
dispatch(doCloseModal());
},
});
export default connect(select, perform)(ModalCreditIntro);

View file

@ -71,10 +71,9 @@ class ReportPage extends React.Component {
onClick={event => {
this.submitMessage(event);
}}
className={
"button-block button-primary " +
(this.state.submitting ? "disabled" : "")
}
className={`button-block button-primary ${
this.state.submitting ? "disabled" : ""
}`}
>
{this.state.submitting
? __("Submitting...")

View file

@ -9,13 +9,11 @@ import { doAuthNavigate, doNavigate } from "redux/actions/navigation";
import { doRewardList } from "redux/actions/rewards";
import RewardsPage from "./view";
const select = (state, props) => {
return {
fetching: selectFetchingRewards(state),
rewards: selectUnclaimedRewards(state),
user: selectUser(state),
};
};
const select = (state, props) => ({
fetching: selectFetchingRewards(state),
rewards: selectUnclaimedRewards(state),
user: selectUser(state),
});
const perform = dispatch => ({
fetchRewards: () => dispatch(doRewardList()),

View file

@ -18,9 +18,11 @@ import { selectCurrentModal } from "redux/selectors/app";
const { remote, ipcRenderer, shell } = require("electron");
const path = require("path");
const { download } = remote.require("electron-dl");
const fs = remote.require("fs");
const { lbrySettings: config } = require("package.json");
const CHECK_UPGRADE_INTERVAL = 10 * 60 * 1000;
export function doOpenModal(modal, modalProps = {}) {
@ -43,7 +45,7 @@ export function doUpdateDownloadProgress(percent) {
return {
type: types.UPGRADE_DOWNLOAD_PROGRESSED,
data: {
percent: percent,
percent,
},
};
}
@ -72,7 +74,7 @@ export function doDownloadUpgrade() {
),
upgradeFilename = selectUpgradeFilename(state);
let options = {
const options = {
onProgress: p => dispatch(doUpdateDownloadProgress(Math.round(p * 100))),
directory: dir,
};

View file

@ -42,9 +42,9 @@ export function doResolveUris(uris) {
data: { uris },
});
let resolveInfo = {};
const resolveInfo = {};
lbry.resolve({ uris: urisToResolve }).then(result => {
for (let [uri, uriResolveInfo] of Object.entries(result)) {
for (const [uri, uriResolveInfo] of Object.entries(result)) {
const fallbackResolveInfo = {
claim: null,
claims_in_channel: null,
@ -80,7 +80,7 @@ export function doFetchFeaturedUris() {
const success = ({ Uris }) => {
let urisToResolve = [];
for (let category in Uris) {
for (const category in Uris) {
urisToResolve = [...urisToResolve, ...Uris[category]];
}
@ -144,7 +144,7 @@ export function doUpdateLoadStatus(uri, outpoint) {
lbry
.file_list({
outpoint: outpoint,
outpoint,
full_status: true,
})
.then(([fileInfo]) => {
@ -239,7 +239,7 @@ export function doDownloadFile(uri, streamInfo) {
lbryio
.call("file", "view", {
uri: uri,
uri,
outpoint: streamInfo.outpoint,
claim_id: streamInfo.claim_id,
})
@ -288,7 +288,9 @@ export function doLoadVideo(uri) {
});
dispatch(
doAlertError(
`Failed to download ${uri}, please try again. If this problem persists, visit https://lbry.io/faq/support for support.`
`Failed to download ${
uri
}, please try again. If this problem persists, visit https://lbry.io/faq/support for support.`
)
);
});
@ -511,7 +513,7 @@ export function doAbandonClaim(txid, nout) {
dispatch({
type: types.ABANDON_CLAIM_STARTED,
data: {
claimId: claimId,
claimId,
},
});
@ -524,7 +526,7 @@ export function doAbandonClaim(txid, nout) {
dispatch({
type: types.ABANDON_CLAIM_SUCCEEDED,
data: {
claimId: claimId,
claimId,
},
});
dispatch(doResolveUri(lbryuri.build({ name, claimId })));
@ -536,8 +538,8 @@ export function doAbandonClaim(txid, nout) {
lbry
.claim_abandon({
txid: txid,
nout: nout,
txid,
nout,
})
.then(successCallback, errorCallback);
};

View file

@ -34,17 +34,15 @@ export function doFetchFileInfo(uri) {
},
});
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, full_status: true }).then(fileInfos => {
dispatch({
type: types.FETCH_FILE_INFO_COMPLETED,
data: {
outpoint,
fileInfo: fileInfos && fileInfos.length ? fileInfos[0] : null,
},
});
});
}
};
}
@ -91,7 +89,7 @@ export function doDeleteFile(outpoint, deleteFromComputer, abandonClaim) {
const state = getState();
lbry.file_delete({
outpoint: outpoint,
outpoint,
delete_from_download_dir: deleteFromComputer,
});

View file

@ -19,7 +19,7 @@ export function doNavigate(path, params = {}, options = {}) {
let url = path;
if (params && Object.values(params).length) {
url += "?" + toQueryString(params);
url += `?${toQueryString(params)}`;
}
const scrollY = options.scrollY;

View file

@ -39,7 +39,7 @@ export function doClaimRewardType(rewardType) {
userIsRewardApproved = selectUserIsRewardApproved(state);
if (!reward || reward.transaction_id) {
//already claimed or doesn't exist, do nothing
// already claimed or doesn't exist, do nothing
return;
}

View file

@ -24,17 +24,18 @@ export function doSearch(rawQuery) {
});
if (page != "search") {
dispatch(doNavigate("search", { query: query }));
dispatch(doNavigate("search", { query }));
} else {
fetch("https://lighthouse.lbry.io/search?s=" + query)
.then(response => {
return response.status === 200
? Promise.resolve(response.json())
: Promise.reject(new Error(response.statusText));
})
fetch(`https://lighthouse.lbry.io/search?s=${query}`)
.then(
response =>
response.status === 200
? Promise.resolve(response.json())
: Promise.reject(new Error(response.statusText))
)
.then(data => {
let uris = [];
let actions = [];
const uris = [];
const actions = [];
data.forEach(result => {
const uri = lbryuri.build({

View file

@ -22,7 +22,7 @@ export function doFetchDaemonSettings() {
export function doSetDaemonSetting(key, value) {
return function(dispatch, getState) {
let settings = {};
const settings = {};
settings[key] = value;
lbry.settings_set(settings).then(settings);
lbry.settings_get().then(settings => {
@ -49,19 +49,13 @@ export function doSetClientSetting(key, value) {
export function doGetThemes() {
return function(dispatch, getState) {
const themes = ["light", "dark"];
dispatch(
doSetClientSetting(
settings.THEMES,
themes
)
);
dispatch(doSetClientSetting(settings.THEMES, themes));
};
}
export function doDownloadLanguage(langFile) {
return function(dispatch, getState) {
const destinationPath = app.i18n.directory + "/" + langFile;
const destinationPath = `${app.i18n.directory}/${langFile}`;
const language = langFile.replace(".json", "");
const req = http.get(
{
@ -82,7 +76,7 @@ export function doDownloadLanguage(langFile) {
// push to our local list
dispatch({
type: types.DOWNLOAD_LANGUAGE_SUCCEEDED,
data: { language: language },
data: { language },
});
});
@ -102,7 +96,7 @@ export function doDownloadLanguage(langFile) {
});
};
req.setTimeout(30000, function() {
req.setTimeout(30000, () => {
req.abort();
});
@ -114,7 +108,7 @@ export function doDownloadLanguage(langFile) {
export function doDownloadLanguages() {
return function(dispatch, getState) {
//temporarily disable i18n so I can get a working build out -- Jeremy
// temporarily disable i18n so I can get a working build out -- Jeremy
return;
if (!fs.existsSync(app.i18n.directory)) {
@ -124,11 +118,10 @@ export function doDownloadLanguages() {
function checkStatus(response) {
if (response.status >= 200 && response.status < 300) {
return response;
} else {
throw new Error(
__("The list of available languages could not be retrieved.")
);
}
throw new Error(
__("The list of available languages could not be retrieved.")
);
}
function parseJSON(response) {

View file

@ -106,7 +106,7 @@ export const createShapeShift = (
const pair = `${originCoin.toLowerCase()}_lbc`;
const options = {
returnAddress: returnAddress,
returnAddress,
};
dispatch({ type: types.PREPARE_SHAPE_SHIFT_START });

View file

@ -1,26 +1,27 @@
// @flow
import * as actions from "constants/action_types";
import type { Subscription, Action, Dispatch } from "redux/reducers/subscriptions";
import type {
Subscription,
Action,
Dispatch,
} from "redux/reducers/subscriptions";
import lbry from "lbry";
export const doChannelSubscribe = (subscription: Subscription) => (
dispatch: Dispatch
) => {
return dispatch({
) =>
dispatch({
type: actions.CHANNEL_SUBSCRIBE,
data: subscription,
});
};
export const doChannelUnsubscribe = (subscription: Subscription) => (
dispatch: Dispatch
) => {
return dispatch({
) =>
dispatch({
type: actions.CHANNEL_UNSUBSCRIBE,
data: subscription,
});
};
export const setHasFetchedSubscriptions = () => (dispatch: Dispatch) => {
return dispatch({ type: actions.HAS_FETCHED_SUBSCRIPTIONS })
}
export const setHasFetchedSubscriptions = () => (dispatch: Dispatch) =>
dispatch({ type: actions.HAS_FETCHED_SUBSCRIPTIONS });

View file

@ -59,7 +59,7 @@ export function doUserEmailNew(email) {
return function(dispatch, getState) {
dispatch({
type: types.USER_EMAIL_NEW_STARTED,
email: email,
email,
});
const success = () => {
@ -68,30 +68,32 @@ export function doUserEmailNew(email) {
data: { email },
});
dispatch(doUserFetch());
}
};
const failure = error => {
dispatch({
type: types.USER_EMAIL_NEW_FAILURE,
data: { error },
});
}
};
lbryio
.call(
"user_email",
"new",
{ email: email, send_verification_email: true },
{ email, send_verification_email: true },
"post"
)
.catch(error => {
if (error.response && error.response.status == 409) {
return lbryio.call(
"user_email",
"resend_token",
{ email: email, only_if_expired: true },
"post"
).then(success, failure);
return lbryio
.call(
"user_email",
"resend_token",
{ email, only_if_expired: true },
"post"
)
.then(success, failure);
}
throw error;
})
@ -113,7 +115,7 @@ export function doUserEmailVerify(verificationToken) {
.call(
"user_email",
"confirm",
{ verification_token: verificationToken, email: email },
{ verification_token: verificationToken, email },
"post"
)
.then(userEmail => {
@ -125,7 +127,7 @@ export function doUserEmailVerify(verificationToken) {
dispatch(doClaimRewardType(rewards.TYPE_CONFIRM_EMAIL)),
dispatch(doUserFetch());
} else {
throw new Error("Your email is still not verified."); //shouldn't happen
throw new Error("Your email is still not verified."); // shouldn't happen
}
})
.catch(error => {
@ -156,7 +158,7 @@ export function doUserIdentityVerify(stripeToken) {
} else {
throw new Error(
"Your identity is still not verified. This should not happen."
); //shouldn't happen
); // shouldn't happen
}
})
.catch(error => {
@ -214,7 +216,7 @@ export function doUserInviteNew(email) {
});
lbryio
.call("user", "invite", { email: email }, "post")
.call("user", "invite", { email }, "post")
.then(invite => {
dispatch({
type: types.USER_INVITE_NEW_SUCCESS,

View file

@ -11,14 +11,14 @@ import * as modals from "constants/modal_types";
export function doUpdateBalance() {
return function(dispatch, getState) {
lbry.wallet_balance().then(balance => {
return dispatch({
lbry.wallet_balance().then(balance =>
dispatch({
type: types.UPDATE_BALANCE,
data: {
balance: balance,
balance,
},
});
});
})
);
};
}
@ -35,14 +35,16 @@ export function doFetchTransactions(fetch_tip_info = true) {
type: types.FETCH_TRANSACTIONS_STARTED,
});
lbry.transaction_list({ include_tip_info: fetch_tip_info }).then(results => {
dispatch({
type: types.FETCH_TRANSACTIONS_COMPLETED,
data: {
transactions: results,
},
lbry
.transaction_list({ include_tip_info: fetch_tip_info })
.then(results => {
dispatch({
type: types.FETCH_TRANSACTIONS_COMPLETED,
data: {
transactions: results,
},
});
});
});
};
}
@ -63,7 +65,7 @@ export function doGetNewAddress() {
type: types.GET_NEW_ADDRESS_STARTED,
});
lbry.wallet_new_address().then(function(address) {
lbry.wallet_new_address().then(address => {
localStorage.setItem("wallet_address", address);
dispatch({
type: types.GET_NEW_ADDRESS_COMPLETED,
@ -201,8 +203,8 @@ export function doSendSupport(amount, claim_id, uri) {
lbry
.wallet_send({
claim_id: claim_id,
amount: amount,
claim_id,
amount,
})
.then(successCallback, errorCallback);
};

View file

@ -9,7 +9,7 @@ reducers[types.RESOLVE_URIS_COMPLETED] = function(state, action) {
const byUri = Object.assign({}, state.claimsByUri);
const byId = Object.assign({}, state.byId);
for (let [uri, { certificate, claim }] of Object.entries(resolveInfo)) {
for (const [uri, { certificate, claim }] of Object.entries(resolveInfo)) {
if (claim) {
byId[claim.claim_id] = claim;
byUri[uri] = claim.claim_id;
@ -51,12 +51,11 @@ reducers[types.FETCH_CLAIM_LIST_MINE_COMPLETED] = function(state, action) {
.forEach(claim => {
byId[claim.claim_id] = claim;
const pending = Object.values(pendingById).find(pendingClaim => {
return (
const pending = Object.values(pendingById).find(
pendingClaim =>
pendingClaim.name == claim.name &&
pendingClaim.channel_name == claim.channel_name
);
});
);
if (pending) {
delete pendingById[pending.claim_id];
@ -115,7 +114,7 @@ reducers[types.FETCH_CHANNEL_CLAIMS_COMPLETED] = function(state, action) {
const claimsByChannel = Object.assign({}, state.claimsByChannel);
const byChannel = Object.assign({}, claimsByChannel[uri]);
const allClaimIds = new Set(byChannel["all"]);
const allClaimIds = new Set(byChannel.all);
const currentPageClaimIds = [];
const byId = Object.assign({}, state.byId);
const fetchingChannelClaims = Object.assign({}, state.fetchingChannelClaims);
@ -128,7 +127,7 @@ reducers[types.FETCH_CHANNEL_CLAIMS_COMPLETED] = function(state, action) {
});
}
byChannel["all"] = allClaimIds;
byChannel.all = allClaimIds;
byChannel[page] = currentPageClaimIds;
claimsByChannel[uri] = byChannel;
delete fetchingChannelClaims[uri];

View file

@ -32,12 +32,12 @@ reducers[types.FETCH_REWARD_CONTENT_COMPLETED] = function(state, action) {
};
reducers[types.RESOLVE_URIS_STARTED] = function(state, action) {
let { uris } = action.data;
const { uris } = action.data;
const oldResolving = state.resolvingUris || [];
const newResolving = Object.assign([], oldResolving);
for (let uri of uris) {
for (const uri of uris) {
if (!newResolving.includes(uri)) {
newResolving.push(uri);
}
@ -52,7 +52,7 @@ reducers[types.RESOLVE_URIS_COMPLETED] = function(state, action) {
const { resolveInfo } = action.data;
const channelClaimCounts = Object.assign({}, state.channelClaimCounts);
for (let [uri, { certificate, claims_in_channel }] of Object.entries(
for (const [uri, { certificate, claims_in_channel }] of Object.entries(
resolveInfo
)) {
if (certificate && !isNaN(claims_in_channel)) {
@ -66,11 +66,10 @@ reducers[types.RESOLVE_URIS_COMPLETED] = function(state, action) {
});
};
reducers[types.SET_PLAYING_URI] = (state, action) => {
return Object.assign({}, state, {
reducers[types.SET_PLAYING_URI] = (state, action) =>
Object.assign({}, state, {
playingUri: action.data.uri,
});
};
reducers[types.FETCH_CHANNEL_CLAIM_COUNT_COMPLETED] = function(state, action) {
const channelClaimCounts = Object.assign({}, state.channelClaimCounts);

View file

@ -4,7 +4,7 @@ import { parseQueryParams } from "util/query_params";
const currentPath = () => {
const hash = document.location.hash;
if (hash !== "") return hash.replace(/^#/, "");
else return "/discover";
return "/discover";
};
const reducers = {};
@ -34,7 +34,7 @@ reducers[types.HISTORY_NAVIGATE] = (state, action) => {
const { stack, index } = state;
const { url: path, index: newIndex, scrollY } = action.data;
let newState = {
const newState = {
currentPath: path,
};
@ -46,7 +46,7 @@ reducers[types.HISTORY_NAVIGATE] = (state, action) => {
newState.index = newState.stack.length - 1;
}
history.replaceState(null, null, "#" + path); //this allows currentPath() to retain the URL on reload
history.replaceState(null, null, `#${path}`); // this allows currentPath() to retain the URL on reload
return Object.assign({}, state, newState);
};
@ -61,7 +61,7 @@ reducers[types.WINDOW_SCROLLED] = (state, action) => {
}
return {
...stackItem,
scrollY: scrollY,
scrollY,
};
}),
});

View file

@ -3,7 +3,7 @@ import * as types from "constants/action_types";
const reducers = {};
const defaultState = {
fetching: false,
claimedRewardsById: {}, //id => reward
claimedRewardsById: {}, // id => reward
unclaimedRewardsByType: {},
claimPendingByType: {},
claimErrorsByType: {},
@ -64,7 +64,10 @@ reducers[types.CLAIM_REWARD_STARTED] = function(state, action) {
reducers[types.CLAIM_REWARD_SUCCESS] = function(state, action) {
const { reward } = action.data;
let unclaimedRewardsByType = Object.assign({}, state.unclaimedRewardsByType);
const unclaimedRewardsByType = Object.assign(
{},
state.unclaimedRewardsByType
);
const existingReward = unclaimedRewardsByType[reward.reward_type];
delete state.unclaimedRewardsByType[reward.reward_type];
@ -73,7 +76,7 @@ reducers[types.CLAIM_REWARD_SUCCESS] = function(state, action) {
reward_description: existingReward.reward_description,
});
let claimedRewardsById = Object.assign({}, state.claimedRewardsById);
const claimedRewardsById = Object.assign({}, state.claimedRewardsById);
claimedRewardsById[reward.id] = newReward;
const newState = Object.assign({}, state, {

View file

@ -3,7 +3,7 @@ import * as settings from "constants/settings";
import LANGUAGES from "constants/languages";
function getLocalStorageSetting(setting, fallback) {
var localStorageVal = localStorage.getItem("setting_" + setting);
const localStorageVal = localStorage.getItem(`setting_${setting}`);
return localStorageVal === null ? fallback : JSON.parse(localStorageVal);
}
@ -27,7 +27,7 @@ const defaultState = {
email_collection_acknowledged: getLocalStorageSetting(
settings.EMAIL_COLLECTION_ACKNOWLEDGED
),
credit_required_acknowledged: false, //this needs to be re-acknowledged every run
credit_required_acknowledged: false, // this needs to be re-acknowledged every run
language: getLocalStorageSetting(settings.LANGUAGE, "en"),
theme: getLocalStorageSetting(settings.THEME, "light"),
themes: getLocalStorageSetting(settings.THEMES, []),
@ -47,8 +47,8 @@ reducers[types.CLIENT_SETTING_CHANGED] = function(state, action) {
clientSettings[key] = value;
//this technically probably shouldn't happen here, and should be fixed when we're no longer using localStorage at all for persistent app state
localStorage.setItem("setting_" + key, JSON.stringify(value));
// this technically probably shouldn't happen here, and should be fixed when we're no longer using localStorage at all for persistent app state
localStorage.setItem(`setting_${key}`, JSON.stringify(value));
return Object.assign({}, state, {
clientSettings,
@ -62,8 +62,9 @@ reducers[types.DOWNLOAD_LANGUAGE_SUCCEEDED] = function(state, action) {
const langCode = language.substring(0, 2);
if (LANGUAGES[langCode]) {
languages[language] =
LANGUAGES[langCode][0] + " (" + LANGUAGES[langCode][1] + ")";
languages[language] = `${LANGUAGES[langCode][0]} (${
LANGUAGES[langCode][1]
})`;
} else {
languages[langCode] = langCode;
}

View file

@ -5,7 +5,7 @@ import { handleActions } from "util/redux-utils";
// Subscription redux types
export type SubscriptionState = {
subscriptions: Array<Subscription>,
hasFetchedSubscriptions: boolean
hasFetchedSubscriptions: boolean,
};
export type Subscription = {
@ -25,15 +25,18 @@ type doChannelUnsubscribe = {
};
type HasFetchedSubscriptions = {
type: actions.HAS_FETCHED_SUBSCRIPTIONS
}
type: actions.HAS_FETCHED_SUBSCRIPTIONS,
};
export type Action = doChannelSubscribe | doChannelUnsubscribe | HasFetchedSubscriptions;
export type Action =
| doChannelSubscribe
| doChannelUnsubscribe
| HasFetchedSubscriptions;
export type Dispatch = (action: Action) => any;
const defaultState = {
subscriptions: [],
hasFetchedSubscriptions: false
hasFetchedSubscriptions: false,
};
export default handleActions(
@ -43,7 +46,7 @@ export default handleActions(
action: doChannelSubscribe
): SubscriptionState => {
const newSubscription: Subscription = action.data;
let newSubscriptions: Array<Subscription> = state.subscriptions.slice();
const newSubscriptions: Array<Subscription> = state.subscriptions.slice();
newSubscriptions.unshift(newSubscription);
return {
@ -59,9 +62,10 @@ export default handleActions(
const newSubscriptions = state.subscriptions
.slice()
.filter(subscription => {
return subscription.channelName !== subscriptionToRemove.channelName;
});
.filter(
subscription =>
subscription.channelName !== subscriptionToRemove.channelName
);
return {
...state,
@ -73,8 +77,8 @@ export default handleActions(
action: HasFetchedSubscriptions
): SubscriptionState => ({
...state,
hasFetchedSubscriptions: true
})
hasFetchedSubscriptions: true,
}),
},
defaultState
);

View file

@ -69,17 +69,17 @@ reducers[types.USER_EMAIL_NEW_STARTED] = function(state, action) {
};
reducers[types.USER_EMAIL_NEW_SUCCESS] = function(state, action) {
let user = Object.assign({}, state.user);
const user = Object.assign({}, state.user);
user.primary_email = action.data.email;
return Object.assign({}, state, {
emailToVerify: action.data.email,
emailNewIsPending: false,
user: user,
user,
});
};
reducers[types.USER_EMAIL_NEW_EXISTS] = function(state, action) {
let user = Object.assign({}, state.user);
const user = Object.assign({}, state.user);
return Object.assign({}, state, {
emailToVerify: action.data.email,
emailNewIsPending: false,
@ -101,12 +101,12 @@ reducers[types.USER_EMAIL_VERIFY_STARTED] = function(state, action) {
};
reducers[types.USER_EMAIL_VERIFY_SUCCESS] = function(state, action) {
let user = Object.assign({}, state.user);
const user = Object.assign({}, state.user);
user.primary_email = action.data.email;
return Object.assign({}, state, {
emailToVerify: "",
emailVerifyIsPending: false,
user: user,
user,
});
};

View file

@ -25,7 +25,7 @@ reducers[types.FETCH_TRANSACTIONS_STARTED] = function(state, action) {
};
reducers[types.FETCH_TRANSACTIONS_COMPLETED] = function(state, action) {
let byId = Object.assign({}, state.transactions);
const byId = Object.assign({}, state.transactions);
const { transactions } = action.data;

View file

@ -7,21 +7,16 @@ export const selectAvailabilityByUri = createSelector(
state => state.byUri || {}
);
export const makeSelectIsAvailableForUri = uri => {
return createSelector(
export const makeSelectIsAvailableForUri = uri =>
createSelector(
selectAvailabilityByUri,
byUri => (!byUri || byUri[uri] === undefined ? undefined : byUri[uri] > 0)
);
};
export const selectFetchingAvailability = createSelector(
_selectState,
state => state.fetching || {}
);
export const makeSelectFetchingAvailabilityForUri = uri => {
return createSelector(
selectFetchingAvailability,
byUri => byUri && byUri[uri]
);
};
export const makeSelectFetchingAvailabilityForUri = uri =>
createSelector(selectFetchingAvailability, byUri => byUri && byUri[uri]);

View file

@ -40,12 +40,11 @@ export const selectAllClaimsByChannel = createSelector(
state => state.claimsByChannel || {}
);
export const makeSelectClaimForUri = uri => {
return createSelector(
export const makeSelectClaimForUri = uri =>
createSelector(
selectClaimsByUri,
claims => claims && claims[lbryuri.normalize(uri)]
);
};
export const makeSelectClaimIsMine = rawUri => {
const uri = lbryuri.normalize(rawUri);
@ -65,12 +64,11 @@ export const selectAllFetchingChannelClaims = createSelector(
state => state.fetchingChannelClaims || {}
);
export const makeSelectFetchingChannelClaims = uri => {
return createSelector(
export const makeSelectFetchingChannelClaims = uri =>
createSelector(
selectAllFetchingChannelClaims,
fetching => fetching && fetching[uri]
);
};
export const makeSelectClaimsInChannelForCurrentPage = uri => {
const pageSelector = makeSelectCurrentParam("page");
@ -90,30 +88,27 @@ export const makeSelectClaimsInChannelForCurrentPage = uri => {
);
};
export const makeSelectMetadataForUri = uri => {
return createSelector(makeSelectClaimForUri(uri), claim => {
export const makeSelectMetadataForUri = uri =>
createSelector(makeSelectClaimForUri(uri), claim => {
const metadata =
claim && claim.value && claim.value.stream && claim.value.stream.metadata;
const value = metadata ? metadata : claim === undefined ? undefined : null;
const value = metadata || (claim === undefined ? undefined : null);
return value;
});
};
export const makeSelectTitleForUri = uri => {
return createSelector(
export const makeSelectTitleForUri = uri =>
createSelector(
makeSelectMetadataForUri(uri),
metadata => metadata && metadata.title
);
};
export const makeSelectContentTypeForUri = uri => {
return createSelector(makeSelectClaimForUri(uri), claim => {
export const makeSelectContentTypeForUri = uri =>
createSelector(makeSelectClaimForUri(uri), claim => {
const source =
claim && claim.value && claim.value.stream && claim.value.stream.source;
return source ? source.contentType : undefined;
});
};
export const selectIsFetchingClaimListMine = createSelector(
_selectState,
@ -203,7 +198,7 @@ export const selectMyChannelClaims = createSelector(
ids.forEach(id => {
if (byId[id]) {
//I'm not sure why this check is necessary, but it ought to be a quick fix for https://github.com/lbryio/lbry-app/issues/544
// I'm not sure why this check is necessary, but it ought to be a quick fix for https://github.com/lbryio/lbry-app/issues/544
claims.push(byId[id]);
}
});

View file

@ -22,28 +22,25 @@ export const selectPlayingUri = createSelector(
state => state.playingUri
);
export const makeSelectIsUriResolving = uri => {
return createSelector(
export const makeSelectIsUriResolving = uri =>
createSelector(
selectResolvingUris,
resolvingUris => resolvingUris && resolvingUris.indexOf(uri) != -1
);
};
export const selectChannelClaimCounts = createSelector(
_selectState,
state => state.channelClaimCounts || {}
);
export const makeSelectTotalItemsForChannel = uri => {
return createSelector(selectChannelClaimCounts, byUri => byUri && byUri[uri]);
};
export const makeSelectTotalItemsForChannel = uri =>
createSelector(selectChannelClaimCounts, byUri => byUri && byUri[uri]);
export const makeSelectTotalPagesForChannel = uri => {
return createSelector(
export const makeSelectTotalPagesForChannel = uri =>
createSelector(
selectChannelClaimCounts,
byUri => byUri && byUri[uri] && Math.ceil(byUri[uri] / 10)
);
};
export const selectRewardContentClaimIds = createSelector(
_selectState,

View file

@ -8,12 +8,11 @@ export const selectAllCostInfoByUri = createSelector(
state => state.byUri || {}
);
export const makeSelectCostInfoForUri = uri => {
return createSelector(
export const makeSelectCostInfoForUri = uri =>
createSelector(
selectAllCostInfoByUri,
costInfos => costInfos && costInfos[uri]
);
};
export const selectCostForCurrentPageUri = createSelector(
selectAllCostInfoByUri,
@ -27,9 +26,8 @@ export const selectFetchingCostInfo = createSelector(
state => state.fetching || {}
);
export const makeSelectFetchingCostInfoForUri = uri => {
return createSelector(
export const makeSelectFetchingCostInfoForUri = uri =>
createSelector(
selectFetchingCostInfo,
fetchingByUri => fetchingByUri && fetchingByUri[uri]
);
};

View file

@ -26,8 +26,8 @@ export const selectIsFetchingFileListDownloadedOrPublished = createSelector(
isFetchingFileList || isFetchingClaimListMine
);
export const makeSelectFileInfoForUri = uri => {
return createSelector(
export const makeSelectFileInfoForUri = uri =>
createSelector(
selectClaimsByUri,
selectFileInfosByOutpoint,
(claims, byOutpoint) => {
@ -37,15 +37,14 @@ export const makeSelectFileInfoForUri = uri => {
return outpoint ? byOutpoint[outpoint] : undefined;
}
);
};
export const selectDownloadingByOutpoint = createSelector(
_selectState,
state => state.downloadingByOutpoint || {}
);
export const makeSelectDownloadingForUri = uri => {
return createSelector(
export const makeSelectDownloadingForUri = uri =>
createSelector(
selectDownloadingByOutpoint,
makeSelectFileInfoForUri(uri),
(byOutpoint, fileInfo) => {
@ -53,16 +52,14 @@ export const makeSelectDownloadingForUri = uri => {
return byOutpoint[fileInfo.outpoint];
}
);
};
export const selectUrisLoading = createSelector(
_selectState,
state => state.urisLoading || {}
);
export const makeSelectLoadingForUri = uri => {
return createSelector(selectUrisLoading, byUri => byUri && byUri[uri]);
};
export const makeSelectLoadingForUri = uri =>
createSelector(selectUrisLoading, byUri => byUri && byUri[uri]);
export const selectFileInfosPendingPublish = createSelector(
_selectState,
@ -72,8 +69,8 @@ export const selectFileInfosPendingPublish = createSelector(
export const selectFileInfosDownloaded = createSelector(
selectFileInfosByOutpoint,
selectMyClaims,
(byOutpoint, myClaims) => {
return Object.values(byOutpoint).filter(fileInfo => {
(byOutpoint, myClaims) =>
Object.values(byOutpoint).filter(fileInfo => {
const myClaimIds = myClaims.map(claim => claim.claim_id);
return (
@ -81,8 +78,7 @@ export const selectFileInfosDownloaded = createSelector(
myClaimIds.indexOf(fileInfo.claim_id) === -1 &&
(fileInfo.completed || fileInfo.written_bytes)
);
});
}
})
);
export const selectFileInfosPublished = createSelector(
@ -157,6 +153,6 @@ export const selectTotalDownloadProgress = createSelector(
const totalProgress = progress.reduce((a, b) => a + b, 0);
if (fileInfos.length > 0) return totalProgress / fileInfos.length / 100.0;
else return -1;
return -1;
}
);

View file

@ -13,9 +13,9 @@ export const selectCurrentPath = createSelector(
export const computePageFromPath = path =>
path.replace(/^\//, "").split("?")[0];
export const selectCurrentPage = createSelector(selectCurrentPath, path => {
return computePageFromPath(path);
});
export const selectCurrentPage = createSelector(selectCurrentPath, path =>
computePageFromPath(path)
);
export const selectCurrentParams = createSelector(selectCurrentPath, path => {
if (path === undefined) return {};
@ -24,12 +24,11 @@ export const selectCurrentParams = createSelector(selectCurrentPath, path => {
return parseQueryParams(path.split("?")[1]);
});
export const makeSelectCurrentParam = param => {
return createSelector(
export const makeSelectCurrentParam = param =>
createSelector(
selectCurrentParams,
params => (params ? params[param] : undefined)
);
};
export const selectHeaderLinks = createSelector(selectCurrentPage, page => {
// This contains intentional fall throughs

View file

@ -31,12 +31,13 @@ export const selectClaimedRewardsByTransactionId = createSelector(
export const selectUnclaimedRewards = createSelector(
selectUnclaimedRewardsByType,
byType =>
Object.values(byType).sort(function(a, b) {
return rewards.SORT_ORDER.indexOf(a.reward_type) <
Object.values(byType).sort(
(a, b) =>
rewards.SORT_ORDER.indexOf(a.reward_type) <
rewards.SORT_ORDER.indexOf(b.reward_type)
? -1
: 1;
}) || []
? -1
: 1
) || []
);
export const selectIsRewardEligible = createSelector(
@ -51,10 +52,7 @@ export const selectFetchingRewards = createSelector(
export const selectUnclaimedRewardValue = createSelector(
selectUnclaimedRewards,
rewards =>
rewards.reduce((sum, reward) => {
return sum + reward.reward_amount;
}, 0)
rewards => rewards.reduce((sum, reward) => sum + reward.reward_amount, 0)
);
export const selectHasClaimedReward = (state, props) => {
@ -62,47 +60,39 @@ export const selectHasClaimedReward = (state, props) => {
return reward && reward.transaction_id !== "";
};
export const makeSelectHasClaimedReward = () => {
return createSelector(selectHasClaimedReward, claimed => claimed);
};
export const makeSelectHasClaimedReward = () =>
createSelector(selectHasClaimedReward, claimed => claimed);
export const selectClaimsPendingByType = createSelector(
_selectState,
state => state.claimPendingByType
);
const selectIsClaimRewardPending = (state, props) => {
return selectClaimsPendingByType(state, props)[props.reward_type];
};
const selectIsClaimRewardPending = (state, props) =>
selectClaimsPendingByType(state, props)[props.reward_type];
export const makeSelectIsRewardClaimPending = () => {
return createSelector(selectIsClaimRewardPending, isClaiming => isClaiming);
};
export const makeSelectIsRewardClaimPending = () =>
createSelector(selectIsClaimRewardPending, isClaiming => isClaiming);
export const selectClaimErrorsByType = createSelector(
_selectState,
state => state.claimErrorsByType
);
const selectClaimRewardError = (state, props) => {
return selectClaimErrorsByType(state, props)[props.reward_type];
};
const selectClaimRewardError = (state, props) =>
selectClaimErrorsByType(state, props)[props.reward_type];
export const makeSelectClaimRewardError = () => {
return createSelector(selectClaimRewardError, errorMessage => errorMessage);
};
export const makeSelectClaimRewardError = () =>
createSelector(selectClaimRewardError, errorMessage => errorMessage);
const selectRewardByType = (state, props) => {
return selectUnclaimedRewardsByType(state)[props.reward_type];
};
const selectRewardByType = (state, props) =>
selectUnclaimedRewardsByType(state)[props.reward_type];
export const makeSelectRewardByType = () => {
return createSelector(selectRewardByType, reward => reward);
};
export const makeSelectRewardByType = () =>
createSelector(selectRewardByType, reward => reward);
export const makeSelectRewardAmountByType = () => {
return createSelector(
export const makeSelectRewardAmountByType = () =>
createSelector(
selectRewardByType,
reward => (reward ? reward.reward_amount : 0)
);
};

View file

@ -23,19 +23,18 @@ export const selectSearchUrisByQuery = createSelector(
state => state.urisByQuery
);
export const makeSelectSearchUris = query => {
//replace statement below is kind of ugly, and repeated in doSearch action
return createSelector(
export const makeSelectSearchUris = query =>
// replace statement below is kind of ugly, and repeated in doSearch action
createSelector(
selectSearchUrisByQuery,
byQuery => byQuery[query ? query.replace(/^lbry:\/\//i, "") : query]
);
};
export const selectWunderBarAddress = createSelector(
selectCurrentPage,
selectPageTitle,
selectSearchQuery,
(page, title, query) => (page != "search" ? title : query ? query : title)
(page, title, query) => (page != "search" ? title : query || title)
);
export const selectWunderBarIcon = createSelector(

View file

@ -14,19 +14,18 @@ export const selectClientSettings = createSelector(
state => state.clientSettings || {}
);
export const makeSelectClientSetting = setting => {
return createSelector(
export const makeSelectClientSetting = setting =>
createSelector(
selectClientSettings,
settings => (settings ? settings[setting] : undefined)
);
};
export const selectSettingsIsGenerous = createSelector(
selectDaemonSettings,
settings => settings && settings.is_generous_host
);
//refactor me
// refactor me
export const selectShowNsfw = makeSelectClientSetting(settings.SHOW_NSFW);
export const selectLanguages = createSelector(
@ -36,5 +35,5 @@ export const selectLanguages = createSelector(
export const selectThemePath = createSelector(
makeSelectClientSetting(settings.THEME),
theme => staticResourcesPath + "/themes/" + (theme || "light") + ".css"
theme => `${staticResourcesPath}/themes/${theme || "light"}.css`
);

View file

@ -21,7 +21,7 @@ export const selectSubscriptionsFromClaims = createSelector(
return [];
}
let fetchedSubscriptions = [];
const fetchedSubscriptions = [];
savedSubscriptions.forEach(subscription => {
let channelClaims = [];
@ -40,9 +40,9 @@ export const selectSubscriptionsFromClaims = createSelector(
}
// all we really need is a uri for each claim
channelClaims = channelClaims.map(claim => {
return `${claim.name}#${claim.claim_id}`;
})
channelClaims = channelClaims.map(
claim => `${claim.name}#${claim.claim_id}`
);
fetchedSubscriptions.push({
claims: channelClaims,

View file

@ -20,7 +20,7 @@ export const selectTransactionItems = createSelector(
Object.keys(byId).forEach(txid => {
const tx = byId[txid];
//ignore dust/fees
// ignore dust/fees
// it is fee only txn if all infos are also empty
if (
Math.abs(tx.value) === Math.abs(tx.fee) &&
@ -31,7 +31,7 @@ export const selectTransactionItems = createSelector(
return;
}
let append = [];
const append = [];
append.push(
...tx.claim_info.map(item =>
@ -63,16 +63,16 @@ export const selectTransactionItems = createSelector(
items.push(
...append.map(item => {
//value on transaction, amount on outpoint
//amount is always positive, but should match sign of value
// value on transaction, amount on outpoint
// amount is always positive, but should match sign of value
const amount = parseFloat(
item.balance_delta ? item.balance_delta : item.value
);
return {
txid: txid,
txid,
date: tx.timestamp ? new Date(parseInt(tx.timestamp) * 1000) : null,
amount: amount,
amount,
fee: amount < 0 ? -1 * tx.fee / append.length : 0,
claim_id: item.claim_id,
claim_name: item.claim_name,
@ -89,19 +89,15 @@ export const selectTransactionItems = createSelector(
export const selectRecentTransactions = createSelector(
selectTransactionItems,
transactions => {
let threshold = new Date();
const threshold = new Date();
threshold.setDate(threshold.getDate() - 7);
return transactions.filter(transaction => {
return transaction.date > threshold;
});
return transactions.filter(transaction => transaction.date > threshold);
}
);
export const selectHasTransactions = createSelector(
selectTransactionItems,
transactions => {
return transactions && transactions.length > 0;
}
transactions => transactions && transactions.length > 0
);
export const selectIsFetchingTransactions = createSelector(
@ -146,10 +142,9 @@ export const selectDraftTransactionError = createSelector(
export const selectBlocks = createSelector(_selectState, state => state.blocks);
export const makeSelectBlockDate = block => {
return createSelector(
export const makeSelectBlockDate = block =>
createSelector(
selectBlocks,
blocks =>
blocks && blocks[block] ? new Date(blocks[block].time * 1000) : undefined
);
};

View file

@ -95,15 +95,16 @@ rewards.claimReward = function(type) {
case rewards.TYPE_FIRST_CHANNEL:
lbry
.claim_list_mine()
.then(function(claims) {
let claim = claims.reverse().find(function(claim) {
return (
claim.name.length &&
claim.name[0] == "@" &&
claim.txid.length &&
claim.category == "claim"
.then(claims => {
const claim = claims
.reverse()
.find(
claim =>
claim.name.length &&
claim.name[0] == "@" &&
claim.txid.length &&
claim.category == "claim"
);
});
if (claim) {
params.transaction_id = claim.txid;
requestReward(resolve, reject, params);
@ -120,14 +121,15 @@ rewards.claimReward = function(type) {
lbry
.claim_list_mine()
.then(claims => {
let claim = claims.reverse().find(function(claim) {
return (
claim.name.length &&
claim.name[0] != "@" &&
claim.txid.length &&
claim.category == "claim"
const claim = claims
.reverse()
.find(
claim =>
claim.name.length &&
claim.name[0] != "@" &&
claim.txid.length &&
claim.category == "claim"
);
});
if (claim) {
params.transaction_id = claim.txid;
requestReward(resolve, reject, params);

View file

@ -2,7 +2,7 @@
function batchActions(...actions) {
return {
type: "BATCH_ACTIONS",
actions: actions,
actions,
};
}

View file

@ -17,7 +17,7 @@ export function formatFullPrice(amount, precision) {
const index = decimals.indexOf(first);
// Set format fraction
formated = "." + fraction.substring(0, index + precision);
formated = `.${fraction.substring(0, index + precision)}`;
}
return parseFloat(quantity[0] + formated);

View file

@ -4,12 +4,10 @@ export function parseQueryParams(queryString) {
.split("?")
.pop()
.split("&")
.map(function(p) {
return p.split("=");
});
.map(p => p.split("="));
const params = {};
parts.forEach(function(arr) {
parts.forEach(arr => {
params[arr[0]] = arr[1];
});
return params;
@ -21,7 +19,7 @@ export function toQueryString(params) {
const parts = [];
for (const key in params) {
if (params.hasOwnProperty(key) && params[key]) {
parts.push(key + "=" + params[key]);
parts.push(`${key}=${params[key]}`);
}
}
return parts.join("&");

View file

@ -1,17 +1,18 @@
// util for creating reducers
// based off of redux-actions
// https://redux-actions.js.org/docs/api/handleAction.html#handleactions
export const handleActions = (actionMap, defaultState) => {
return (state = defaultState, action) => {
const handler = actionMap[action.type];
export const handleActions = (actionMap, defaultState) => (
state = defaultState,
action
) => {
const handler = actionMap[action.type];
if (handler) {
const newState = handler(state, action);
return Object.assign({}, state, newState);
}
if (handler) {
const newState = handler(state, action);
return Object.assign({}, state, newState);
}
// just return the original state if no handler
// returning a copy here breaks redux-persist
return state;
};
// just return the original state if no handler
// returning a copy here breaks redux-persist
return state;
};

View file

@ -1,4 +1,5 @@
const { remote } = require("electron");
const application = remote.app;
const dock = application.dock;
const win = remote.BrowserWindow.getFocusedWindow();

View file

@ -1,4 +1,5 @@
const { remote } = require("electron");
const application = remote.app;
const win = remote.getCurrentWindow();

View file

@ -20,7 +20,7 @@ const validateAddress = (coinType, address) => {
};
export const validateShapeShiftForm = (vals, props) => {
let errors = {};
const errors = {};
if (!vals.returnAddress) {
return errors;
@ -45,6 +45,4 @@ const exampleCoinAddresses = {
"466XMeJEcowYGx7RzUJj3VDWBZgRWErVQQX6tHYbsacS5QF6v3tidE6LZZnTJgzeEh6bKEEJ6GC9jHirrUKvJwVKVj9e7jm",
};
export const getExampleAddress = coin => {
return exampleCoinAddresses[coin];
};
export const getExampleAddress = coin => exampleCoinAddresses[coin];