Compare commits

..

1 commit

Author SHA1 Message Date
Anthony
76e79886b2
add comments and begin stripe integration 2021-06-12 21:16:34 +02:00
7 changed files with 91 additions and 82 deletions

View file

@ -17,9 +17,6 @@ yarn link lbryinc
### Build
Run `$ yarn build`. If the symlink does not work, just build the file and move the `bundle.js` file in to the `node_modules/` folder.
### Automatic rebuild
To have the code automatically rebuild upon changes you can run `$ yarn dev` which will use `rollup` to watch the files and build upon detection of updated source code.
## License
[MIT © LBRY](LICENSE)

27
dist/bundle.es.js vendored
View file

@ -759,19 +759,19 @@ function doFetchTrendingUris() {
}
//
const doFetchViewCount = claimIdCsv => dispatch => {
const doFetchViewCount = claimId => dispatch => {
dispatch({
type: FETCH_VIEW_COUNT_STARTED
});
return Lbryio.call('file', 'view_count', {
claim_id: claimIdCsv
claim_id: claimId
}).then(result => {
const viewCounts = result;
const viewCount = result[0];
dispatch({
type: FETCH_VIEW_COUNT_COMPLETED,
data: {
claimIdCsv,
viewCounts
claimId,
viewCount
}
});
}).catch(error => {
@ -1318,18 +1318,12 @@ const statsReducer = handleActions({
}),
[FETCH_VIEW_COUNT_COMPLETED]: (state, action) => {
const {
claimIdCsv,
viewCounts
claimId,
viewCount
} = action.data;
const viewCountById = Object.assign({}, state.viewCountById);
const claimIds = claimIdCsv.split(',');
if (claimIds.length === viewCounts.length) {
claimIds.forEach((claimId, index) => {
viewCountById[claimId] = viewCounts[index];
});
}
const viewCountById = { ...state.viewCountById,
[claimId]: viewCount
};
return { ...state,
fetchingViewCount: false,
viewCountById
@ -1605,7 +1599,6 @@ exports.selectSyncData = selectSyncData;
exports.selectSyncHash = selectSyncHash;
exports.selectTrendingUris = selectTrendingUris;
exports.selectUploadCount = selectUploadCount;
exports.selectViewCount = selectViewCount;
exports.statsReducer = statsReducer;
exports.syncReducer = syncReducer;
exports.webReducer = webReducer;

24
dist/bundle.js vendored
View file

@ -210,8 +210,6 @@ __webpack_require__.r(__webpack_exports__);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectFetchingTrendingUris", function() { return redux_selectors_homepage__WEBPACK_IMPORTED_MODULE_25__["selectFetchingTrendingUris"]; });
/* harmony import */ var redux_selectors_stats__WEBPACK_IMPORTED_MODULE_26__ = __webpack_require__(38);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "selectViewCount", function() { return redux_selectors_stats__WEBPACK_IMPORTED_MODULE_26__["selectViewCount"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeSelectViewCountForUri", function() { return redux_selectors_stats__WEBPACK_IMPORTED_MODULE_26__["makeSelectViewCountForUri"]; });
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeSelectSubCountForUri", function() { return redux_selectors_stats__WEBPACK_IMPORTED_MODULE_26__["makeSelectSubCountForUri"]; });
@ -3478,20 +3476,20 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var constants_action_types__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
var doFetchViewCount = function doFetchViewCount(claimIdCsv) {
var doFetchViewCount = function doFetchViewCount(claimId) {
return function (dispatch) {
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_VIEW_COUNT_STARTED"]
});
return lbryio__WEBPACK_IMPORTED_MODULE_0__["default"].call('file', 'view_count', {
claim_id: claimIdCsv
claim_id: claimId
}).then(function (result) {
var viewCounts = result;
var viewCount = result[0];
dispatch({
type: constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_VIEW_COUNT_COMPLETED"],
data: {
claimIdCsv: claimIdCsv,
viewCounts: viewCounts
claimId: claimId,
viewCount: viewCount
}
});
})["catch"](function (error) {
@ -4170,16 +4168,10 @@ var statsReducer = Object(util_redux_utils__WEBPACK_IMPORTED_MODULE_0__["handleA
});
}), _defineProperty(_handleActions, constants_action_types__WEBPACK_IMPORTED_MODULE_1__["FETCH_VIEW_COUNT_COMPLETED"], function (state, action) {
var _action$data = action.data,
claimIdCsv = _action$data.claimIdCsv,
viewCounts = _action$data.viewCounts;
var viewCountById = Object.assign({}, state.viewCountById);
var claimIds = claimIdCsv.split(',');
claimId = _action$data.claimId,
viewCount = _action$data.viewCount;
if (claimIds.length === viewCounts.length) {
claimIds.forEach(function (claimId, index) {
viewCountById[claimId] = viewCounts[index];
});
}
var viewCountById = _objectSpread({}, state.viewCountById, _defineProperty({}, claimId, viewCount));
return _objectSpread({}, state, {
fetchingViewCount: false,

View file

@ -58,11 +58,7 @@ export {
selectTrendingUris,
selectFetchingTrendingUris,
} from 'redux/selectors/homepage';
export {
selectViewCount,
makeSelectViewCountForUri,
makeSelectSubCountForUri,
} from 'redux/selectors/stats';
export { makeSelectViewCountForUri, makeSelectSubCountForUri } from 'redux/selectors/stats';
export {
selectHasSyncedWallet,
selectSyncData,

View file

@ -10,6 +10,7 @@ const Lbryio = {
CONNECTION_STRING: 'https://api.lbry.com/',
};
// 20 minute exchange rate timeout
const EXCHANGE_RATE_TIMEOUT = 20 * 60 * 1000;
const INTERNAL_APIS_DOWN = 'internal_apis_down';
@ -18,43 +19,57 @@ Lbryio.setLocalApi = endpoint => {
Lbryio.CONNECTION_STRING = endpoint.replace(/\/*$/, '/'); // exactly one slash at the end;
};
function checkAndParse(response) {
if (response.status >= 200 && response.status < 300) {
return response.json();
}
if (response.status === 500) {
return Promise.reject(INTERNAL_APIS_DOWN);
}
if (response)
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) {
return fetch(url, options).then(checkAndParse);
}
/**
* Call a Lbry API method
*
* @param {string} resource - resource value (me/lbc/customer/account/etc.)
* @param {string} action - the subresource (aka for customer: status/link)
* @param {object || string} params - used to build querystring for fetch (default {})
* @param {string} method - 'get' or 'post' (default - get)
* @returns {string} returns response.data returned by the API
*/
Lbryio.call = (resource, action, params = {}, method = 'get') => {
// reject promise if API disabled
if (!Lbryio.enabled) {
return Promise.reject(new Error(__('LBRY internal API is disabled')));
}
// only allow get or post requests
if (!(method === 'get' || method === 'post')) {
return Promise.reject(new Error(__('Invalid method')));
}
function checkAndParse(response) {
if (response.status >= 200 && response.status < 300) {
return response.json();
}
if (response.status === 500) {
return Promise.reject(INTERNAL_APIS_DOWN);
}
if (response)
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) {
return fetch(url, options).then(checkAndParse);
}
// get auth token and build request to be called via fetch
return Lbryio.getAuthToken().then(token => {
// add auth token to params
const fullParams = { auth_token: token, ...params };
// stringify param values
Object.keys(fullParams).forEach(key => {
const value = fullParams[key];
if (typeof value === 'object') {
@ -62,16 +77,21 @@ Lbryio.call = (resource, action, params = {}, method = 'get') => {
}
});
// build querystring for fetch
const qs = querystring.stringify(fullParams);
// build url for fetch
let url = `${Lbryio.CONNECTION_STRING}${resource}/${action}?${qs}`;
// set method to GET (changed to POST if applicable later)
let options = {
method: 'GET',
};
// build post request for fetch
if (method === 'post') {
options = {
method: 'POST',
// send as a form encoded url with query string
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
@ -80,20 +100,29 @@ Lbryio.call = (resource, action, params = {}, method = 'get') => {
url = `${Lbryio.CONNECTION_STRING}${resource}/${action}`;
}
// make request per url and options and return response.data
return makeRequest(url, options).then(response => response.data);
});
};
Lbryio.authToken = null;
/**
* Get user auth token, either stored on the window, or via a request to the API
*
* @returns {string} returns user's auth token
*/
Lbryio.getAuthToken = () =>
new Promise(resolve => {
// if authToken already saved on Lbryio object, return it
if (Lbryio.authToken) {
resolve(Lbryio.authToken);
// if there is an override, use that to get token
} else if (Lbryio.overrides.getAuthToken) {
Lbryio.overrides.getAuthToken().then(token => {
resolve(token);
});
// if the window is already defined, get token from there
} else if (typeof window !== 'undefined') {
const { store } = window;
if (store) {
@ -102,9 +131,10 @@ Lbryio.getAuthToken = () =>
Lbryio.authToken = token;
resolve(token);
}
// if everything whifs, return null
resolve(null);
} else {
// return null if nothing above worked
resolve(null);
}
});
@ -235,4 +265,13 @@ Lbryio.setOverride = (methodName, newMethod) => {
Lbryio.overrides[methodName] = newMethod;
};
function getCustomerStatus() {
const response = Lbryio.call('account', 'status', {}, 'post');
console.log(response);
}
setTimeout(() => {
getCustomerStatus();
}, 1000 * 5);
export default Lbryio;

View file

@ -2,13 +2,13 @@
import Lbryio from 'lbryio';
import * as ACTIONS from 'constants/action_types';
export const doFetchViewCount = (claimIdCsv: string) => dispatch => {
export const doFetchViewCount = (claimId: string) => dispatch => {
dispatch({ type: ACTIONS.FETCH_VIEW_COUNT_STARTED });
return Lbryio.call('file', 'view_count', { claim_id: claimIdCsv })
return Lbryio.call('file', 'view_count', { claim_id: claimId })
.then((result: Array<number>) => {
const viewCounts = result;
dispatch({ type: ACTIONS.FETCH_VIEW_COUNT_COMPLETED, data: { claimIdCsv, viewCounts } });
const viewCount = result[0];
dispatch({ type: ACTIONS.FETCH_VIEW_COUNT_COMPLETED, data: { claimId, viewCount } });
})
.catch(error => {
dispatch({ type: ACTIONS.FETCH_VIEW_COUNT_FAILED, data: error });

View file

@ -18,17 +18,9 @@ export const statsReducer = handleActions(
viewCountError: action.data,
}),
[ACTIONS.FETCH_VIEW_COUNT_COMPLETED]: (state, action) => {
const { claimIdCsv, viewCounts } = action.data;
const viewCountById = Object.assign({}, state.viewCountById);
const claimIds = claimIdCsv.split(',');
if (claimIds.length === viewCounts.length) {
claimIds.forEach((claimId, index) => {
viewCountById[claimId] = viewCounts[index];
});
}
const { claimId, viewCount } = action.data;
const viewCountById = { ...state.viewCountById, [claimId]: viewCount };
return {
...state,
fetchingViewCount: false,