From 673e35a88d65ef040bd7dfbd3f68c9ab1f5afefd Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Mon, 18 Oct 2021 17:06:53 +0800 Subject: [PATCH 1/3] Lint '/extras/*' + fixes - Add `/extras` to the precommit hooks (lint, prettier). - Remove `preinstall` since these modules don't exist anymore. - Fix missing brace if one single-line if-statement. --- .lintstagedrc.json | 2 ++ extras/lbryinc/lbryio.js | 40 +++++++++++++++++++--------------------- package.json | 6 +++--- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.lintstagedrc.json b/.lintstagedrc.json index ae253a628..0e729e8bd 100644 --- a/.lintstagedrc.json +++ b/.lintstagedrc.json @@ -1,8 +1,10 @@ { "linters": { "ui/**/*.{js,jsx,scss,json}": ["prettier --write", "git add"], + "extras/**/*.{js,jsx,scss,json}": ["prettier --write", "git add"], "web/**/*.{js,jsx,scss,json}": ["prettier --write", "git add"], "ui/**/*.{js,jsx}": ["eslint", "flow focus-check --color always", "git add"], + "extras/**/*.{js,jsx}": ["eslint", "flow focus-check --color always", "git add"], "web/**/*.{js,jsx}": ["eslint", "git add"] }, "ignore": ["node_modules", "web/dist/**/*", "dist/**/*", "package-lock.json"] diff --git a/extras/lbryinc/lbryio.js b/extras/lbryinc/lbryio.js index 89c0536e9..770e2b6e8 100644 --- a/extras/lbryinc/lbryio.js +++ b/extras/lbryinc/lbryio.js @@ -14,7 +14,7 @@ const EXCHANGE_RATE_TIMEOUT = 20 * 60 * 1000; const INTERNAL_APIS_DOWN = 'internal_apis_down'; // We can't use env's because they aren't passed into node_modules -Lbryio.setLocalApi = endpoint => { +Lbryio.setLocalApi = (endpoint) => { Lbryio.CONNECTION_STRING = endpoint.replace(/\/*$/, '/'); // exactly one slash at the end; }; @@ -36,8 +36,8 @@ Lbryio.call = (resource, action, params = {}, method = 'get') => { return Promise.reject(INTERNAL_APIS_DOWN); } - if (response) - return response.json().then(json => { + if (response) { + return response.json().then((json) => { let error; if (json.error) { error = new Error(json.error); @@ -47,15 +47,16 @@ Lbryio.call = (resource, action, params = {}, method = 'get') => { error.response = response; // This is primarily a hack used in actions/user.js return Promise.reject(error); }); + } } function makeRequest(url, options) { return fetch(url, options).then(checkAndParse); } - return Lbryio.getAuthToken().then(token => { + return Lbryio.getAuthToken().then((token) => { const fullParams = { auth_token: token, ...params }; - Object.keys(fullParams).forEach(key => { + Object.keys(fullParams).forEach((key) => { const value = fullParams[key]; if (typeof value === 'object') { fullParams[key] = JSON.stringify(value); @@ -80,18 +81,18 @@ Lbryio.call = (resource, action, params = {}, method = 'get') => { url = `${Lbryio.CONNECTION_STRING}${resource}/${action}`; } - return makeRequest(url, options).then(response => response.data); + return makeRequest(url, options).then((response) => response.data); }); }; Lbryio.authToken = null; Lbryio.getAuthToken = () => - new Promise(resolve => { + new Promise((resolve) => { if (Lbryio.authToken) { resolve(Lbryio.authToken); } else if (Lbryio.overrides.getAuthToken) { - Lbryio.overrides.getAuthToken().then(token => { + Lbryio.overrides.getAuthToken().then((token) => { resolve(token); }); } else if (typeof window !== 'undefined') { @@ -122,7 +123,7 @@ Lbryio.authenticate = (domain, language) => { language: language || 'en', }; - return new Promise(resolve => { + return new Promise((resolve) => { resolve(params); }); } @@ -130,15 +131,15 @@ Lbryio.authenticate = (domain, language) => { if (Lbryio.authenticationPromise === null) { Lbryio.authenticationPromise = new Promise((resolve, reject) => { Lbryio.getAuthToken() - .then(token => { + .then((token) => { if (!token || token.length > 60) { return false; } // check that token works return Lbryio.getCurrentUser() - .then(user => user) - .catch(error => { + .then((user) => user) + .catch((error) => { if (error === INTERNAL_APIS_DOWN) { throw new Error('Internal APIS down'); } @@ -146,14 +147,14 @@ Lbryio.authenticate = (domain, language) => { return false; }); }) - .then(user => { + .then((user) => { if (user) { return user; } return Lbry.status() .then( - status => + (status) => new Promise((res, rej) => { const appId = domain && domain !== 'lbry.tv' @@ -169,7 +170,7 @@ Lbryio.authenticate = (domain, language) => { }, 'post' ) - .then(response => { + .then((response) => { if (!response.auth_token) { throw new Error('auth_token was not set in the response'); } @@ -188,10 +189,10 @@ Lbryio.authenticate = (domain, language) => { Lbryio.authToken = response.auth_token; return res(response); }) - .catch(error => rej(error)); + .catch((error) => rej(error)); }) ) - .then(newUser => { + .then((newUser) => { if (!newUser) { return Lbryio.getCurrentUser(); } @@ -211,10 +212,7 @@ Lbryio.getStripeToken = () => : 'pk_live_e8M4dRNnCCbmpZzduEUZBgJO'; Lbryio.getExchangeRates = () => { - if ( - !Lbryio.exchangeLastFetched || - Date.now() - Lbryio.exchangeLastFetched > EXCHANGE_RATE_TIMEOUT - ) { + if (!Lbryio.exchangeLastFetched || Date.now() - Lbryio.exchangeLastFetched > EXCHANGE_RATE_TIMEOUT) { Lbryio.exchangePromise = new Promise((resolve, reject) => { Lbryio.call('lbc', 'exchange_rate', {}, 'get', true) .then(({ lbc_usd: LBC_USD, lbc_btc: LBC_BTC, btc_usd: BTC_USD }) => { diff --git a/package.json b/package.json index adf9ced23..1c1492173 100644 --- a/package.json +++ b/package.json @@ -38,12 +38,12 @@ "build:dir": "yarn build -- --dir -c.compression=store -c.mac.identity=null", "crossenv": "./node_modules/cross-env/dist/bin/cross-env", "flow": "flow", - "lint": "eslint 'ui/**/*.{js,jsx}' && eslint 'web/**/*.{js,jsx}' && eslint 'electron/**/*.js' && flow", - "lint-fix": "eslint --fix --quiet 'ui/**/*.{js,jsx}' && eslint --fix --quiet 'web/**/*.{js,jsx}' && eslint --fix --quiet 'electron/**/*.js'", + "lint": "eslint 'ui/**/*.{js,jsx}' && eslint 'extras/**/*.{js,jsx}' && eslint 'web/**/*.{js,jsx}' && eslint 'electron/**/*.js' && flow", + "lint-fix": "eslint --fix --quiet 'ui/**/*.{js,jsx}' && eslint --fix --quiet 'extras/**/*.{js,jsx}' && eslint --fix --quiet 'web/**/*.{js,jsx}' && eslint --fix --quiet 'electron/**/*.js'", "format": "prettier 'src/**/*.{js,jsx,scss,json}' --write", "flow-defs": "flow-typed install", "precommit": "lint-staged", - "preinstall": "yarn cache clean lbry-redux && yarn cache clean lbryinc", + "preinstall": "", "postinstall": "cd web && yarn && cd .. && if-env NODE_ENV=production && yarn postinstall:warning || if-env APP_ENV=web && echo 'Done installing deps' || yarn postinstall:electron", "postinstall:electron": "electron-builder install-app-deps && node ./build/downloadDaemon.js && node ./build/downloadLBRYFirst.js", "postinstall:warning": "echo '\n\nWARNING\n\nNot all node modules were installed because NODE_ENV is set to \"production\".\nThis should only be set after installing dependencies with \"yarn\". The app will not work.\n\n'" -- 2.45.2 From 7e2f66e207e091fed5edcce1da36a1d33e1230d0 Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Tue, 19 Oct 2021 09:47:29 +0800 Subject: [PATCH 2/3] Remove unused 'publish' actions The past-tense version is no longer used. --- extras/lbryinc/constants/action_types.js | 9 ++------- ui/constants/action_types.js | 3 --- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/extras/lbryinc/constants/action_types.js b/extras/lbryinc/constants/action_types.js index 65723007d..82c3a819d 100644 --- a/extras/lbryinc/constants/action_types.js +++ b/extras/lbryinc/constants/action_types.js @@ -17,9 +17,6 @@ export const FETCH_CHANNEL_LIST_STARTED = 'FETCH_CHANNEL_LIST_STARTED'; export const FETCH_CHANNEL_LIST_COMPLETED = 'FETCH_CHANNEL_LIST_COMPLETED'; export const CREATE_CHANNEL_STARTED = 'CREATE_CHANNEL_STARTED'; export const CREATE_CHANNEL_COMPLETED = 'CREATE_CHANNEL_COMPLETED'; -export const PUBLISH_STARTED = 'PUBLISH_STARTED'; -export const PUBLISH_COMPLETED = 'PUBLISH_COMPLETED'; -export const PUBLISH_FAILED = 'PUBLISH_FAILED'; export const SET_PLAYING_URI = 'SET_PLAYING_URI'; export const SET_CONTENT_POSITION = 'SET_CONTENT_POSITION'; export const SET_CONTENT_LAST_VIEWED = 'SET_CONTENT_LAST_VIEWED'; @@ -29,10 +26,8 @@ export const CLEAR_CONTENT_HISTORY_ALL = 'CLEAR_CONTENT_HISTORY_ALL'; // Subscriptions export const CHANNEL_SUBSCRIBE = 'CHANNEL_SUBSCRIBE'; export const CHANNEL_UNSUBSCRIBE = 'CHANNEL_UNSUBSCRIBE'; -export const CHANNEL_SUBSCRIPTION_ENABLE_NOTIFICATIONS = - 'CHANNEL_SUBSCRIPTION_ENABLE_NOTIFICATIONS'; -export const CHANNEL_SUBSCRIPTION_DISABLE_NOTIFICATIONS = - 'CHANNEL_SUBSCRIPTION_DISABLE_NOTIFICATIONS'; +export const CHANNEL_SUBSCRIPTION_ENABLE_NOTIFICATIONS = 'CHANNEL_SUBSCRIPTION_ENABLE_NOTIFICATIONS'; +export const CHANNEL_SUBSCRIPTION_DISABLE_NOTIFICATIONS = 'CHANNEL_SUBSCRIPTION_DISABLE_NOTIFICATIONS'; export const HAS_FETCHED_SUBSCRIPTIONS = 'HAS_FETCHED_SUBSCRIPTIONS'; export const SET_SUBSCRIPTION_LATEST = 'SET_SUBSCRIPTION_LATEST'; export const UPDATE_SUBSCRIPTION_UNREADS = 'UPDATE_SUBSCRIPTION_UNREADS'; diff --git a/ui/constants/action_types.js b/ui/constants/action_types.js index 9fbeeecd1..249d28d7a 100644 --- a/ui/constants/action_types.js +++ b/ui/constants/action_types.js @@ -133,9 +133,6 @@ export const FETCH_CHANNEL_LIST_STARTED = 'FETCH_CHANNEL_LIST_STARTED'; export const FETCH_CHANNEL_LIST_COMPLETED = 'FETCH_CHANNEL_LIST_COMPLETED'; export const CREATE_CHANNEL_STARTED = 'CREATE_CHANNEL_STARTED'; export const CREATE_CHANNEL_COMPLETED = 'CREATE_CHANNEL_COMPLETED'; -export const PUBLISH_STARTED = 'PUBLISH_STARTED'; -export const PUBLISH_COMPLETED = 'PUBLISH_COMPLETED'; -export const PUBLISH_FAILED = 'PUBLISH_FAILED'; export const SET_PRIMARY_URI = 'SET_PRIMARY_URI'; export const SET_PLAYING_URI = 'SET_PLAYING_URI'; export const SET_CONTENT_POSITION = 'SET_CONTENT_POSITION'; -- 2.45.2 From cbde7b904c64028bb0b2bce7b8295ac3bcc74141 Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Tue, 19 Oct 2021 09:51:00 +0800 Subject: [PATCH 3/3] Remove test function I assume this was a temp function. --- extras/lbryinc/index.js | 15 ++------------- ui/index.jsx | 4 +--- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/extras/lbryinc/index.js b/extras/lbryinc/index.js index b68d006e6..9216aa651 100644 --- a/extras/lbryinc/index.js +++ b/extras/lbryinc/index.js @@ -5,10 +5,6 @@ import Lbryio from './lbryio'; export { Lbryio }; -export function testTheThing() { - console.log('tested'); -} - // constants export { LBRYINC_ACTIONS, YOUTUBE_STATUSES, ERRORS }; @@ -51,10 +47,7 @@ export { selectAllCostInfoByUri, selectFetchingCostInfo, } from './redux/selectors/cost_info'; -export { - selectBlackListedOutpoints, - selectBlacklistedOutpointMap, -} from './redux/selectors/blacklist'; +export { selectBlackListedOutpoints, selectBlacklistedOutpointMap } from './redux/selectors/blacklist'; export { selectFilteredOutpoints, selectFilteredOutpointMap } from './redux/selectors/filtered'; // export { // selectFeaturedUris, @@ -62,11 +55,7 @@ export { selectFilteredOutpoints, selectFilteredOutpointMap } from './redux/sele // selectTrendingUris, // selectFetchingTrendingUris, // } from './redux/selectors/homepage'; -export { - selectViewCount, - makeSelectViewCountForUri, - makeSelectSubCountForUri, -} from './redux/selectors/stats'; +export { selectViewCount, makeSelectViewCountForUri, makeSelectSubCountForUri } from './redux/selectors/stats'; export { selectHasSyncedWallet, selectSyncData, diff --git a/ui/index.jsx b/ui/index.jsx index b723d3a74..4fe93fdcd 100644 --- a/ui/index.jsx +++ b/ui/index.jsx @@ -19,7 +19,7 @@ import Lbry, { apiCall } from 'lbry'; import { isURIValid } from 'util/lbryURI'; import { setSearchApi } from 'redux/actions/search'; import { doSetLanguage, doFetchLanguage, doUpdateIsNightAsync } from 'redux/actions/settings'; -import { Lbryio, doBlackListedOutpointsSubscribe, doFilteredOutpointsSubscribe, testTheThing } from 'lbryinc'; +import { Lbryio, doBlackListedOutpointsSubscribe, doFilteredOutpointsSubscribe } from 'lbryinc'; import rewards from 'rewards'; import { store, persistor, history } from 'store'; import app from './app'; @@ -65,8 +65,6 @@ if (process.env.NODE_ENV === 'production') { }); } -testTheThing(); - if (process.env.SDK_API_URL) { console.warn('SDK_API_URL env var is deprecated. Use SDK_API_HOST instead'); // @eslint-disable-line } -- 2.45.2