Common components refactor #1

Merged
akinwale merged 42 commits from common-components-refactor into master 2018-04-05 04:57:30 +02:00
9 changed files with 90 additions and 31 deletions
Showing only changes of commit 7a5d25d3d9 - Show all commits

30
.eslintrc.json Normal file
View file

@ -0,0 +1,30 @@
{
kauffj commented 2018-02-02 15:38:47 +01:00 (Migrated from github.com)
Review

It's a dream to have linting and prettier configuration files shared across JS repos, right?

It's a dream to have linting and prettier configuration files shared across JS repos, right?
kauffj commented 2018-02-02 15:38:56 +01:00 (Migrated from github.com)
Review

(By dream I mean unrealistic)

(By dream I mean unrealistic)
"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
View file

@ -0,0 +1,12 @@
{
"linters": {
"src/**/*.{js}": [
"prettier --write",
"git add"
],
"src/**/*.{js}": [
"eslint --fix",
"git add"
]
}
}

5
.prettierrc.json Normal file
View file

@ -0,0 +1,5 @@
{
"trailingComma": "es5",
"printWidth": 100,
"singleQuote": true
}

View file

@ -17,6 +17,7 @@
"main": "build/index.js",
"scripts": {
"build": "webpack",
"precommit": "lint-staged",
kauffj commented 2018-02-02 15:40:36 +01:00 (Migrated from github.com)
Review

Please remove any unused depdencies.

Please remove any unused depdencies.
"lint": "eslint 'src/**/*.{js,jsx}' --fix",
"format": "prettier 'src/**/*.{js,jsx,scss,json}' --write"
},

View file

@ -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';

View file

@ -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);

View file

@ -1,7 +1,6 @@
import Lbry from 'lbry';
import querystring from 'querystring';
const LbryApi = {
const Lbryapi = {
enabled: true,
exchangePromise: null,
kauffj commented 2018-02-02 15:48:12 +01:00 (Migrated from github.com)
Review

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.

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.
akinwale commented 2018-02-05 08:42:39 +01:00 (Migrated from github.com)
Review

LbryWebApi or Lbrydotio, maybe?

LbryWebApi or Lbrydotio, maybe?
neb-b commented 2018-03-30 00:54:16 +02:00 (Migrated from github.com)
Review

I like LbryIncApi.

Whatever works though, I agree it might be nicer to have a larger difference between this and lbry

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;

View file

@ -1,7 +1,9 @@
kauffj commented 2018-02-02 15:53:15 +01:00 (Migrated from github.com)
Review

All of these will need to be removed from other actions.

All of these will need to be removed from other actions.
kauffj commented 2018-02-02 15:53:15 +01:00 (Migrated from github.com)
Review

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';
kauffj commented 2018-02-02 15:53:15 +01:00 (Migrated from github.com)
Review

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';
kauffj commented 2018-02-02 15:53:15 +01:00 (Migrated from github.com)
Review

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';
kauffj commented 2018-02-02 15:53:15 +01:00 (Migrated from github.com)
Review

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';
kauffj commented 2018-02-02 15:53:15 +01:00 (Migrated from github.com)
Review

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) {
kauffj commented 2018-02-02 15:53:15 +01:00 (Migrated from github.com)
Review

All of these will need to be removed from other actions.

All of these will need to be removed from other actions.
kauffj commented 2018-02-02 15:53:15 +01:00 (Migrated from github.com)
Review

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);
};
}
kauffj commented 2018-02-02 15:53:15 +01:00 (Migrated from github.com)
Review

All of these will need to be removed from other actions.

All of these will need to be removed from other actions.
}
kauffj commented 2018-02-02 15:53:15 +01:00 (Migrated from github.com)
Review

All of these will need to be removed from other actions.

All of these will need to be removed from other actions.

kauffj commented 2018-02-02 15:53:15 +01:00 (Migrated from github.com)
Review

All of these will need to be removed from other actions.

All of these will need to be removed from other actions.
kauffj commented 2018-02-02 15:53:15 +01:00 (Migrated from github.com)
Review

All of these will need to be removed from other actions.

All of these will need to be removed from other actions.

View file

@ -179,4 +179,3 @@ export const makeSelectIsUriResolving = uri =>
selectResolvingUris,
resolvingUris => resolvingUris && resolvingUris.indexOf(uri) !== -1
);