Common components refactor #1
30
.eslintrc.json
Normal file
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
|
||||
"plugins": ["flowtype"],
|
||||
"extends": [
|
||||
"airbnb",
|
||||
"plugin:import/electron",
|
||||
"plugin:flowtype/recommended",
|
||||
"plugin:prettier/recommended"
|
||||
],
|
||||
"settings": {
|
||||
"import/resolver": {
|
||||
"webpack": {
|
||||
"config": "webpack.config.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parser": "babel-eslint",
|
||||
"env": {
|
||||
"browser": true,
|
||||
"node": true
|
||||
},
|
||||
"globals": {
|
||||
"__": true
|
||||
},
|
||||
"rules": {
|
||||
"import/no-commonjs": "warn",
|
||||
"import/no-amd": "warn",
|
||||
"import/prefer-default-export": "ignore",
|
||||
"func-names": ["warn", "as-needed"]
|
||||
}
|
||||
}
|
12
.lintstagedrc
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"linters": {
|
||||
"src/**/*.{js}": [
|
||||
"prettier --write",
|
||||
"git add"
|
||||
],
|
||||
"src/**/*.{js}": [
|
||||
"eslint --fix",
|
||||
"git add"
|
||||
]
|
||||
}
|
||||
}
|
5
.prettierrc.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"trailingComma": "es5",
|
||||
"printWidth": 100,
|
||||
"singleQuote": true
|
||||
}
|
|
@ -17,6 +17,7 @@
|
|||
"main": "build/index.js",
|
||||
"scripts": {
|
||||
"build": "webpack",
|
||||
"precommit": "lint-staged",
|
||||
![]() Please remove any unused depdencies. Please remove any unused depdencies.
|
||||
"lint": "eslint 'src/**/*.{js,jsx}' --fix",
|
||||
"format": "prettier 'src/**/*.{js,jsx,scss,json}' --write"
|
||||
},
|
||||
|
|
40
src/index.js
|
@ -1,20 +1,30 @@
|
|||
// common
|
||||
import Lbry from 'lbry';
|
||||
import Lbryuri from 'lbryuri';
|
||||
|
||||
export { Lbry, Lbryuri };
|
||||
|
||||
// actions
|
||||
export { doOpenModal, doCloseModal, doShowSnackBar } from 'redux/actions/app';
|
||||
export { doFetchClaimListMine, doAbandonClaim, doResolveUris, doResolveUri } from 'redux/actions/claims';
|
||||
export {
|
||||
doFetchClaimListMine,
|
||||
doAbandonClaim,
|
||||
doResolveUris,
|
||||
doResolveUri,
|
||||
} from 'redux/actions/claims';
|
||||
export { doFetchCostInfoForUri } from 'redux/actions/cost_info';
|
||||
export { doFetchFileInfo, doFileList, doFetchFileInfosAndPublishedClaims } from 'redux/actions/file_info';
|
||||
export {
|
||||
doFetchFileInfo,
|
||||
doFileList,
|
||||
doFetchFileInfosAndPublishedClaims,
|
||||
} from 'redux/actions/file_info';
|
||||
export {
|
||||
doNavigate,
|
||||
doAuthNavigate,
|
||||
doHistoryTraverse,
|
||||
doHistoryBack,
|
||||
doHistoryForward,
|
||||
doRecordScroll
|
||||
doRecordScroll,
|
||||
} from 'redux/actions/navigation';
|
||||
export { doSearch } from 'redux/actions/search';
|
||||
export {
|
||||
|
@ -27,7 +37,7 @@ export {
|
|||
doSendDraftTransaction,
|
||||
doSetDraftTransactionAmount,
|
||||
doSetDraftTransactionAddress,
|
||||
doSendSupport
|
||||
doSendSupport,
|
||||
} from 'redux/actions/wallet';
|
||||
|
||||
// utils
|
||||
|
@ -35,7 +45,7 @@ export { batchActions } from 'util/batchActions';
|
|||
export { parseQueryParams, toQueryString } from 'util/query_params';
|
||||
|
||||
// reducers
|
||||
export { claimsReducer } from 'redux/reducers/claims';
|
||||
export { claimsReducer } from 'redux/reducers/claims';
|
||||
export { costInfoReducer } from 'redux/reducers/cost_info';
|
||||
export { fileInfoReducer } from 'redux/reducers/file_info';
|
||||
export { searchReducer } from 'redux/reducers/search';
|
||||
|
@ -66,15 +76,15 @@ export {
|
|||
selectMyClaimsOutpoints,
|
||||
selectFetchingMyChannels,
|
||||
selectMyChannelClaims,
|
||||
selectResolvingUris
|
||||
selectResolvingUris,
|
||||
} from 'redux/selectors/claims';
|
||||
|
||||
export {
|
||||
makeSelectFetchingCostInfoForUri,
|
||||
makeSelectCostInfoForUri,
|
||||
selectAllCostInfoByUri,
|
||||
selectCostForCurrentPageUri,
|
||||
selectFetchingCostInfo
|
||||
makeSelectFetchingCostInfoForUri,
|
||||
makeSelectCostInfoForUri,
|
||||
selectAllCostInfoByUri,
|
||||
selectCostForCurrentPageUri,
|
||||
selectFetchingCostInfo,
|
||||
} from 'redux/selectors/cost_info';
|
||||
|
||||
export {
|
||||
|
@ -88,7 +98,7 @@ export {
|
|||
selectUrisLoading,
|
||||
selectFileInfosDownloaded,
|
||||
selectDownloadingFileInfos,
|
||||
selectTotalDownloadProgress
|
||||
selectTotalDownloadProgress,
|
||||
} from 'redux/selectors/file_info';
|
||||
|
||||
export {
|
||||
|
@ -104,7 +114,7 @@ export {
|
|||
selectIsForwardDisabled,
|
||||
selectHistoryIndex,
|
||||
selectHistoryStack,
|
||||
selectActiveHistoryEntry
|
||||
selectActiveHistoryEntry,
|
||||
} from 'redux/selectors/navigation';
|
||||
|
||||
export {
|
||||
|
@ -113,7 +123,7 @@ export {
|
|||
selectIsSearching,
|
||||
selectSearchUrisByQuery,
|
||||
selectWunderBarAddress,
|
||||
selectWunderBarIcon
|
||||
selectWunderBarIcon,
|
||||
} from 'redux/selectors/search';
|
||||
|
||||
export {
|
||||
|
@ -131,5 +141,5 @@ export {
|
|||
selectDraftTransactionAmount,
|
||||
selectDraftTransactionAddress,
|
||||
selectDraftTransactionError,
|
||||
selectBlocks
|
||||
selectBlocks,
|
||||
} from 'redux/selectors/wallet';
|
||||
|
|
|
@ -103,6 +103,7 @@ Lbry.connect = () => {
|
|||
// Check every half second to see if the daemon is accepting connections
|
||||
function checkDaemonStarted() {
|
||||
tryNum += 1;
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
lbryProxy
|
||||
.status()
|
||||
.then(resolve)
|
||||
|
@ -146,6 +147,7 @@ Lbry.publishDeprecated = (params, fileListedCallback, publishedCallback, errorCa
|
|||
{ once: true }
|
||||
);
|
||||
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
lbryProxy.publish(params).then(
|
||||
result => {
|
||||
if (returnPendingTimeout) clearTimeout(returnPendingTimeout);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import Lbry from 'lbry';
|
||||
import querystring from 'querystring';
|
||||
|
||||
const LbryApi = {
|
||||
const Lbryapi = {
|
||||
enabled: true,
|
||||
exchangePromise: null,
|
||||
![]() I think we should consider naming this something else. If a new user is using this repo to build something, it's confusing to have two objects, Maybe call this I think we should consider naming this something else. If a new user is using this repo to build something, it's confusing to have two objects, `Lbry`, and `LbryApi`, and then first one is the LBRY API!
Maybe call this `LbryIncApi` or `LbryIoApi`? Not in love with either.
![]() LbryWebApi or Lbrydotio, maybe? LbryWebApi or Lbrydotio, maybe?
![]() I like Whatever works though, I agree it might be nicer to have a larger difference between this and I like `LbryIncApi`.
Whatever works though, I agree it might be nicer to have a larger difference between this and `lbry`
|
||||
exchangeLastFetched: null,
|
||||
|
@ -13,27 +12,26 @@ const CONNECTION_STRING = process.env.LBRY_APP_API_URL
|
|||
|
||||
const EXCHANGE_RATE_TIMEOUT = 20 * 60 * 1000;
|
||||
|
||||
LbryApi.getExchangeRates = () => {
|
||||
Lbryapi.getExchangeRates = () => {
|
||||
if (
|
||||
!LbryApi.exchangeLastFetched ||
|
||||
Date.now() - LbryApi.exchangeLastFetched > EXCHANGE_RATE_TIMEOUT
|
||||
!Lbryapi.exchangeLastFetched ||
|
||||
Date.now() - Lbryapi.exchangeLastFetched > EXCHANGE_RATE_TIMEOUT
|
||||
) {
|
||||
LbryApi.exchangePromise = new Promise((resolve, reject) => {
|
||||
LbryApi.call('lbc', 'exchange_rate', {}, 'get', true)
|
||||
Lbryapi.exchangePromise = new Promise((resolve, reject) => {
|
||||
Lbryapi.call('lbc', 'exchange_rate', {}, 'get', true)
|
||||
.then(({ lbc_usd: LBC_USD, lbc_btc: LBC_BTC, btc_usd: BTC_USD }) => {
|
||||
const rates = { LBC_USD, LBC_BTC, BTC_USD };
|
||||
resolve(rates);
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
LbryApi.exchangeLastFetched = Date.now();
|
||||
Lbryapi.exchangeLastFetched = Date.now();
|
||||
}
|
||||
return LbryApi.exchangePromise;
|
||||
return Lbryapi.exchangePromise;
|
||||
};
|
||||
|
||||
LbryApi.call = (resource, action, params = {}, method = 'get') => {
|
||||
if (!LbryApi.enabled) {
|
||||
console.log(__('Internal API disabled'));
|
||||
Lbryapi.call = (resource, action, params = {}, method = 'get') => {
|
||||
if (!Lbryapi.enabled) {
|
||||
return Promise.reject(new Error(__('LBRY internal API is disabled')));
|
||||
}
|
||||
|
||||
|
@ -83,4 +81,4 @@ LbryApi.call = (resource, action, params = {}, method = 'get') => {
|
|||
return makeRequest(url, options).then(response => response.data);
|
||||
};
|
||||
|
||||
export default LbryApi;
|
||||
export default Lbryapi;
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
![]() All of these will need to be removed from other actions. All of these will need to be removed from other actions.
![]() All of these will need to be removed from other actions. All of these will need to be removed from other actions.
|
||||
import * as ACTIONS from 'constants/action_types';
|
||||
import * as MODALS from 'constants/modal_types';
|
||||
![]() All of these will need to be removed from other actions. All of these will need to be removed from other actions.
|
||||
import Lbry from 'lbry';
|
||||
import Lbryuri from 'lbryuri';
|
||||
import { selectResolvingUris } from 'redux/selectors/claims';
|
||||
![]() All of these will need to be removed from other actions. All of these will need to be removed from other actions.
|
||||
import { doOpenModal } from 'redux/actions/app';
|
||||
![]() All of these will need to be removed from other actions. All of these will need to be removed from other actions.
|
||||
import { selectMyClaimsRaw, selectResolvingUris } from 'redux/selectors/claims';
|
||||
![]() All of these will need to be removed from other actions. All of these will need to be removed from other actions.
|
||||
|
||||
export function doResolveUris(uris) {
|
||||
return (dispatch, getState) => {
|
||||
|
@ -104,4 +106,4 @@ export function doAbandonClaim(txid, nout) {
|
|||
![]() All of these will need to be removed from other actions. All of these will need to be removed from other actions.
![]() All of these will need to be removed from other actions. All of these will need to be removed from other actions.
|
||||
nout,
|
||||
}).then(successCallback, errorCallback);
|
||||
};
|
||||
}
|
||||
![]() All of these will need to be removed from other actions. All of these will need to be removed from other actions.
|
||||
}
|
||||
![]() All of these will need to be removed from other actions. All of these will need to be removed from other actions.
|
||||
|
|
|||
![]() All of these will need to be removed from other actions. All of these will need to be removed from other actions.
![]() All of these will need to be removed from other actions. All of these will need to be removed from other actions.
|
|
@ -179,4 +179,3 @@ export const makeSelectIsUriResolving = uri =>
|
|||
selectResolvingUris,
|
||||
resolvingUris => resolvingUris && resolvingUris.indexOf(uri) !== -1
|
||||
);
|
||||
|
||||
|
|
It's a dream to have linting and prettier configuration files shared across JS repos, right?
(By dream I mean unrealistic)