2019-04-03 23:34:07 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
|
|
|
|
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
|
|
|
|
|
|
var lbryRedux = require('lbry-redux');
|
|
|
|
var querystring = _interopDefault(require('querystring'));
|
|
|
|
var reselect = require('reselect');
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
// Claims
|
2019-04-03 23:34:07 +02:00
|
|
|
const FETCH_FEATURED_CONTENT_STARTED = 'FETCH_FEATURED_CONTENT_STARTED';
|
|
|
|
const FETCH_FEATURED_CONTENT_COMPLETED = 'FETCH_FEATURED_CONTENT_COMPLETED';
|
|
|
|
const FETCH_TRENDING_CONTENT_STARTED = 'FETCH_TRENDING_CONTENT_STARTED';
|
|
|
|
const FETCH_TRENDING_CONTENT_COMPLETED = 'FETCH_TRENDING_CONTENT_COMPLETED';
|
|
|
|
const RESOLVE_URIS_STARTED = 'RESOLVE_URIS_STARTED';
|
|
|
|
const RESOLVE_URIS_COMPLETED = 'RESOLVE_URIS_COMPLETED';
|
|
|
|
const FETCH_CHANNEL_CLAIMS_STARTED = 'FETCH_CHANNEL_CLAIMS_STARTED';
|
|
|
|
const FETCH_CHANNEL_CLAIMS_COMPLETED = 'FETCH_CHANNEL_CLAIMS_COMPLETED';
|
|
|
|
const FETCH_CHANNEL_CLAIM_COUNT_STARTED = 'FETCH_CHANNEL_CLAIM_COUNT_STARTED';
|
|
|
|
const FETCH_CHANNEL_CLAIM_COUNT_COMPLETED = 'FETCH_CHANNEL_CLAIM_COUNT_COMPLETED';
|
|
|
|
const FETCH_CLAIM_LIST_MINE_STARTED = 'FETCH_CLAIM_LIST_MINE_STARTED';
|
|
|
|
const FETCH_CLAIM_LIST_MINE_COMPLETED = 'FETCH_CLAIM_LIST_MINE_COMPLETED';
|
|
|
|
const ABANDON_CLAIM_STARTED = 'ABANDON_CLAIM_STARTED';
|
|
|
|
const ABANDON_CLAIM_SUCCEEDED = 'ABANDON_CLAIM_SUCCEEDED';
|
|
|
|
const FETCH_CHANNEL_LIST_STARTED = 'FETCH_CHANNEL_LIST_STARTED';
|
|
|
|
const FETCH_CHANNEL_LIST_COMPLETED = 'FETCH_CHANNEL_LIST_COMPLETED';
|
|
|
|
const CREATE_CHANNEL_STARTED = 'CREATE_CHANNEL_STARTED';
|
|
|
|
const CREATE_CHANNEL_COMPLETED = 'CREATE_CHANNEL_COMPLETED';
|
|
|
|
const PUBLISH_STARTED = 'PUBLISH_STARTED';
|
|
|
|
const PUBLISH_COMPLETED = 'PUBLISH_COMPLETED';
|
|
|
|
const PUBLISH_FAILED = 'PUBLISH_FAILED';
|
|
|
|
const SET_PLAYING_URI = 'SET_PLAYING_URI';
|
|
|
|
const SET_CONTENT_POSITION = 'SET_CONTENT_POSITION';
|
|
|
|
const SET_CONTENT_LAST_VIEWED = 'SET_CONTENT_LAST_VIEWED';
|
|
|
|
const CLEAR_CONTENT_HISTORY_URI = 'CLEAR_CONTENT_HISTORY_URI';
|
|
|
|
const CLEAR_CONTENT_HISTORY_ALL = 'CLEAR_CONTENT_HISTORY_ALL'; // Subscriptions
|
|
|
|
|
|
|
|
const CHANNEL_SUBSCRIBE = 'CHANNEL_SUBSCRIBE';
|
|
|
|
const CHANNEL_UNSUBSCRIBE = 'CHANNEL_UNSUBSCRIBE';
|
|
|
|
const CHANNEL_SUBSCRIPTION_ENABLE_NOTIFICATIONS = 'CHANNEL_SUBSCRIPTION_ENABLE_NOTIFICATIONS';
|
|
|
|
const CHANNEL_SUBSCRIPTION_DISABLE_NOTIFICATIONS = 'CHANNEL_SUBSCRIPTION_DISABLE_NOTIFICATIONS';
|
|
|
|
const HAS_FETCHED_SUBSCRIPTIONS = 'HAS_FETCHED_SUBSCRIPTIONS';
|
|
|
|
const SET_SUBSCRIPTION_LATEST = 'SET_SUBSCRIPTION_LATEST';
|
|
|
|
const UPDATE_SUBSCRIPTION_UNREADS = 'UPDATE_SUBSCRIPTION_UNREADS';
|
|
|
|
const REMOVE_SUBSCRIPTION_UNREADS = 'REMOVE_SUBSCRIPTION_UNREADS';
|
|
|
|
const CHECK_SUBSCRIPTION_STARTED = 'CHECK_SUBSCRIPTION_STARTED';
|
|
|
|
const CHECK_SUBSCRIPTION_COMPLETED = 'CHECK_SUBSCRIPTION_COMPLETED';
|
|
|
|
const CHECK_SUBSCRIPTIONS_SUBSCRIBE = 'CHECK_SUBSCRIPTIONS_SUBSCRIBE';
|
|
|
|
const FETCH_SUBSCRIPTIONS_START = 'FETCH_SUBSCRIPTIONS_START';
|
|
|
|
const FETCH_SUBSCRIPTIONS_FAIL = 'FETCH_SUBSCRIPTIONS_FAIL';
|
|
|
|
const FETCH_SUBSCRIPTIONS_SUCCESS = 'FETCH_SUBSCRIPTIONS_SUCCESS';
|
|
|
|
const SET_VIEW_MODE = 'SET_VIEW_MODE';
|
|
|
|
const GET_SUGGESTED_SUBSCRIPTIONS_START = 'GET_SUGGESTED_SUBSCRIPTIONS_START';
|
|
|
|
const GET_SUGGESTED_SUBSCRIPTIONS_SUCCESS = 'GET_SUGGESTED_SUBSCRIPTIONS_SUCCESS';
|
|
|
|
const GET_SUGGESTED_SUBSCRIPTIONS_FAIL = 'GET_SUGGESTED_SUBSCRIPTIONS_FAIL';
|
|
|
|
const SUBSCRIPTION_FIRST_RUN_COMPLETED = 'SUBSCRIPTION_FIRST_RUN_COMPLETED';
|
|
|
|
const VIEW_SUGGESTED_SUBSCRIPTIONS = 'VIEW_SUGGESTED_SUBSCRIPTIONS'; // Blacklist
|
|
|
|
|
|
|
|
const FETCH_BLACK_LISTED_CONTENT_STARTED = 'FETCH_BLACK_LISTED_CONTENT_STARTED';
|
|
|
|
const FETCH_BLACK_LISTED_CONTENT_COMPLETED = 'FETCH_BLACK_LISTED_CONTENT_COMPLETED';
|
|
|
|
const FETCH_BLACK_LISTED_CONTENT_FAILED = 'FETCH_BLACK_LISTED_CONTENT_FAILED';
|
2019-07-09 16:20:01 +02:00
|
|
|
const BLACK_LISTED_CONTENT_SUBSCRIBE = 'BLACK_LISTED_CONTENT_SUBSCRIBE'; // Filtered list
|
|
|
|
|
|
|
|
const FETCH_FILTERED_CONTENT_STARTED = 'FETCH_FILTERED_CONTENT_STARTED';
|
|
|
|
const FETCH_FILTERED_CONTENT_COMPLETED = 'FETCH_FILTERED_CONTENT_COMPLETED';
|
|
|
|
const FETCH_FILTERED_CONTENT_FAILED = 'FETCH_FILTERED_CONTENT_FAILED';
|
|
|
|
const FILTERED_CONTENT_SUBSCRIBE = 'FILTERED_CONTENT_SUBSCRIBE'; // Cost Info
|
2019-04-03 23:34:07 +02:00
|
|
|
|
|
|
|
const FETCH_COST_INFO_STARTED = 'FETCH_COST_INFO_STARTED';
|
2019-09-25 04:30:53 +02:00
|
|
|
const FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED'; // Stats
|
2019-04-03 23:34:07 +02:00
|
|
|
|
|
|
|
const FETCH_VIEW_COUNT_STARTED = 'FETCH_VIEW_COUNT_STARTED';
|
|
|
|
const FETCH_VIEW_COUNT_FAILED = 'FETCH_VIEW_COUNT_FAILED';
|
2019-09-25 04:30:53 +02:00
|
|
|
const FETCH_VIEW_COUNT_COMPLETED = 'FETCH_VIEW_COUNT_COMPLETED';
|
|
|
|
const FETCH_SUB_COUNT_STARTED = 'FETCH_SUB_COUNT_STARTED';
|
|
|
|
const FETCH_SUB_COUNT_FAILED = 'FETCH_SUB_COUNT_FAILED';
|
|
|
|
const FETCH_SUB_COUNT_COMPLETED = 'FETCH_SUB_COUNT_COMPLETED'; // Cross-device Sync
|
2019-04-18 10:02:11 +02:00
|
|
|
|
|
|
|
const GET_SYNC_STARTED = 'GET_SYNC_STARTED';
|
|
|
|
const GET_SYNC_COMPLETED = 'GET_SYNC_COMPLETED';
|
2019-10-02 06:15:24 +02:00
|
|
|
const GET_SYNC_FAILED = 'GET_SYNC_FAILED';
|
2019-04-18 10:02:11 +02:00
|
|
|
const SET_SYNC_STARTED = 'SET_SYNC_STARTED';
|
|
|
|
const SET_SYNC_FAILED = 'SET_SYNC_FAILED';
|
|
|
|
const SET_SYNC_COMPLETED = 'SET_SYNC_COMPLETED';
|
2019-05-10 16:45:56 +02:00
|
|
|
const SET_DEFAULT_ACCOUNT = 'SET_DEFAULT_ACCOUNT';
|
2019-05-27 15:57:31 +02:00
|
|
|
const SYNC_APPLY_STARTED = 'SYNC_APPLY_STARTED';
|
|
|
|
const SYNC_APPLY_COMPLETED = 'SYNC_APPLY_COMPLETED';
|
2019-09-16 22:12:43 +02:00
|
|
|
const SYNC_APPLY_FAILED = 'SYNC_APPLY_FAILED';
|
2019-10-29 20:14:41 +01:00
|
|
|
const SYNC_APPLY_BAD_PASSWORD = 'SYNC_APPLY_BAD_PASSWORD';
|
2019-10-22 21:21:42 +02:00
|
|
|
const SYNC_RESET = 'SYNC_RESET'; // Lbry.tv
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const UPDATE_UPLOAD_PROGRESS = 'UPDATE_UPLOAD_PROGRESS'; // User
|
|
|
|
|
|
|
|
const GENERATE_AUTH_TOKEN_FAILURE = 'GENERATE_AUTH_TOKEN_FAILURE';
|
|
|
|
const GENERATE_AUTH_TOKEN_STARTED = 'GENERATE_AUTH_TOKEN_STARTED';
|
|
|
|
const GENERATE_AUTH_TOKEN_SUCCESS = 'GENERATE_AUTH_TOKEN_SUCCESS';
|
2019-04-03 23:34:07 +02:00
|
|
|
|
|
|
|
var action_types = /*#__PURE__*/Object.freeze({
|
|
|
|
FETCH_FEATURED_CONTENT_STARTED: FETCH_FEATURED_CONTENT_STARTED,
|
|
|
|
FETCH_FEATURED_CONTENT_COMPLETED: FETCH_FEATURED_CONTENT_COMPLETED,
|
|
|
|
FETCH_TRENDING_CONTENT_STARTED: FETCH_TRENDING_CONTENT_STARTED,
|
|
|
|
FETCH_TRENDING_CONTENT_COMPLETED: FETCH_TRENDING_CONTENT_COMPLETED,
|
|
|
|
RESOLVE_URIS_STARTED: RESOLVE_URIS_STARTED,
|
|
|
|
RESOLVE_URIS_COMPLETED: RESOLVE_URIS_COMPLETED,
|
|
|
|
FETCH_CHANNEL_CLAIMS_STARTED: FETCH_CHANNEL_CLAIMS_STARTED,
|
|
|
|
FETCH_CHANNEL_CLAIMS_COMPLETED: FETCH_CHANNEL_CLAIMS_COMPLETED,
|
|
|
|
FETCH_CHANNEL_CLAIM_COUNT_STARTED: FETCH_CHANNEL_CLAIM_COUNT_STARTED,
|
|
|
|
FETCH_CHANNEL_CLAIM_COUNT_COMPLETED: FETCH_CHANNEL_CLAIM_COUNT_COMPLETED,
|
|
|
|
FETCH_CLAIM_LIST_MINE_STARTED: FETCH_CLAIM_LIST_MINE_STARTED,
|
|
|
|
FETCH_CLAIM_LIST_MINE_COMPLETED: FETCH_CLAIM_LIST_MINE_COMPLETED,
|
|
|
|
ABANDON_CLAIM_STARTED: ABANDON_CLAIM_STARTED,
|
|
|
|
ABANDON_CLAIM_SUCCEEDED: ABANDON_CLAIM_SUCCEEDED,
|
|
|
|
FETCH_CHANNEL_LIST_STARTED: FETCH_CHANNEL_LIST_STARTED,
|
|
|
|
FETCH_CHANNEL_LIST_COMPLETED: FETCH_CHANNEL_LIST_COMPLETED,
|
|
|
|
CREATE_CHANNEL_STARTED: CREATE_CHANNEL_STARTED,
|
|
|
|
CREATE_CHANNEL_COMPLETED: CREATE_CHANNEL_COMPLETED,
|
|
|
|
PUBLISH_STARTED: PUBLISH_STARTED,
|
|
|
|
PUBLISH_COMPLETED: PUBLISH_COMPLETED,
|
|
|
|
PUBLISH_FAILED: PUBLISH_FAILED,
|
|
|
|
SET_PLAYING_URI: SET_PLAYING_URI,
|
|
|
|
SET_CONTENT_POSITION: SET_CONTENT_POSITION,
|
|
|
|
SET_CONTENT_LAST_VIEWED: SET_CONTENT_LAST_VIEWED,
|
|
|
|
CLEAR_CONTENT_HISTORY_URI: CLEAR_CONTENT_HISTORY_URI,
|
|
|
|
CLEAR_CONTENT_HISTORY_ALL: CLEAR_CONTENT_HISTORY_ALL,
|
|
|
|
CHANNEL_SUBSCRIBE: CHANNEL_SUBSCRIBE,
|
|
|
|
CHANNEL_UNSUBSCRIBE: CHANNEL_UNSUBSCRIBE,
|
|
|
|
CHANNEL_SUBSCRIPTION_ENABLE_NOTIFICATIONS: CHANNEL_SUBSCRIPTION_ENABLE_NOTIFICATIONS,
|
|
|
|
CHANNEL_SUBSCRIPTION_DISABLE_NOTIFICATIONS: CHANNEL_SUBSCRIPTION_DISABLE_NOTIFICATIONS,
|
|
|
|
HAS_FETCHED_SUBSCRIPTIONS: HAS_FETCHED_SUBSCRIPTIONS,
|
|
|
|
SET_SUBSCRIPTION_LATEST: SET_SUBSCRIPTION_LATEST,
|
|
|
|
UPDATE_SUBSCRIPTION_UNREADS: UPDATE_SUBSCRIPTION_UNREADS,
|
|
|
|
REMOVE_SUBSCRIPTION_UNREADS: REMOVE_SUBSCRIPTION_UNREADS,
|
|
|
|
CHECK_SUBSCRIPTION_STARTED: CHECK_SUBSCRIPTION_STARTED,
|
|
|
|
CHECK_SUBSCRIPTION_COMPLETED: CHECK_SUBSCRIPTION_COMPLETED,
|
|
|
|
CHECK_SUBSCRIPTIONS_SUBSCRIBE: CHECK_SUBSCRIPTIONS_SUBSCRIBE,
|
|
|
|
FETCH_SUBSCRIPTIONS_START: FETCH_SUBSCRIPTIONS_START,
|
|
|
|
FETCH_SUBSCRIPTIONS_FAIL: FETCH_SUBSCRIPTIONS_FAIL,
|
|
|
|
FETCH_SUBSCRIPTIONS_SUCCESS: FETCH_SUBSCRIPTIONS_SUCCESS,
|
|
|
|
SET_VIEW_MODE: SET_VIEW_MODE,
|
|
|
|
GET_SUGGESTED_SUBSCRIPTIONS_START: GET_SUGGESTED_SUBSCRIPTIONS_START,
|
|
|
|
GET_SUGGESTED_SUBSCRIPTIONS_SUCCESS: GET_SUGGESTED_SUBSCRIPTIONS_SUCCESS,
|
|
|
|
GET_SUGGESTED_SUBSCRIPTIONS_FAIL: GET_SUGGESTED_SUBSCRIPTIONS_FAIL,
|
|
|
|
SUBSCRIPTION_FIRST_RUN_COMPLETED: SUBSCRIPTION_FIRST_RUN_COMPLETED,
|
|
|
|
VIEW_SUGGESTED_SUBSCRIPTIONS: VIEW_SUGGESTED_SUBSCRIPTIONS,
|
|
|
|
FETCH_BLACK_LISTED_CONTENT_STARTED: FETCH_BLACK_LISTED_CONTENT_STARTED,
|
|
|
|
FETCH_BLACK_LISTED_CONTENT_COMPLETED: FETCH_BLACK_LISTED_CONTENT_COMPLETED,
|
|
|
|
FETCH_BLACK_LISTED_CONTENT_FAILED: FETCH_BLACK_LISTED_CONTENT_FAILED,
|
|
|
|
BLACK_LISTED_CONTENT_SUBSCRIBE: BLACK_LISTED_CONTENT_SUBSCRIBE,
|
2019-07-09 16:20:01 +02:00
|
|
|
FETCH_FILTERED_CONTENT_STARTED: FETCH_FILTERED_CONTENT_STARTED,
|
|
|
|
FETCH_FILTERED_CONTENT_COMPLETED: FETCH_FILTERED_CONTENT_COMPLETED,
|
|
|
|
FETCH_FILTERED_CONTENT_FAILED: FETCH_FILTERED_CONTENT_FAILED,
|
|
|
|
FILTERED_CONTENT_SUBSCRIBE: FILTERED_CONTENT_SUBSCRIBE,
|
2019-04-03 23:34:07 +02:00
|
|
|
FETCH_COST_INFO_STARTED: FETCH_COST_INFO_STARTED,
|
|
|
|
FETCH_COST_INFO_COMPLETED: FETCH_COST_INFO_COMPLETED,
|
|
|
|
FETCH_VIEW_COUNT_STARTED: FETCH_VIEW_COUNT_STARTED,
|
|
|
|
FETCH_VIEW_COUNT_FAILED: FETCH_VIEW_COUNT_FAILED,
|
2019-04-18 10:02:11 +02:00
|
|
|
FETCH_VIEW_COUNT_COMPLETED: FETCH_VIEW_COUNT_COMPLETED,
|
2019-09-25 04:30:53 +02:00
|
|
|
FETCH_SUB_COUNT_STARTED: FETCH_SUB_COUNT_STARTED,
|
|
|
|
FETCH_SUB_COUNT_FAILED: FETCH_SUB_COUNT_FAILED,
|
|
|
|
FETCH_SUB_COUNT_COMPLETED: FETCH_SUB_COUNT_COMPLETED,
|
2019-04-18 10:02:11 +02:00
|
|
|
GET_SYNC_STARTED: GET_SYNC_STARTED,
|
|
|
|
GET_SYNC_COMPLETED: GET_SYNC_COMPLETED,
|
2019-10-02 06:15:24 +02:00
|
|
|
GET_SYNC_FAILED: GET_SYNC_FAILED,
|
2019-04-18 10:02:11 +02:00
|
|
|
SET_SYNC_STARTED: SET_SYNC_STARTED,
|
|
|
|
SET_SYNC_FAILED: SET_SYNC_FAILED,
|
2019-05-10 16:45:56 +02:00
|
|
|
SET_SYNC_COMPLETED: SET_SYNC_COMPLETED,
|
2019-05-27 15:57:31 +02:00
|
|
|
SET_DEFAULT_ACCOUNT: SET_DEFAULT_ACCOUNT,
|
|
|
|
SYNC_APPLY_STARTED: SYNC_APPLY_STARTED,
|
|
|
|
SYNC_APPLY_COMPLETED: SYNC_APPLY_COMPLETED,
|
2019-10-02 22:22:51 +02:00
|
|
|
SYNC_APPLY_FAILED: SYNC_APPLY_FAILED,
|
2019-10-29 20:14:41 +01:00
|
|
|
SYNC_APPLY_BAD_PASSWORD: SYNC_APPLY_BAD_PASSWORD,
|
2019-10-22 21:21:42 +02:00
|
|
|
SYNC_RESET: SYNC_RESET,
|
2020-06-15 22:29:48 +02:00
|
|
|
UPDATE_UPLOAD_PROGRESS: UPDATE_UPLOAD_PROGRESS,
|
|
|
|
GENERATE_AUTH_TOKEN_FAILURE: GENERATE_AUTH_TOKEN_FAILURE,
|
|
|
|
GENERATE_AUTH_TOKEN_STARTED: GENERATE_AUTH_TOKEN_STARTED,
|
|
|
|
GENERATE_AUTH_TOKEN_SUCCESS: GENERATE_AUTH_TOKEN_SUCCESS
|
2019-04-03 23:34:07 +02:00
|
|
|
});
|
|
|
|
|
2019-10-02 06:15:24 +02:00
|
|
|
const NOT_TRANSFERRED = 'not_transferred';
|
|
|
|
const PENDING_TRANSFER = 'pending_transfer';
|
|
|
|
const COMPLETED_TRANSFER = 'completed_transfer';
|
|
|
|
|
|
|
|
var youtube = /*#__PURE__*/Object.freeze({
|
|
|
|
NOT_TRANSFERRED: NOT_TRANSFERRED,
|
|
|
|
PENDING_TRANSFER: PENDING_TRANSFER,
|
|
|
|
COMPLETED_TRANSFER: COMPLETED_TRANSFER
|
|
|
|
});
|
|
|
|
|
2020-01-10 04:28:46 +01:00
|
|
|
const ALREADY_CLAIMED = 'once the invite reward has been claimed the referrer cannot be changed';
|
|
|
|
const REFERRER_NOT_FOUND = 'A lbry.tv account could not be found for the referrer you provided.';
|
|
|
|
|
|
|
|
var errors = /*#__PURE__*/Object.freeze({
|
|
|
|
ALREADY_CLAIMED: ALREADY_CLAIMED,
|
|
|
|
REFERRER_NOT_FOUND: REFERRER_NOT_FOUND
|
|
|
|
});
|
|
|
|
|
2019-04-03 23:34:07 +02:00
|
|
|
const Lbryio = {
|
|
|
|
enabled: true,
|
|
|
|
authenticationPromise: null,
|
|
|
|
exchangePromise: null,
|
|
|
|
exchangeLastFetched: null,
|
|
|
|
CONNECTION_STRING: 'https://api.lbry.com/'
|
|
|
|
};
|
|
|
|
const EXCHANGE_RATE_TIMEOUT = 20 * 60 * 1000; // We can't use env's because they aren't passed into node_modules
|
|
|
|
|
|
|
|
Lbryio.setLocalApi = endpoint => {
|
|
|
|
Lbryio.CONNECTION_STRING = endpoint.replace(/\/*$/, '/'); // exactly one slash at the end;
|
|
|
|
};
|
|
|
|
|
|
|
|
Lbryio.call = (resource, action, params = {}, method = 'get') => {
|
|
|
|
if (!Lbryio.enabled) {
|
|
|
|
return Promise.reject(new Error(__('LBRY internal API is disabled')));
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Lbryio.getAuthToken().then(token => {
|
|
|
|
const fullParams = {
|
|
|
|
auth_token: token,
|
|
|
|
...params
|
|
|
|
};
|
2019-09-13 16:38:40 +02:00
|
|
|
Object.keys(fullParams).forEach(key => {
|
|
|
|
const value = fullParams[key];
|
|
|
|
|
|
|
|
if (typeof value === 'object') {
|
|
|
|
fullParams[key] = JSON.stringify(value);
|
|
|
|
}
|
|
|
|
});
|
2019-04-03 23:34:07 +02:00
|
|
|
const qs = querystring.stringify(fullParams);
|
|
|
|
let url = `${Lbryio.CONNECTION_STRING}${resource}/${action}?${qs}`;
|
|
|
|
let options = {
|
|
|
|
method: 'GET'
|
|
|
|
};
|
|
|
|
|
|
|
|
if (method === 'post') {
|
|
|
|
options = {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
},
|
|
|
|
body: qs
|
|
|
|
};
|
|
|
|
url = `${Lbryio.CONNECTION_STRING}${resource}/${action}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return makeRequest(url, options).then(response => response.data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Lbryio.authToken = null;
|
|
|
|
|
|
|
|
Lbryio.getAuthToken = () => new Promise(resolve => {
|
|
|
|
if (Lbryio.authToken) {
|
|
|
|
resolve(Lbryio.authToken);
|
|
|
|
} else if (Lbryio.overrides.getAuthToken) {
|
|
|
|
Lbryio.overrides.getAuthToken().then(token => {
|
|
|
|
resolve(token);
|
|
|
|
});
|
2020-04-08 18:17:40 +02:00
|
|
|
} else if (typeof window !== 'undefined') {
|
2019-04-03 23:34:07 +02:00
|
|
|
const {
|
|
|
|
store
|
|
|
|
} = window;
|
|
|
|
|
|
|
|
if (store) {
|
|
|
|
const state = store.getState();
|
|
|
|
const token = state.auth ? state.auth.authToken : null;
|
|
|
|
Lbryio.authToken = token;
|
|
|
|
resolve(token);
|
|
|
|
}
|
|
|
|
|
2020-04-08 18:17:40 +02:00
|
|
|
resolve(null);
|
|
|
|
} else {
|
2019-04-03 23:34:07 +02:00
|
|
|
resolve(null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Lbryio.getCurrentUser = () => Lbryio.call('user', 'me');
|
|
|
|
|
|
|
|
Lbryio.authenticate = () => {
|
|
|
|
if (!Lbryio.enabled) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
resolve({
|
|
|
|
id: 1,
|
|
|
|
language: 'en',
|
|
|
|
primary_email: 'disabled@lbry.io',
|
|
|
|
has_verified_email: true,
|
|
|
|
is_identity_verified: true,
|
|
|
|
is_reward_approved: false
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Lbryio.authenticationPromise === null) {
|
|
|
|
Lbryio.authenticationPromise = new Promise((resolve, reject) => {
|
|
|
|
Lbryio.getAuthToken().then(token => {
|
|
|
|
if (!token || token.length > 60) {
|
|
|
|
return false;
|
|
|
|
} // check that token works
|
|
|
|
|
|
|
|
|
|
|
|
return Lbryio.getCurrentUser().then(user => user).catch(() => false);
|
|
|
|
}).then(user => {
|
|
|
|
if (user) {
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lbryRedux.Lbry.status().then(status => {
|
|
|
|
if (Lbryio.overrides.setAuthToken) {
|
|
|
|
return Lbryio.overrides.setAuthToken(status);
|
|
|
|
} // simply call the logic to create a new user, and obtain the auth token
|
|
|
|
|
|
|
|
|
|
|
|
return new Promise((res, rej) => {
|
|
|
|
Lbryio.call('user', 'new', {
|
|
|
|
auth_token: '',
|
|
|
|
language: 'en',
|
|
|
|
app_id: status.installation_id
|
|
|
|
}, 'post').then(response => {
|
|
|
|
if (!response.auth_token) {
|
|
|
|
throw new Error('auth_token was not set in the response');
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
|
|
|
store
|
|
|
|
} = window;
|
|
|
|
|
|
|
|
if (store) {
|
|
|
|
store.dispatch({
|
|
|
|
type: GENERATE_AUTH_TOKEN_SUCCESS,
|
|
|
|
data: {
|
|
|
|
authToken: response.auth_token
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Lbryio.authToken = response.auth_token;
|
|
|
|
res(response);
|
2019-04-18 10:02:11 +02:00
|
|
|
}).catch(error => rej(error));
|
2019-04-03 23:34:07 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}).then(user => {
|
|
|
|
if (!user) {
|
|
|
|
return Lbryio.getCurrentUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
return user;
|
|
|
|
}).then(resolve, reject);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return Lbryio.authenticationPromise;
|
|
|
|
};
|
|
|
|
|
|
|
|
Lbryio.getStripeToken = () => Lbryio.CONNECTION_STRING.startsWith('http://localhost:') ? 'pk_test_NoL1JWL7i1ipfhVId5KfDZgo' : 'pk_live_e8M4dRNnCCbmpZzduEUZBgJO';
|
|
|
|
|
|
|
|
Lbryio.getExchangeRates = () => {
|
|
|
|
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
|
|
|
|
}) => {
|
|
|
|
const rates = {
|
|
|
|
LBC_USD,
|
|
|
|
LBC_BTC,
|
|
|
|
BTC_USD
|
|
|
|
};
|
|
|
|
resolve(rates);
|
|
|
|
}).catch(reject);
|
|
|
|
});
|
|
|
|
Lbryio.exchangeLastFetched = Date.now();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Lbryio.exchangePromise;
|
|
|
|
}; // Allow overriding lbryio methods
|
|
|
|
// The desktop app will need to use it for getAuthToken because we use electron's ipcRenderer
|
|
|
|
|
|
|
|
|
|
|
|
Lbryio.overrides = {};
|
|
|
|
|
|
|
|
Lbryio.setOverride = (methodName, newMethod) => {
|
|
|
|
Lbryio.overrides[methodName] = newMethod;
|
|
|
|
};
|
|
|
|
|
2019-12-05 13:13:10 +01:00
|
|
|
const apiBaseUrl = 'https://www.transifex.com/api/2/project';
|
|
|
|
const resource = 'app-strings';
|
|
|
|
function doTransifexUpload(contents, project, token, success, fail) {
|
|
|
|
const url = `${apiBaseUrl}/${project}/resources/`;
|
|
|
|
const updateUrl = `${apiBaseUrl}/${project}/resource/${resource}/content/`;
|
|
|
|
const headers = {
|
|
|
|
Authorization: `Basic ${Buffer.from(`api:${token}`).toString('base64')}`,
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
};
|
|
|
|
const req = {
|
|
|
|
accept_translations: true,
|
|
|
|
i18n_type: 'KEYVALUEJSON',
|
|
|
|
name: resource,
|
|
|
|
slug: resource,
|
|
|
|
content: contents
|
|
|
|
};
|
|
|
|
|
|
|
|
function handleResponse(text) {
|
|
|
|
let json;
|
|
|
|
|
|
|
|
try {
|
|
|
|
// transifex api returns Python dicts for some reason.
|
|
|
|
// Any way to get the api to return valid JSON?
|
|
|
|
json = JSON.parse(text);
|
|
|
|
} catch (e) {// ignore
|
|
|
|
}
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
success(json || text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleError(err) {
|
|
|
|
if (fail) {
|
|
|
|
fail(err.message ? err.message : 'Could not upload strings resource to Transifex');
|
|
|
|
}
|
|
|
|
} // check if the resource exists
|
|
|
|
|
|
|
|
|
|
|
|
fetch(updateUrl, {
|
|
|
|
headers
|
|
|
|
}).then(response => response.json()).then(() => {
|
|
|
|
// perform an update
|
|
|
|
fetch(updateUrl, {
|
|
|
|
method: 'PUT',
|
|
|
|
headers,
|
|
|
|
body: JSON.stringify({
|
|
|
|
content: contents
|
|
|
|
})
|
|
|
|
}).then(response => {
|
|
|
|
if (response.status !== 200 && response.status !== 201) {
|
|
|
|
throw new Error('failed to update transifex');
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.text();
|
|
|
|
}).then(handleResponse).catch(handleError);
|
|
|
|
}).catch(() => {
|
|
|
|
// resource doesn't exist, create a fresh resource
|
|
|
|
fetch(url, {
|
|
|
|
method: 'POST',
|
|
|
|
headers,
|
|
|
|
body: JSON.stringify(req)
|
|
|
|
}).then(response => {
|
2020-06-15 22:29:48 +02:00
|
|
|
if (response.status !== 200 && response.status !== 201) {
|
|
|
|
throw new Error('failed to upload to transifex');
|
|
|
|
}
|
2019-04-03 23:34:07 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
return response.text();
|
|
|
|
}).then(handleResponse).catch(handleError);
|
2019-04-03 23:34:07 +02:00
|
|
|
});
|
2020-06-15 22:29:48 +02:00
|
|
|
}
|
2019-04-03 23:34:07 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
function doGenerateAuthToken(installationId) {
|
|
|
|
return dispatch => {
|
2019-04-03 23:34:07 +02:00
|
|
|
dispatch({
|
2020-06-15 22:29:48 +02:00
|
|
|
type: GENERATE_AUTH_TOKEN_STARTED
|
2019-04-03 23:34:07 +02:00
|
|
|
});
|
2020-06-15 22:29:48 +02:00
|
|
|
Lbryio.call('user', 'new', {
|
|
|
|
auth_token: '',
|
|
|
|
language: 'en',
|
|
|
|
app_id: installationId
|
|
|
|
}, 'post').then(response => {
|
|
|
|
if (!response.auth_token) {
|
|
|
|
dispatch({
|
|
|
|
type: GENERATE_AUTH_TOKEN_FAILURE
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
dispatch({
|
|
|
|
type: GENERATE_AUTH_TOKEN_SUCCESS,
|
|
|
|
data: {
|
|
|
|
authToken: response.auth_token
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}).catch(() => {
|
|
|
|
dispatch({
|
|
|
|
type: GENERATE_AUTH_TOKEN_FAILURE
|
|
|
|
});
|
2019-04-03 23:34:07 +02:00
|
|
|
});
|
2020-06-15 22:29:48 +02:00
|
|
|
};
|
|
|
|
}
|
2019-04-03 23:34:07 +02:00
|
|
|
|
|
|
|
function doFetchCostInfoForUri(uri) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const state = getState();
|
|
|
|
const claim = lbryRedux.selectClaimsByUri(state)[uri];
|
|
|
|
if (!claim) return;
|
|
|
|
|
|
|
|
function resolve(costInfo) {
|
|
|
|
dispatch({
|
|
|
|
type: FETCH_COST_INFO_COMPLETED,
|
|
|
|
data: {
|
|
|
|
uri,
|
|
|
|
costInfo
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-22 23:24:03 +02:00
|
|
|
const fee = claim.value ? claim.value.fee : undefined;
|
2019-04-03 23:34:07 +02:00
|
|
|
|
|
|
|
if (fee === undefined) {
|
|
|
|
resolve({
|
|
|
|
cost: 0,
|
|
|
|
includesData: true
|
|
|
|
});
|
|
|
|
} else if (fee.currency === 'LBC') {
|
|
|
|
resolve({
|
|
|
|
cost: fee.amount,
|
|
|
|
includesData: true
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Lbryio.getExchangeRates().then(({
|
|
|
|
LBC_USD
|
|
|
|
}) => {
|
|
|
|
resolve({
|
|
|
|
cost: fee.amount / LBC_USD,
|
|
|
|
includesData: true
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const CHECK_BLACK_LISTED_CONTENT_INTERVAL = 60 * 60 * 1000;
|
|
|
|
function doFetchBlackListedOutpoints() {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch({
|
|
|
|
type: FETCH_BLACK_LISTED_CONTENT_STARTED
|
|
|
|
});
|
|
|
|
|
|
|
|
const success = ({
|
|
|
|
outpoints
|
|
|
|
}) => {
|
2020-01-03 20:06:35 +01:00
|
|
|
const splitOutpoints = [];
|
|
|
|
|
|
|
|
if (outpoints) {
|
|
|
|
outpoints.forEach((outpoint, index) => {
|
|
|
|
const [txid, nout] = outpoint.split(':');
|
|
|
|
splitOutpoints[index] = {
|
|
|
|
txid,
|
|
|
|
nout: Number.parseInt(nout, 10)
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-03 23:34:07 +02:00
|
|
|
dispatch({
|
|
|
|
type: FETCH_BLACK_LISTED_CONTENT_COMPLETED,
|
|
|
|
data: {
|
2020-01-03 20:06:35 +01:00
|
|
|
outpoints: splitOutpoints,
|
2019-04-03 23:34:07 +02:00
|
|
|
success: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const failure = ({
|
|
|
|
error
|
|
|
|
}) => {
|
|
|
|
dispatch({
|
|
|
|
type: FETCH_BLACK_LISTED_CONTENT_FAILED,
|
|
|
|
data: {
|
|
|
|
error,
|
|
|
|
success: false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Lbryio.call('file', 'list_blocked').then(success, failure);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function doBlackListedOutpointsSubscribe() {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(doFetchBlackListedOutpoints());
|
|
|
|
setInterval(() => dispatch(doFetchBlackListedOutpoints()), CHECK_BLACK_LISTED_CONTENT_INTERVAL);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-07-09 16:20:01 +02:00
|
|
|
const CHECK_FILTERED_CONTENT_INTERVAL = 60 * 60 * 1000;
|
|
|
|
function doFetchFilteredOutpoints() {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch({
|
|
|
|
type: FETCH_FILTERED_CONTENT_STARTED
|
|
|
|
});
|
|
|
|
|
|
|
|
const success = ({
|
|
|
|
outpoints
|
|
|
|
}) => {
|
2020-01-03 20:06:35 +01:00
|
|
|
let formattedOutpoints = [];
|
|
|
|
|
|
|
|
if (outpoints) {
|
|
|
|
formattedOutpoints = outpoints.map(outpoint => {
|
|
|
|
const [txid, nout] = outpoint.split(':');
|
|
|
|
return {
|
|
|
|
txid,
|
|
|
|
nout: Number.parseInt(nout, 10)
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-09 16:20:01 +02:00
|
|
|
dispatch({
|
|
|
|
type: FETCH_FILTERED_CONTENT_COMPLETED,
|
|
|
|
data: {
|
2019-07-11 02:44:15 +02:00
|
|
|
outpoints: formattedOutpoints
|
2019-07-09 16:20:01 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const failure = ({
|
|
|
|
error
|
|
|
|
}) => {
|
|
|
|
dispatch({
|
|
|
|
type: FETCH_FILTERED_CONTENT_FAILED,
|
|
|
|
data: {
|
2019-07-11 02:44:15 +02:00
|
|
|
error
|
2019-07-09 16:20:01 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Lbryio.call('file', 'list_filtered').then(success, failure);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function doFilteredOutpointsSubscribe() {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch(doFetchFilteredOutpoints());
|
|
|
|
setInterval(() => dispatch(doFetchFilteredOutpoints()), CHECK_FILTERED_CONTENT_INTERVAL);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-04-03 23:34:07 +02:00
|
|
|
function doFetchFeaturedUris(offloadResolve = false) {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch({
|
|
|
|
type: FETCH_FEATURED_CONTENT_STARTED
|
|
|
|
});
|
|
|
|
|
|
|
|
const success = ({
|
|
|
|
Uris
|
|
|
|
}) => {
|
|
|
|
let urisToResolve = [];
|
|
|
|
Object.keys(Uris).forEach(category => {
|
|
|
|
urisToResolve = [...urisToResolve, ...Uris[category]];
|
|
|
|
});
|
|
|
|
const actions = [{
|
|
|
|
type: FETCH_FEATURED_CONTENT_COMPLETED,
|
|
|
|
data: {
|
|
|
|
uris: Uris,
|
|
|
|
success: true
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
|
|
|
|
if (urisToResolve.length && !offloadResolve) {
|
|
|
|
actions.push(lbryRedux.doResolveUris(urisToResolve));
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(lbryRedux.batchActions(...actions));
|
|
|
|
};
|
|
|
|
|
|
|
|
const failure = () => {
|
|
|
|
dispatch({
|
|
|
|
type: FETCH_FEATURED_CONTENT_COMPLETED,
|
|
|
|
data: {
|
|
|
|
uris: {}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Lbryio.call('file', 'list_homepage').then(success, failure);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function doFetchTrendingUris() {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch({
|
|
|
|
type: FETCH_TRENDING_CONTENT_STARTED
|
|
|
|
});
|
|
|
|
|
|
|
|
const success = data => {
|
|
|
|
const urisToResolve = data.map(uri => uri.url);
|
|
|
|
const actions = [lbryRedux.doResolveUris(urisToResolve), {
|
|
|
|
type: FETCH_TRENDING_CONTENT_COMPLETED,
|
|
|
|
data: {
|
|
|
|
uris: data,
|
|
|
|
success: true
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
dispatch(lbryRedux.batchActions(...actions));
|
|
|
|
};
|
|
|
|
|
|
|
|
const failure = () => {
|
|
|
|
dispatch({
|
|
|
|
type: FETCH_TRENDING_CONTENT_COMPLETED,
|
|
|
|
data: {
|
|
|
|
uris: []
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Lbryio.call('file', 'list_trending').then(success, failure);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
const doFetchViewCount = claimId => dispatch => {
|
|
|
|
dispatch({
|
|
|
|
type: FETCH_VIEW_COUNT_STARTED
|
|
|
|
});
|
|
|
|
return Lbryio.call('file', 'view_count', {
|
|
|
|
claim_id: claimId
|
|
|
|
}).then(result => {
|
|
|
|
const viewCount = result[0];
|
|
|
|
dispatch({
|
|
|
|
type: FETCH_VIEW_COUNT_COMPLETED,
|
|
|
|
data: {
|
|
|
|
claimId,
|
|
|
|
viewCount
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({
|
|
|
|
type: FETCH_VIEW_COUNT_FAILED,
|
|
|
|
data: error
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2019-09-25 04:30:53 +02:00
|
|
|
const doFetchSubCount = claimId => dispatch => {
|
|
|
|
dispatch({
|
|
|
|
type: FETCH_SUB_COUNT_STARTED
|
|
|
|
});
|
|
|
|
return Lbryio.call('subscription', 'sub_count', {
|
|
|
|
claim_id: claimId
|
|
|
|
}).then(result => {
|
|
|
|
const subCount = result[0];
|
|
|
|
dispatch({
|
|
|
|
type: FETCH_SUB_COUNT_COMPLETED,
|
|
|
|
data: {
|
|
|
|
claimId,
|
|
|
|
subCount
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({
|
|
|
|
type: FETCH_SUB_COUNT_FAILED,
|
|
|
|
data: error
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2019-04-03 23:34:07 +02:00
|
|
|
|
2019-09-06 17:19:17 +02:00
|
|
|
function doSetDefaultAccount(success, failure) {
|
2019-05-10 16:45:56 +02:00
|
|
|
return dispatch => {
|
|
|
|
dispatch({
|
|
|
|
type: SET_DEFAULT_ACCOUNT
|
|
|
|
});
|
|
|
|
lbryRedux.Lbry.account_list().then(accountList => {
|
|
|
|
const {
|
|
|
|
lbc_mainnet: accounts
|
|
|
|
} = accountList;
|
|
|
|
let defaultId;
|
|
|
|
|
2019-05-27 15:57:31 +02:00
|
|
|
for (let i = 0; i < accounts.length; ++i) {
|
2019-05-10 16:45:56 +02:00
|
|
|
if (accounts[i].satoshis > 0) {
|
|
|
|
defaultId = accounts[i].id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} // In a case where there's no balance on either account
|
|
|
|
// assume the second (which is created after sync) as default
|
|
|
|
|
|
|
|
|
|
|
|
if (!defaultId && accounts.length > 1) {
|
|
|
|
defaultId = accounts[1].id;
|
|
|
|
} // Set the default account
|
|
|
|
|
|
|
|
|
|
|
|
if (defaultId) {
|
|
|
|
lbryRedux.Lbry.account_set({
|
|
|
|
account_id: defaultId,
|
|
|
|
default: true
|
2019-09-06 17:19:17 +02:00
|
|
|
}).then(() => {
|
|
|
|
if (success) {
|
|
|
|
success();
|
|
|
|
}
|
|
|
|
}).catch(err => {
|
|
|
|
if (failure) {
|
|
|
|
failure(err);
|
|
|
|
}
|
2019-05-10 16:45:56 +02:00
|
|
|
});
|
2019-10-02 06:15:24 +02:00
|
|
|
} else if (failure) {
|
2019-09-06 17:19:17 +02:00
|
|
|
// no default account to set
|
2019-10-02 06:15:24 +02:00
|
|
|
failure('Could not set a default account'); // fail
|
2019-09-06 17:19:17 +02:00
|
|
|
}
|
|
|
|
}).catch(err => {
|
|
|
|
if (failure) {
|
|
|
|
failure(err);
|
2019-05-10 16:45:56 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2019-10-04 18:52:28 +02:00
|
|
|
function doSetSync(oldHash, newHash, data) {
|
2019-10-02 06:15:24 +02:00
|
|
|
return dispatch => {
|
|
|
|
dispatch({
|
|
|
|
type: SET_SYNC_STARTED
|
|
|
|
});
|
2019-10-04 18:52:28 +02:00
|
|
|
return Lbryio.call('sync', 'set', {
|
2019-10-02 06:15:24 +02:00
|
|
|
old_hash: oldHash,
|
|
|
|
new_hash: newHash,
|
|
|
|
data
|
|
|
|
}, 'post').then(response => {
|
|
|
|
if (!response.hash) {
|
2019-10-04 18:52:28 +02:00
|
|
|
throw Error('No hash returned for sync/set.');
|
2019-10-02 06:15:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return dispatch({
|
|
|
|
type: SET_SYNC_COMPLETED,
|
|
|
|
data: {
|
|
|
|
syncHash: response.hash
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}).catch(error => {
|
|
|
|
dispatch({
|
|
|
|
type: SET_SYNC_FAILED,
|
|
|
|
data: {
|
|
|
|
error
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2019-10-15 05:21:17 +02:00
|
|
|
function doGetSync(passedPassword, callback) {
|
|
|
|
const password = passedPassword === null || passedPassword === undefined ? '' : passedPassword;
|
|
|
|
|
2020-03-19 18:49:47 +01:00
|
|
|
function handleCallback(error, hasNewData) {
|
2019-10-15 05:07:41 +02:00
|
|
|
if (callback) {
|
|
|
|
if (typeof callback !== 'function') {
|
|
|
|
throw new Error('Second argument passed to "doGetSync" must be a function');
|
|
|
|
}
|
|
|
|
|
2020-03-19 18:49:47 +01:00
|
|
|
callback(error, hasNewData);
|
2019-10-15 05:07:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-18 10:02:11 +02:00
|
|
|
return dispatch => {
|
|
|
|
dispatch({
|
|
|
|
type: GET_SYNC_STARTED
|
|
|
|
});
|
2019-10-02 06:15:24 +02:00
|
|
|
const data = {};
|
2019-10-16 05:35:03 +02:00
|
|
|
lbryRedux.Lbry.wallet_status().then(status => {
|
|
|
|
if (status.is_locked) {
|
|
|
|
return lbryRedux.Lbry.wallet_unlock({
|
|
|
|
password
|
|
|
|
});
|
2020-01-23 23:11:07 +01:00
|
|
|
} // Wallet is already unlocked
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}).then(isUnlocked => {
|
|
|
|
if (isUnlocked) {
|
|
|
|
return lbryRedux.Lbry.sync_hash();
|
2019-10-16 05:35:03 +02:00
|
|
|
}
|
2020-01-23 23:11:07 +01:00
|
|
|
|
|
|
|
data.unlockFailed = true;
|
|
|
|
throw new Error();
|
|
|
|
}).then(hash => Lbryio.call('sync', 'get', {
|
2019-10-16 05:35:03 +02:00
|
|
|
hash
|
|
|
|
}, 'post')).then(response => {
|
|
|
|
const syncHash = response.hash;
|
|
|
|
data.syncHash = syncHash;
|
|
|
|
data.syncData = response.data;
|
2020-03-19 18:49:47 +01:00
|
|
|
data.changed = response.changed;
|
2019-10-16 05:35:03 +02:00
|
|
|
data.hasSyncedWallet = true;
|
|
|
|
|
|
|
|
if (response.changed) {
|
|
|
|
return lbryRedux.Lbry.sync_apply({
|
|
|
|
password,
|
2020-01-07 23:01:26 +01:00
|
|
|
data: response.data,
|
|
|
|
blocking: true
|
2019-10-16 05:35:03 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}).then(response => {
|
|
|
|
if (!response) {
|
|
|
|
dispatch({
|
|
|
|
type: GET_SYNC_COMPLETED,
|
|
|
|
data
|
|
|
|
});
|
2020-03-19 18:49:47 +01:00
|
|
|
handleCallback(null, data.changed);
|
2019-10-16 05:35:03 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-10-02 06:15:24 +02:00
|
|
|
|
2019-10-16 05:35:03 +02:00
|
|
|
const {
|
|
|
|
hash: walletHash,
|
|
|
|
data: walletData
|
|
|
|
} = response;
|
|
|
|
|
|
|
|
if (walletHash !== data.syncHash) {
|
|
|
|
// different local hash, need to synchronise
|
|
|
|
dispatch(doSetSync(data.syncHash, walletHash, walletData));
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: GET_SYNC_COMPLETED,
|
|
|
|
data
|
2019-04-18 10:02:11 +02:00
|
|
|
});
|
2020-03-19 18:49:47 +01:00
|
|
|
handleCallback(null, data.changed);
|
2020-01-23 23:11:07 +01:00
|
|
|
}).catch(syncAttemptError => {
|
|
|
|
if (data.unlockFailed) {
|
|
|
|
dispatch({
|
|
|
|
type: GET_SYNC_FAILED,
|
|
|
|
data: {
|
|
|
|
error: syncAttemptError
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (password !== '') {
|
|
|
|
dispatch({
|
|
|
|
type: SYNC_APPLY_BAD_PASSWORD
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCallback(syncAttemptError);
|
|
|
|
} else if (data.hasSyncedWallet) {
|
2019-10-16 05:35:03 +02:00
|
|
|
const error = 'Error getting synced wallet';
|
|
|
|
dispatch({
|
|
|
|
type: GET_SYNC_FAILED,
|
|
|
|
data: {
|
|
|
|
error
|
|
|
|
}
|
2019-10-29 20:14:41 +01:00
|
|
|
}); // Temp solution until we have a bad password error code
|
|
|
|
// Don't fail on blank passwords so we don't show a "password error" message
|
|
|
|
// before users have ever entered a password
|
|
|
|
|
|
|
|
if (password !== '') {
|
|
|
|
dispatch({
|
|
|
|
type: SYNC_APPLY_BAD_PASSWORD
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-16 05:35:03 +02:00
|
|
|
handleCallback(error);
|
|
|
|
} else {
|
|
|
|
// user doesn't have a synced wallet
|
|
|
|
dispatch({
|
|
|
|
type: GET_SYNC_COMPLETED,
|
|
|
|
data: {
|
|
|
|
hasSyncedWallet: false,
|
|
|
|
syncHash: null
|
|
|
|
}
|
|
|
|
}); // call sync_apply to get data to sync
|
|
|
|
// first time sync. use any string for old hash
|
|
|
|
|
|
|
|
lbryRedux.Lbry.sync_apply({
|
|
|
|
password
|
|
|
|
}).then(({
|
|
|
|
hash: walletHash,
|
|
|
|
data: syncApplyData
|
|
|
|
}) => {
|
|
|
|
dispatch(doSetSync('', walletHash, syncApplyData, password));
|
|
|
|
handleCallback();
|
2020-01-23 23:11:07 +01:00
|
|
|
}).catch(syncApplyError => {
|
|
|
|
handleCallback(syncApplyError);
|
2019-10-16 05:35:03 +02:00
|
|
|
});
|
|
|
|
}
|
2019-04-18 10:02:11 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2019-05-27 15:57:31 +02:00
|
|
|
function doSyncApply(syncHash, syncData, password) {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch({
|
|
|
|
type: SYNC_APPLY_STARTED
|
|
|
|
});
|
|
|
|
lbryRedux.Lbry.sync_apply({
|
|
|
|
password,
|
|
|
|
data: syncData
|
|
|
|
}).then(({
|
|
|
|
hash: walletHash,
|
|
|
|
data: walletData
|
|
|
|
}) => {
|
|
|
|
dispatch({
|
|
|
|
type: SYNC_APPLY_COMPLETED
|
|
|
|
});
|
|
|
|
|
|
|
|
if (walletHash !== syncHash) {
|
|
|
|
// different local hash, need to synchronise
|
|
|
|
dispatch(doSetSync(syncHash, walletHash, walletData));
|
2019-05-28 18:38:43 +02:00
|
|
|
}
|
2019-05-27 15:57:31 +02:00
|
|
|
}).catch(() => {
|
|
|
|
dispatch({
|
|
|
|
type: SYNC_APPLY_FAILED,
|
|
|
|
data: {
|
|
|
|
error: 'Invalid password specified. Please enter the password for your previously synchronised wallet.'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function doCheckSync() {
|
|
|
|
return dispatch => {
|
|
|
|
dispatch({
|
|
|
|
type: GET_SYNC_STARTED
|
|
|
|
});
|
|
|
|
lbryRedux.Lbry.sync_hash().then(hash => {
|
|
|
|
Lbryio.call('sync', 'get', {
|
|
|
|
hash
|
|
|
|
}, 'post').then(response => {
|
|
|
|
const data = {
|
|
|
|
hasSyncedWallet: true,
|
|
|
|
syncHash: response.hash,
|
2019-08-16 03:33:07 +02:00
|
|
|
syncData: response.data,
|
|
|
|
hashChanged: response.changed
|
2019-05-27 15:57:31 +02:00
|
|
|
};
|
|
|
|
dispatch({
|
|
|
|
type: GET_SYNC_COMPLETED,
|
|
|
|
data
|
|
|
|
});
|
|
|
|
}).catch(() => {
|
|
|
|
// user doesn't have a synced wallet
|
|
|
|
dispatch({
|
|
|
|
type: GET_SYNC_COMPLETED,
|
|
|
|
data: {
|
|
|
|
hasSyncedWallet: false,
|
|
|
|
syncHash: null
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2019-10-02 22:22:51 +02:00
|
|
|
function doResetSync() {
|
|
|
|
return dispatch => new Promise(resolve => {
|
|
|
|
dispatch({
|
|
|
|
type: SYNC_RESET
|
|
|
|
});
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
}
|
2019-10-17 06:00:43 +02:00
|
|
|
function doSyncEncryptAndDecrypt(oldPassword, newPassword, encrypt) {
|
2019-10-17 01:28:02 +02:00
|
|
|
return dispatch => {
|
2019-10-21 18:35:52 +02:00
|
|
|
const data = {};
|
|
|
|
return lbryRedux.Lbry.sync_hash().then(hash => Lbryio.call('sync', 'get', {
|
|
|
|
hash
|
|
|
|
}, 'post')).then(syncGetResponse => {
|
2019-10-17 01:28:02 +02:00
|
|
|
data.oldHash = syncGetResponse.hash;
|
|
|
|
return lbryRedux.Lbry.sync_apply({
|
|
|
|
password: oldPassword,
|
|
|
|
data: syncGetResponse.data
|
|
|
|
});
|
2019-10-17 06:00:43 +02:00
|
|
|
}).then(() => {
|
|
|
|
if (encrypt) {
|
|
|
|
dispatch(lbryRedux.doWalletEncrypt(newPassword));
|
|
|
|
} else {
|
|
|
|
dispatch(lbryRedux.doWalletDecrypt());
|
|
|
|
}
|
2019-10-17 01:28:02 +02:00
|
|
|
}).then(() => lbryRedux.Lbry.sync_apply({
|
|
|
|
password: newPassword
|
|
|
|
})).then(syncApplyResponse => {
|
|
|
|
if (syncApplyResponse.hash !== data.oldHash) {
|
|
|
|
return dispatch(doSetSync(data.oldHash, syncApplyResponse.hash, syncApplyResponse.data));
|
|
|
|
}
|
|
|
|
}).catch(console.error);
|
|
|
|
};
|
|
|
|
}
|
2019-04-18 10:02:11 +02:00
|
|
|
|
2019-10-22 21:21:42 +02:00
|
|
|
//
|
|
|
|
const doUpdateUploadProgress = (progress, params, xhr) => dispatch => dispatch({
|
|
|
|
type: UPDATE_UPLOAD_PROGRESS,
|
|
|
|
data: {
|
|
|
|
progress,
|
|
|
|
params,
|
|
|
|
xhr
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-04-03 23:34:07 +02:00
|
|
|
const reducers = {};
|
2020-06-15 22:29:48 +02:00
|
|
|
const defaultState = {
|
2019-04-03 23:34:07 +02:00
|
|
|
authenticating: false
|
|
|
|
};
|
|
|
|
|
|
|
|
reducers[GENERATE_AUTH_TOKEN_FAILURE] = state => Object.assign({}, state, {
|
|
|
|
authToken: null,
|
|
|
|
authenticating: false
|
|
|
|
});
|
|
|
|
|
|
|
|
reducers[GENERATE_AUTH_TOKEN_STARTED] = state => Object.assign({}, state, {
|
|
|
|
authenticating: true
|
|
|
|
});
|
|
|
|
|
|
|
|
reducers[GENERATE_AUTH_TOKEN_SUCCESS] = (state, action) => Object.assign({}, state, {
|
|
|
|
authToken: action.data.authToken,
|
|
|
|
authenticating: false
|
|
|
|
});
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
function authReducer(state = defaultState, action) {
|
2019-04-03 23:34:07 +02:00
|
|
|
const handler = reducers[action.type];
|
|
|
|
if (handler) return handler(state, action);
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
// util for creating reducers
|
|
|
|
// based off of redux-actions
|
|
|
|
// https://redux-actions.js.org/docs/api/handleAction.html#handleactions
|
|
|
|
// eslint-disable-next-line import/prefer-default-export
|
|
|
|
const handleActions = (actionMap, defaultState) => (state = defaultState, action) => {
|
|
|
|
const handler = actionMap[action.type];
|
2019-04-03 23:34:07 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
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
|
2019-04-03 23:34:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
return state;
|
2019-10-02 06:15:24 +02:00
|
|
|
};
|
2019-09-17 23:01:10 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const defaultState$1 = {
|
2019-04-03 23:34:07 +02:00
|
|
|
fetching: {},
|
|
|
|
byUri: {}
|
|
|
|
};
|
|
|
|
const costInfoReducer = handleActions({
|
|
|
|
[FETCH_COST_INFO_STARTED]: (state, action) => {
|
|
|
|
const {
|
|
|
|
uri
|
|
|
|
} = action.data;
|
|
|
|
const newFetching = Object.assign({}, state.fetching);
|
|
|
|
newFetching[uri] = true;
|
|
|
|
return { ...state,
|
|
|
|
fetching: newFetching
|
|
|
|
};
|
|
|
|
},
|
|
|
|
[FETCH_COST_INFO_COMPLETED]: (state, action) => {
|
|
|
|
const {
|
|
|
|
uri,
|
|
|
|
costInfo
|
|
|
|
} = action.data;
|
|
|
|
const newByUri = Object.assign({}, state.byUri);
|
|
|
|
const newFetching = Object.assign({}, state.fetching);
|
|
|
|
newByUri[uri] = costInfo;
|
|
|
|
delete newFetching[uri];
|
|
|
|
return { ...state,
|
|
|
|
byUri: newByUri,
|
|
|
|
fetching: newFetching
|
|
|
|
};
|
|
|
|
}
|
2020-06-15 22:29:48 +02:00
|
|
|
}, defaultState$1);
|
2019-04-03 23:34:07 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const defaultState$2 = {
|
2019-04-03 23:34:07 +02:00
|
|
|
fetchingBlackListedOutpoints: false,
|
|
|
|
fetchingBlackListedOutpointsSucceed: undefined,
|
|
|
|
blackListedOutpoints: undefined
|
|
|
|
};
|
|
|
|
const blacklistReducer = handleActions({
|
|
|
|
[FETCH_BLACK_LISTED_CONTENT_STARTED]: state => ({ ...state,
|
|
|
|
fetchingBlackListedOutpoints: true
|
|
|
|
}),
|
|
|
|
[FETCH_BLACK_LISTED_CONTENT_COMPLETED]: (state, action) => {
|
|
|
|
const {
|
|
|
|
outpoints,
|
|
|
|
success
|
|
|
|
} = action.data;
|
|
|
|
return { ...state,
|
|
|
|
fetchingBlackListedOutpoints: false,
|
|
|
|
fetchingBlackListedOutpointsSucceed: success,
|
|
|
|
blackListedOutpoints: outpoints
|
|
|
|
};
|
|
|
|
},
|
|
|
|
[FETCH_BLACK_LISTED_CONTENT_FAILED]: (state, action) => {
|
|
|
|
const {
|
|
|
|
error,
|
|
|
|
success
|
|
|
|
} = action.data;
|
|
|
|
return { ...state,
|
|
|
|
fetchingBlackListedOutpoints: false,
|
|
|
|
fetchingBlackListedOutpointsSucceed: success,
|
|
|
|
fetchingBlackListedOutpointsError: error
|
|
|
|
};
|
|
|
|
}
|
2020-06-15 22:29:48 +02:00
|
|
|
}, defaultState$2);
|
2019-04-03 23:34:07 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const defaultState$3 = {
|
2019-07-11 02:44:15 +02:00
|
|
|
loading: false,
|
2019-07-09 16:20:01 +02:00
|
|
|
filteredOutpoints: undefined
|
|
|
|
};
|
|
|
|
const filteredReducer = handleActions({
|
|
|
|
[FETCH_FILTERED_CONTENT_STARTED]: state => ({ ...state,
|
2019-07-11 02:44:15 +02:00
|
|
|
loading: true
|
2019-07-09 16:20:01 +02:00
|
|
|
}),
|
|
|
|
[FETCH_FILTERED_CONTENT_COMPLETED]: (state, action) => {
|
|
|
|
const {
|
2019-07-11 02:44:15 +02:00
|
|
|
outpoints
|
2019-07-09 16:20:01 +02:00
|
|
|
} = action.data;
|
|
|
|
return { ...state,
|
2019-07-11 02:44:15 +02:00
|
|
|
loading: false,
|
2019-07-09 16:20:01 +02:00
|
|
|
filteredOutpoints: outpoints
|
|
|
|
};
|
|
|
|
},
|
|
|
|
[FETCH_FILTERED_CONTENT_FAILED]: (state, action) => {
|
|
|
|
const {
|
2019-07-11 02:44:15 +02:00
|
|
|
error
|
2019-07-09 16:20:01 +02:00
|
|
|
} = action.data;
|
|
|
|
return { ...state,
|
2019-07-11 02:44:15 +02:00
|
|
|
loading: false,
|
2019-07-09 16:20:01 +02:00
|
|
|
fetchingFilteredOutpointsError: error
|
|
|
|
};
|
|
|
|
}
|
2020-06-15 22:29:48 +02:00
|
|
|
}, defaultState$3);
|
2019-07-09 16:20:01 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const defaultState$4 = {
|
2019-04-03 23:34:07 +02:00
|
|
|
fetchingFeaturedContent: false,
|
|
|
|
fetchingFeaturedContentFailed: false,
|
|
|
|
featuredUris: undefined,
|
|
|
|
fetchingTrendingContent: false,
|
|
|
|
fetchingTrendingContentFailed: false,
|
|
|
|
trendingUris: undefined
|
|
|
|
};
|
|
|
|
const homepageReducer = handleActions({
|
|
|
|
[FETCH_FEATURED_CONTENT_STARTED]: state => ({ ...state,
|
|
|
|
fetchingFeaturedContent: true
|
|
|
|
}),
|
|
|
|
[FETCH_FEATURED_CONTENT_COMPLETED]: (state, action) => {
|
|
|
|
const {
|
|
|
|
uris,
|
|
|
|
success
|
|
|
|
} = action.data;
|
|
|
|
return { ...state,
|
|
|
|
fetchingFeaturedContent: false,
|
|
|
|
fetchingFeaturedContentFailed: !success,
|
|
|
|
featuredUris: uris
|
|
|
|
};
|
|
|
|
},
|
|
|
|
[FETCH_TRENDING_CONTENT_STARTED]: state => ({ ...state,
|
|
|
|
fetchingTrendingContent: true
|
|
|
|
}),
|
|
|
|
[FETCH_TRENDING_CONTENT_COMPLETED]: (state, action) => {
|
|
|
|
const {
|
|
|
|
uris,
|
|
|
|
success
|
|
|
|
} = action.data;
|
|
|
|
return { ...state,
|
|
|
|
fetchingTrendingContent: false,
|
|
|
|
fetchingTrendingContentFailed: !success,
|
|
|
|
trendingUris: uris
|
|
|
|
};
|
|
|
|
}
|
2020-06-15 22:29:48 +02:00
|
|
|
}, defaultState$4);
|
2019-04-03 23:34:07 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const defaultState$5 = {
|
2019-04-03 23:34:07 +02:00
|
|
|
fetchingViewCount: false,
|
|
|
|
viewCountError: undefined,
|
2019-09-25 04:30:53 +02:00
|
|
|
viewCountById: {},
|
|
|
|
fetchingSubCount: false,
|
|
|
|
subCountError: undefined,
|
|
|
|
subCountById: {}
|
2019-04-03 23:34:07 +02:00
|
|
|
};
|
|
|
|
const statsReducer = handleActions({
|
|
|
|
[FETCH_VIEW_COUNT_STARTED]: state => ({ ...state,
|
|
|
|
fetchingViewCount: true
|
|
|
|
}),
|
|
|
|
[FETCH_VIEW_COUNT_FAILED]: (state, action) => ({ ...state,
|
|
|
|
viewCountError: action.data
|
|
|
|
}),
|
|
|
|
[FETCH_VIEW_COUNT_COMPLETED]: (state, action) => {
|
|
|
|
const {
|
|
|
|
claimId,
|
|
|
|
viewCount
|
|
|
|
} = action.data;
|
|
|
|
const viewCountById = { ...state.viewCountById,
|
|
|
|
[claimId]: viewCount
|
|
|
|
};
|
|
|
|
return { ...state,
|
|
|
|
fetchingViewCount: false,
|
|
|
|
viewCountById
|
|
|
|
};
|
2019-09-25 04:30:53 +02:00
|
|
|
},
|
|
|
|
[FETCH_SUB_COUNT_STARTED]: state => ({ ...state,
|
|
|
|
fetchingSubCount: true
|
|
|
|
}),
|
|
|
|
[FETCH_SUB_COUNT_FAILED]: (state, action) => ({ ...state,
|
|
|
|
subCountError: action.data
|
|
|
|
}),
|
|
|
|
[FETCH_SUB_COUNT_COMPLETED]: (state, action) => {
|
|
|
|
const {
|
|
|
|
claimId,
|
|
|
|
subCount
|
|
|
|
} = action.data;
|
|
|
|
const subCountById = { ...state.subCountById,
|
|
|
|
[claimId]: subCount
|
|
|
|
};
|
|
|
|
return { ...state,
|
|
|
|
fetchingSubCount: false,
|
|
|
|
subCountById
|
|
|
|
};
|
2019-04-03 23:34:07 +02:00
|
|
|
}
|
2020-06-15 22:29:48 +02:00
|
|
|
}, defaultState$5);
|
2019-04-03 23:34:07 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const reducers$1 = {};
|
|
|
|
const defaultState$6 = {
|
2019-04-18 10:02:11 +02:00
|
|
|
hasSyncedWallet: false,
|
|
|
|
syncHash: null,
|
2019-05-27 15:57:31 +02:00
|
|
|
syncData: null,
|
2019-04-18 10:02:11 +02:00
|
|
|
setSyncErrorMessage: null,
|
2019-10-02 06:15:24 +02:00
|
|
|
getSyncErrorMessage: null,
|
2019-05-27 15:57:31 +02:00
|
|
|
syncApplyErrorMessage: '',
|
|
|
|
syncApplyIsPending: false,
|
2019-10-29 20:14:41 +01:00
|
|
|
syncApplyPasswordError: false,
|
2019-05-27 15:57:31 +02:00
|
|
|
getSyncIsPending: false,
|
2019-08-16 03:33:07 +02:00
|
|
|
setSyncIsPending: false,
|
|
|
|
hashChanged: false
|
2019-04-18 10:02:11 +02:00
|
|
|
};
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
reducers$1[GET_SYNC_STARTED] = state => Object.assign({}, state, {
|
2019-10-02 06:15:24 +02:00
|
|
|
getSyncIsPending: true,
|
|
|
|
getSyncErrorMessage: null
|
2019-04-18 10:02:11 +02:00
|
|
|
});
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
reducers$1[GET_SYNC_COMPLETED] = (state, action) => Object.assign({}, state, {
|
2019-04-18 10:02:11 +02:00
|
|
|
syncHash: action.data.syncHash,
|
2019-05-27 15:57:31 +02:00
|
|
|
syncData: action.data.syncData,
|
2019-04-18 10:02:11 +02:00
|
|
|
hasSyncedWallet: action.data.hasSyncedWallet,
|
2019-08-16 03:33:07 +02:00
|
|
|
getSyncIsPending: false,
|
|
|
|
hashChanged: action.data.hashChanged
|
2019-04-18 10:02:11 +02:00
|
|
|
});
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
reducers$1[GET_SYNC_FAILED] = (state, action) => Object.assign({}, state, {
|
2019-10-02 06:15:24 +02:00
|
|
|
getSyncIsPending: false,
|
|
|
|
getSyncErrorMessage: action.data.error
|
|
|
|
});
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
reducers$1[SET_SYNC_STARTED] = state => Object.assign({}, state, {
|
2019-05-27 15:57:31 +02:00
|
|
|
setSyncIsPending: true,
|
2019-04-18 10:02:11 +02:00
|
|
|
setSyncErrorMessage: null
|
|
|
|
});
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
reducers$1[SET_SYNC_FAILED] = (state, action) => Object.assign({}, state, {
|
2019-05-27 15:57:31 +02:00
|
|
|
setSyncIsPending: false,
|
2019-04-18 10:02:11 +02:00
|
|
|
setSyncErrorMessage: action.data.error
|
|
|
|
});
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
reducers$1[SET_SYNC_COMPLETED] = (state, action) => Object.assign({}, state, {
|
2019-05-27 15:57:31 +02:00
|
|
|
setSyncIsPending: false,
|
2019-04-18 10:02:11 +02:00
|
|
|
setSyncErrorMessage: null,
|
|
|
|
hasSyncedWallet: true,
|
|
|
|
// sync was successful, so the user has a synced wallet at this point
|
|
|
|
syncHash: action.data.syncHash
|
|
|
|
});
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
reducers$1[SYNC_APPLY_STARTED] = state => Object.assign({}, state, {
|
2019-10-29 20:14:41 +01:00
|
|
|
syncApplyPasswordError: false,
|
2019-05-27 15:57:31 +02:00
|
|
|
syncApplyIsPending: true,
|
|
|
|
syncApplyErrorMessage: ''
|
|
|
|
});
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
reducers$1[SYNC_APPLY_COMPLETED] = state => Object.assign({}, state, {
|
2019-05-27 15:57:31 +02:00
|
|
|
syncApplyIsPending: false,
|
|
|
|
syncApplyErrorMessage: ''
|
|
|
|
});
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
reducers$1[SYNC_APPLY_FAILED] = (state, action) => Object.assign({}, state, {
|
2019-05-27 15:57:31 +02:00
|
|
|
syncApplyIsPending: false,
|
|
|
|
syncApplyErrorMessage: action.data.error
|
|
|
|
});
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
reducers$1[SYNC_APPLY_BAD_PASSWORD] = state => Object.assign({}, state, {
|
2019-10-29 20:14:41 +01:00
|
|
|
syncApplyPasswordError: true
|
|
|
|
});
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
reducers$1[SYNC_RESET] = () => defaultState$6;
|
2019-10-02 22:22:51 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
function syncReducer(state = defaultState$6, action) {
|
|
|
|
const handler = reducers$1[action.type];
|
2019-04-18 10:02:11 +02:00
|
|
|
if (handler) return handler(state, action);
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2019-10-22 21:21:42 +02:00
|
|
|
//
|
|
|
|
/*
|
|
|
|
test mock:
|
|
|
|
currentUploads: {
|
|
|
|
'test#upload': {
|
|
|
|
progress: 50,
|
|
|
|
params: {
|
|
|
|
name: 'steve',
|
|
|
|
thumbnail_url: 'https://dev2.spee.ch/4/KMNtoSZ009fawGz59VG8PrID.jpeg',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
*/
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const reducers$2 = {};
|
|
|
|
const defaultState$7 = {
|
2019-10-22 21:21:42 +02:00
|
|
|
currentUploads: {}
|
|
|
|
};
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
reducers$2[UPDATE_UPLOAD_PROGRESS] = (state, action) => {
|
2019-10-22 21:21:42 +02:00
|
|
|
const {
|
|
|
|
progress,
|
|
|
|
params,
|
|
|
|
xhr
|
|
|
|
} = action.data;
|
|
|
|
const key = params.channel ? `${params.name}#${params.channel}` : `${params.name}#anonymous`;
|
|
|
|
let currentUploads;
|
|
|
|
|
|
|
|
if (!progress) {
|
|
|
|
currentUploads = Object.assign({}, state.currentUploads);
|
|
|
|
Object.keys(currentUploads).forEach(k => {
|
|
|
|
if (k === key) {
|
|
|
|
delete currentUploads[key];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
currentUploads = Object.assign({}, state.currentUploads);
|
|
|
|
currentUploads[key] = {
|
|
|
|
progress,
|
|
|
|
params,
|
|
|
|
xhr
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return { ...state,
|
|
|
|
currentUploads
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
function webReducer(state = defaultState$7, action) {
|
|
|
|
const handler = reducers$2[action.type];
|
2019-10-22 21:21:42 +02:00
|
|
|
if (handler) return handler(state, action);
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const selectState = state => state.auth || {};
|
2019-04-03 23:34:07 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const selectAuthToken = reselect.createSelector(selectState, state => state.authToken);
|
|
|
|
const selectIsAuthenticating = reselect.createSelector(selectState, state => state.authenticating);
|
2019-04-03 23:34:07 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const selectState$1 = state => state.costInfo || {};
|
|
|
|
const selectAllCostInfoByUri = reselect.createSelector(selectState$1, state => state.byUri || {});
|
2019-04-03 23:34:07 +02:00
|
|
|
const makeSelectCostInfoForUri = uri => reselect.createSelector(selectAllCostInfoByUri, costInfos => costInfos && costInfos[uri]);
|
2020-06-15 22:29:48 +02:00
|
|
|
const selectFetchingCostInfo = reselect.createSelector(selectState$1, state => state.fetching || {});
|
2019-04-03 23:34:07 +02:00
|
|
|
const makeSelectFetchingCostInfoForUri = uri => reselect.createSelector(selectFetchingCostInfo, fetchingByUri => fetchingByUri && fetchingByUri[uri]);
|
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const selectState$2 = state => state.blacklist || {};
|
|
|
|
const selectBlackListedOutpoints = reselect.createSelector(selectState$2, state => state.blackListedOutpoints);
|
2019-04-03 23:34:07 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const selectState$3 = state => state.filtered || {};
|
|
|
|
const selectFilteredOutpoints = reselect.createSelector(selectState$3, state => state.filteredOutpoints);
|
2019-07-09 16:20:01 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const selectState$4 = state => state.homepage || {};
|
2019-04-03 23:34:07 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const selectFeaturedUris = reselect.createSelector(selectState$4, state => state.featuredUris);
|
|
|
|
const selectFetchingFeaturedUris = reselect.createSelector(selectState$4, state => state.fetchingFeaturedContent);
|
|
|
|
const selectTrendingUris = reselect.createSelector(selectState$4, state => state.trendingUris);
|
|
|
|
const selectFetchingTrendingUris = reselect.createSelector(selectState$4, state => state.fetchingTrendingContent);
|
2019-04-03 23:34:07 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const selectState$5 = state => state.stats || {};
|
2019-04-03 23:34:07 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const selectViewCount = reselect.createSelector(selectState$5, state => state.viewCountById);
|
|
|
|
const selectSubCount = reselect.createSelector(selectState$5, state => state.subCountById);
|
2019-12-20 08:45:03 +01:00
|
|
|
const makeSelectViewCountForUri = uri => reselect.createSelector(lbryRedux.makeSelectClaimForUri(uri), selectViewCount, (claim, viewCountById) => claim ? viewCountById[claim.claim_id] || 0 : 0);
|
|
|
|
const makeSelectSubCountForUri = uri => reselect.createSelector(lbryRedux.makeSelectClaimForUri(uri), selectSubCount, (claim, subCountById) => claim ? subCountById[claim.claim_id] || 0 : 0);
|
2019-04-03 23:34:07 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const selectState$6 = state => state.sync || {};
|
2019-04-18 10:02:11 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const selectHasSyncedWallet = reselect.createSelector(selectState$6, state => state.hasSyncedWallet);
|
|
|
|
const selectSyncHash = reselect.createSelector(selectState$6, state => state.syncHash);
|
|
|
|
const selectSyncData = reselect.createSelector(selectState$6, state => state.syncData);
|
|
|
|
const selectSetSyncErrorMessage = reselect.createSelector(selectState$6, state => state.setSyncErrorMessage);
|
|
|
|
const selectGetSyncErrorMessage = reselect.createSelector(selectState$6, state => state.getSyncErrorMessage);
|
|
|
|
const selectGetSyncIsPending = reselect.createSelector(selectState$6, state => state.getSyncIsPending);
|
|
|
|
const selectSetSyncIsPending = reselect.createSelector(selectState$6, state => state.setSyncIsPending);
|
|
|
|
const selectHashChanged = reselect.createSelector(selectState$6, state => state.hashChanged);
|
|
|
|
const selectSyncApplyIsPending = reselect.createSelector(selectState$6, state => state.syncApplyIsPending);
|
|
|
|
const selectSyncApplyErrorMessage = reselect.createSelector(selectState$6, state => state.syncApplyErrorMessage);
|
|
|
|
const selectSyncApplyPasswordError = reselect.createSelector(selectState$6, state => state.syncApplyPasswordError);
|
2019-04-18 10:02:11 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const selectState$7 = state => state.web || {};
|
2019-10-22 21:21:42 +02:00
|
|
|
|
2020-06-15 22:29:48 +02:00
|
|
|
const selectCurrentUploads = reselect.createSelector(selectState$7, state => state.currentUploads);
|
2019-10-22 21:21:42 +02:00
|
|
|
const selectUploadCount = reselect.createSelector(selectCurrentUploads, currentUploads => currentUploads && Object.keys(currentUploads).length);
|
|
|
|
|
2020-01-10 04:28:46 +01:00
|
|
|
exports.ERRORS = errors;
|
2019-04-03 23:34:07 +02:00
|
|
|
exports.LBRYINC_ACTIONS = action_types;
|
|
|
|
exports.Lbryio = Lbryio;
|
2019-10-02 06:15:24 +02:00
|
|
|
exports.YOUTUBE_STATUSES = youtube;
|
2019-04-03 23:34:07 +02:00
|
|
|
exports.authReducer = authReducer;
|
|
|
|
exports.blacklistReducer = blacklistReducer;
|
|
|
|
exports.costInfoReducer = costInfoReducer;
|
|
|
|
exports.doBlackListedOutpointsSubscribe = doBlackListedOutpointsSubscribe;
|
2019-05-27 15:57:31 +02:00
|
|
|
exports.doCheckSync = doCheckSync;
|
2019-04-03 23:34:07 +02:00
|
|
|
exports.doFetchCostInfoForUri = doFetchCostInfoForUri;
|
|
|
|
exports.doFetchFeaturedUris = doFetchFeaturedUris;
|
2019-09-25 04:30:53 +02:00
|
|
|
exports.doFetchSubCount = doFetchSubCount;
|
2019-04-03 23:34:07 +02:00
|
|
|
exports.doFetchTrendingUris = doFetchTrendingUris;
|
|
|
|
exports.doFetchViewCount = doFetchViewCount;
|
2019-07-09 16:20:01 +02:00
|
|
|
exports.doFilteredOutpointsSubscribe = doFilteredOutpointsSubscribe;
|
2019-04-03 23:34:07 +02:00
|
|
|
exports.doGenerateAuthToken = doGenerateAuthToken;
|
2019-04-18 10:02:11 +02:00
|
|
|
exports.doGetSync = doGetSync;
|
2019-10-02 22:22:51 +02:00
|
|
|
exports.doResetSync = doResetSync;
|
2019-05-10 16:45:56 +02:00
|
|
|
exports.doSetDefaultAccount = doSetDefaultAccount;
|
2019-04-18 10:02:11 +02:00
|
|
|
exports.doSetSync = doSetSync;
|
2019-05-27 15:57:31 +02:00
|
|
|
exports.doSyncApply = doSyncApply;
|
2019-10-17 06:00:43 +02:00
|
|
|
exports.doSyncEncryptAndDecrypt = doSyncEncryptAndDecrypt;
|
2019-12-05 13:13:10 +01:00
|
|
|
exports.doTransifexUpload = doTransifexUpload;
|
2019-10-22 21:21:42 +02:00
|
|
|
exports.doUpdateUploadProgress = doUpdateUploadProgress;
|
2019-07-09 16:20:01 +02:00
|
|
|
exports.filteredReducer = filteredReducer;
|
2019-04-03 23:34:07 +02:00
|
|
|
exports.homepageReducer = homepageReducer;
|
|
|
|
exports.makeSelectCostInfoForUri = makeSelectCostInfoForUri;
|
|
|
|
exports.makeSelectFetchingCostInfoForUri = makeSelectFetchingCostInfoForUri;
|
2019-09-25 04:30:53 +02:00
|
|
|
exports.makeSelectSubCountForUri = makeSelectSubCountForUri;
|
2019-04-03 23:34:07 +02:00
|
|
|
exports.makeSelectViewCountForUri = makeSelectViewCountForUri;
|
|
|
|
exports.selectAllCostInfoByUri = selectAllCostInfoByUri;
|
|
|
|
exports.selectAuthToken = selectAuthToken;
|
|
|
|
exports.selectBlackListedOutpoints = selectBlackListedOutpoints;
|
2019-10-22 21:21:42 +02:00
|
|
|
exports.selectCurrentUploads = selectCurrentUploads;
|
2019-04-03 23:34:07 +02:00
|
|
|
exports.selectFeaturedUris = selectFeaturedUris;
|
|
|
|
exports.selectFetchingCostInfo = selectFetchingCostInfo;
|
|
|
|
exports.selectFetchingFeaturedUris = selectFetchingFeaturedUris;
|
|
|
|
exports.selectFetchingTrendingUris = selectFetchingTrendingUris;
|
2019-07-09 16:20:01 +02:00
|
|
|
exports.selectFilteredOutpoints = selectFilteredOutpoints;
|
2019-10-02 06:15:24 +02:00
|
|
|
exports.selectGetSyncErrorMessage = selectGetSyncErrorMessage;
|
2019-05-27 15:57:31 +02:00
|
|
|
exports.selectGetSyncIsPending = selectGetSyncIsPending;
|
2019-04-18 10:02:11 +02:00
|
|
|
exports.selectHasSyncedWallet = selectHasSyncedWallet;
|
2019-08-16 03:33:07 +02:00
|
|
|
exports.selectHashChanged = selectHashChanged;
|
2019-04-03 23:34:07 +02:00
|
|
|
exports.selectIsAuthenticating = selectIsAuthenticating;
|
2019-04-18 10:02:11 +02:00
|
|
|
exports.selectSetSyncErrorMessage = selectSetSyncErrorMessage;
|
2019-05-27 15:57:31 +02:00
|
|
|
exports.selectSetSyncIsPending = selectSetSyncIsPending;
|
|
|
|
exports.selectSyncApplyErrorMessage = selectSyncApplyErrorMessage;
|
|
|
|
exports.selectSyncApplyIsPending = selectSyncApplyIsPending;
|
2019-10-29 20:14:41 +01:00
|
|
|
exports.selectSyncApplyPasswordError = selectSyncApplyPasswordError;
|
2019-05-27 15:57:31 +02:00
|
|
|
exports.selectSyncData = selectSyncData;
|
2019-04-18 10:02:11 +02:00
|
|
|
exports.selectSyncHash = selectSyncHash;
|
2019-04-03 23:34:07 +02:00
|
|
|
exports.selectTrendingUris = selectTrendingUris;
|
2019-10-22 21:21:42 +02:00
|
|
|
exports.selectUploadCount = selectUploadCount;
|
2019-04-03 23:34:07 +02:00
|
|
|
exports.statsReducer = statsReducer;
|
2019-04-18 10:02:11 +02:00
|
|
|
exports.syncReducer = syncReducer;
|
2020-05-07 19:56:10 +02:00
|
|
|
exports.webReducer = webReducer;
|