From 6418b5a9f23f7604c8609a760f08ac8ef1075708 Mon Sep 17 00:00:00 2001 From: akinwale Date: Thu, 5 Apr 2018 03:57:29 +0100 Subject: [PATCH] Common components refactor (#1) --- .eslintrc.json | 30 + .lintstagedrc | 9 + .prettierrc.json | 5 + README.md | 22 + build/index.js | 4958 +++++++++++++++++++++++--- package.json | 23 +- src/constants/action_types.js | 41 +- src/constants/search.js | 3 + src/constants/settings.js | 4 + src/index.js | 178 +- src/jsonrpc.js | 86 - src/lbry.js | 251 +- src/lbryURI.js | 230 ++ src/lbryapi.js | 25 +- src/redux/actions/claims.js | 188 + src/redux/actions/file_info.js | 66 + src/redux/actions/notifications.js | 10 + src/redux/actions/search.js | 174 + src/redux/actions/wallet.js | 209 ++ src/redux/reducers/claims.js | 246 ++ src/redux/reducers/cost_info.js | 2 +- src/redux/reducers/file_info.js | 156 + src/redux/reducers/notifications.js | 39 + src/redux/reducers/search.js | 103 + src/redux/reducers/wallet.js | 146 + src/redux/selectors/claims.js | 186 +- src/redux/selectors/cost_info.js | 4 +- src/redux/selectors/file_info.js | 197 + src/redux/selectors/navigation.js | 202 ++ src/redux/selectors/notifications.js | 8 + src/redux/selectors/search.js | 37 + src/redux/selectors/wallet.js | 125 + src/types/Notification.js | 12 + src/util/batchActions.js | 7 + src/util/formatCredits.js | 21 + src/util/handle-fetch.js | 5 + src/util/query_params.js | 28 + src/util/redux-utils.js | 17 + webpack.config.js | 2 +- 39 files changed, 7302 insertions(+), 753 deletions(-) create mode 100644 .eslintrc.json create mode 100644 .lintstagedrc create mode 100644 .prettierrc.json create mode 100644 README.md create mode 100644 src/constants/search.js delete mode 100644 src/jsonrpc.js create mode 100644 src/lbryURI.js create mode 100644 src/redux/actions/claims.js create mode 100644 src/redux/actions/file_info.js create mode 100644 src/redux/actions/notifications.js create mode 100644 src/redux/actions/search.js create mode 100644 src/redux/actions/wallet.js create mode 100644 src/redux/reducers/claims.js create mode 100644 src/redux/reducers/file_info.js create mode 100644 src/redux/reducers/notifications.js create mode 100644 src/redux/reducers/search.js create mode 100644 src/redux/reducers/wallet.js create mode 100644 src/redux/selectors/file_info.js create mode 100644 src/redux/selectors/navigation.js create mode 100644 src/redux/selectors/notifications.js create mode 100644 src/redux/selectors/search.js create mode 100644 src/redux/selectors/wallet.js create mode 100644 src/types/Notification.js create mode 100644 src/util/batchActions.js create mode 100644 src/util/formatCredits.js create mode 100644 src/util/handle-fetch.js create mode 100644 src/util/query_params.js create mode 100644 src/util/redux-utils.js diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..8581d49 --- /dev/null +++ b/.eslintrc.json @@ -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"] + } +} diff --git a/.lintstagedrc b/.lintstagedrc new file mode 100644 index 0000000..b03e7c9 --- /dev/null +++ b/.lintstagedrc @@ -0,0 +1,9 @@ +{ + "linters": { + "src/**/*.js": [ + "prettier --write", + "eslint --fix", + "git add" + ] + } +} diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..1d3fce7 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,5 @@ +{ + "trailingComma": "es5", + "printWidth": 100, + "singleQuote": true +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4abdc2c --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# lbry-redux +lbry-redux is a module which contains common React and redux code shared between lbry-app and lbry-android. + +## Installation +Add `lbry-redux` as a dependency to your `package.json` file. +`"lbry-redux": "lbryio/lbry-redux"` + +### Local development +If you intend to make changes to the module and test immediately, you can use `npm link` to add the package to your `node_modules` folder. This will create a symlink to the folder where `lbry-redux` was cloned to. +``` +cd lbry-redux +sudo npm link +cd ////node_modules +npm link lbry-redux +```` + +### Build +Run `$ npm build`. + +## License + +[MIT © LBRY](LICENSE) \ No newline at end of file diff --git a/build/index.js b/build/index.js index 48561f4..cf7bf49 100644 --- a/build/index.js +++ b/build/index.js @@ -1,5 +1,14 @@ -module.exports = -/******/ (function(modules) { // webpackBootstrap +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(); + else if(typeof define === 'function' && define.amd) + define([], factory); + else { + var a = factory(); + for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; + } +})(typeof self !== 'undefined' ? self : this, function() { +return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ @@ -61,7 +70,7 @@ module.exports = /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 1); +/******/ return __webpack_require__(__webpack_require__.s = 15); /******/ }) /************************************************************************/ /******/ ([ @@ -74,153 +83,897 @@ module.exports = Object.defineProperty(exports, "__esModule", { value: true }); +var OPEN_MODAL = exports.OPEN_MODAL = 'OPEN_MODAL'; +var CLOSE_MODAL = exports.CLOSE_MODAL = 'CLOSE_MODAL'; +var SHOW_SNACKBAR = exports.SHOW_SNACKBAR = 'SHOW_SNACKBAR'; +var REMOVE_SNACKBAR_SNACK = exports.REMOVE_SNACKBAR_SNACK = 'REMOVE_SNACKBAR_SNACK'; +var WINDOW_FOCUSED = exports.WINDOW_FOCUSED = 'WINDOW_FOCUSED'; +var DAEMON_READY = exports.DAEMON_READY = 'DAEMON_READY'; +var DAEMON_VERSION_MATCH = exports.DAEMON_VERSION_MATCH = 'DAEMON_VERSION_MATCH'; +var DAEMON_VERSION_MISMATCH = exports.DAEMON_VERSION_MISMATCH = 'DAEMON_VERSION_MISMATCH'; +var VOLUME_CHANGED = exports.VOLUME_CHANGED = 'VOLUME_CHANGED'; -var _jsonrpc = __webpack_require__(2); +// Navigation +var CHANGE_AFTER_AUTH_PATH = exports.CHANGE_AFTER_AUTH_PATH = 'CHANGE_AFTER_AUTH_PATH'; +var WINDOW_SCROLLED = exports.WINDOW_SCROLLED = 'WINDOW_SCROLLED'; +var HISTORY_NAVIGATE = exports.HISTORY_NAVIGATE = 'HISTORY_NAVIGATE'; -var _jsonrpc2 = _interopRequireDefault(_jsonrpc); +// Upgrades +var UPGRADE_CANCELLED = exports.UPGRADE_CANCELLED = 'UPGRADE_CANCELLED'; +var DOWNLOAD_UPGRADE = exports.DOWNLOAD_UPGRADE = 'DOWNLOAD_UPGRADE'; +var UPGRADE_DOWNLOAD_STARTED = exports.UPGRADE_DOWNLOAD_STARTED = 'UPGRADE_DOWNLOAD_STARTED'; +var UPGRADE_DOWNLOAD_COMPLETED = exports.UPGRADE_DOWNLOAD_COMPLETED = 'UPGRADE_DOWNLOAD_COMPLETED'; +var UPGRADE_DOWNLOAD_PROGRESSED = exports.UPGRADE_DOWNLOAD_PROGRESSED = 'UPGRADE_DOWNLOAD_PROGRESSED'; +var CHECK_UPGRADE_AVAILABLE = exports.CHECK_UPGRADE_AVAILABLE = 'CHECK_UPGRADE_AVAILABLE'; +var CHECK_UPGRADE_START = exports.CHECK_UPGRADE_START = 'CHECK_UPGRADE_START'; +var CHECK_UPGRADE_SUCCESS = exports.CHECK_UPGRADE_SUCCESS = 'CHECK_UPGRADE_SUCCESS'; +var CHECK_UPGRADE_FAIL = exports.CHECK_UPGRADE_FAIL = 'CHECK_UPGRADE_FAIL'; +var CHECK_UPGRADE_SUBSCRIBE = exports.CHECK_UPGRADE_SUBSCRIBE = 'CHECK_UPGRADE_SUBSCRIBE'; +var UPDATE_VERSION = exports.UPDATE_VERSION = 'UPDATE_VERSION'; +var UPDATE_REMOTE_VERSION = exports.UPDATE_REMOTE_VERSION = 'UPDATE_REMOTE_VERSION'; +var SKIP_UPGRADE = exports.SKIP_UPGRADE = 'SKIP_UPGRADE'; +var START_UPGRADE = exports.START_UPGRADE = 'START_UPGRADE'; +var AUTO_UPDATE_DECLINED = exports.AUTO_UPDATE_DECLINED = 'AUTO_UPDATE_DECLINED'; +var AUTO_UPDATE_DOWNLOADED = exports.AUTO_UPDATE_DOWNLOADED = 'AUTO_UPDATE_DOWNLOADED'; -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +// Wallet +var GET_NEW_ADDRESS_STARTED = exports.GET_NEW_ADDRESS_STARTED = 'GET_NEW_ADDRESS_STARTED'; +var GET_NEW_ADDRESS_COMPLETED = exports.GET_NEW_ADDRESS_COMPLETED = 'GET_NEW_ADDRESS_COMPLETED'; +var FETCH_TRANSACTIONS_STARTED = exports.FETCH_TRANSACTIONS_STARTED = 'FETCH_TRANSACTIONS_STARTED'; +var FETCH_TRANSACTIONS_COMPLETED = exports.FETCH_TRANSACTIONS_COMPLETED = 'FETCH_TRANSACTIONS_COMPLETED'; +var UPDATE_BALANCE = exports.UPDATE_BALANCE = 'UPDATE_BALANCE'; +var CHECK_ADDRESS_IS_MINE_STARTED = exports.CHECK_ADDRESS_IS_MINE_STARTED = 'CHECK_ADDRESS_IS_MINE_STARTED'; +var CHECK_ADDRESS_IS_MINE_COMPLETED = exports.CHECK_ADDRESS_IS_MINE_COMPLETED = 'CHECK_ADDRESS_IS_MINE_COMPLETED'; +var SEND_TRANSACTION_STARTED = exports.SEND_TRANSACTION_STARTED = 'SEND_TRANSACTION_STARTED'; +var SEND_TRANSACTION_COMPLETED = exports.SEND_TRANSACTION_COMPLETED = 'SEND_TRANSACTION_COMPLETED'; +var SEND_TRANSACTION_FAILED = exports.SEND_TRANSACTION_FAILED = 'SEND_TRANSACTION_FAILED'; +var FETCH_BLOCK_SUCCESS = exports.FETCH_BLOCK_SUCCESS = 'FETCH_BLOCK_SUCCESS'; +var SUPPORT_TRANSACTION_STARTED = exports.SUPPORT_TRANSACTION_STARTED = 'SUPPORT_TRANSACTION_STARTED'; +var SUPPORT_TRANSACTION_COMPLETED = exports.SUPPORT_TRANSACTION_COMPLETED = 'SUPPORT_TRANSACTION_COMPLETED'; +var SUPPORT_TRANSACTION_FAILED = exports.SUPPORT_TRANSACTION_FAILED = 'SUPPORT_TRANSACTION_FAILED'; + +// Claims +var FETCH_FEATURED_CONTENT_STARTED = exports.FETCH_FEATURED_CONTENT_STARTED = 'FETCH_FEATURED_CONTENT_STARTED'; +var FETCH_FEATURED_CONTENT_COMPLETED = exports.FETCH_FEATURED_CONTENT_COMPLETED = 'FETCH_FEATURED_CONTENT_COMPLETED'; +var RESOLVE_URIS_STARTED = exports.RESOLVE_URIS_STARTED = 'RESOLVE_URIS_STARTED'; +var RESOLVE_URIS_COMPLETED = exports.RESOLVE_URIS_COMPLETED = 'RESOLVE_URIS_COMPLETED'; +var FETCH_CHANNEL_CLAIMS_STARTED = exports.FETCH_CHANNEL_CLAIMS_STARTED = 'FETCH_CHANNEL_CLAIMS_STARTED'; +var FETCH_CHANNEL_CLAIMS_COMPLETED = exports.FETCH_CHANNEL_CLAIMS_COMPLETED = 'FETCH_CHANNEL_CLAIMS_COMPLETED'; +var FETCH_CHANNEL_CLAIM_COUNT_STARTED = exports.FETCH_CHANNEL_CLAIM_COUNT_STARTED = 'FETCH_CHANNEL_CLAIM_COUNT_STARTED'; +var FETCH_CHANNEL_CLAIM_COUNT_COMPLETED = exports.FETCH_CHANNEL_CLAIM_COUNT_COMPLETED = 'FETCH_CHANNEL_CLAIM_COUNT_COMPLETED'; +var FETCH_CLAIM_LIST_MINE_STARTED = exports.FETCH_CLAIM_LIST_MINE_STARTED = 'FETCH_CLAIM_LIST_MINE_STARTED'; +var FETCH_CLAIM_LIST_MINE_COMPLETED = exports.FETCH_CLAIM_LIST_MINE_COMPLETED = 'FETCH_CLAIM_LIST_MINE_COMPLETED'; +var ABANDON_CLAIM_STARTED = exports.ABANDON_CLAIM_STARTED = 'ABANDON_CLAIM_STARTED'; +var ABANDON_CLAIM_SUCCEEDED = exports.ABANDON_CLAIM_SUCCEEDED = 'ABANDON_CLAIM_SUCCEEDED'; +var FETCH_CHANNEL_LIST_STARTED = exports.FETCH_CHANNEL_LIST_STARTED = 'FETCH_CHANNEL_LIST_STARTED'; +var FETCH_CHANNEL_LIST_COMPLETED = exports.FETCH_CHANNEL_LIST_COMPLETED = 'FETCH_CHANNEL_LIST_COMPLETED'; +var CREATE_CHANNEL_STARTED = exports.CREATE_CHANNEL_STARTED = 'CREATE_CHANNEL_STARTED'; +var CREATE_CHANNEL_COMPLETED = exports.CREATE_CHANNEL_COMPLETED = 'CREATE_CHANNEL_COMPLETED'; +var PUBLISH_STARTED = exports.PUBLISH_STARTED = 'PUBLISH_STARTED'; +var PUBLISH_COMPLETED = exports.PUBLISH_COMPLETED = 'PUBLISH_COMPLETED'; +var PUBLISH_FAILED = exports.PUBLISH_FAILED = 'PUBLISH_FAILED'; +var SET_PLAYING_URI = exports.SET_PLAYING_URI = 'PLAY_URI'; + +// Files +var FILE_LIST_STARTED = exports.FILE_LIST_STARTED = 'FILE_LIST_STARTED'; +var FILE_LIST_SUCCEEDED = exports.FILE_LIST_SUCCEEDED = 'FILE_LIST_SUCCEEDED'; +var FETCH_FILE_INFO_STARTED = exports.FETCH_FILE_INFO_STARTED = 'FETCH_FILE_INFO_STARTED'; +var FETCH_FILE_INFO_COMPLETED = exports.FETCH_FILE_INFO_COMPLETED = 'FETCH_FILE_INFO_COMPLETED'; +var FETCH_COST_INFO_STARTED = exports.FETCH_COST_INFO_STARTED = 'FETCH_COST_INFO_STARTED'; +var FETCH_COST_INFO_COMPLETED = exports.FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED'; +var LOADING_VIDEO_STARTED = exports.LOADING_VIDEO_STARTED = 'LOADING_VIDEO_STARTED'; +var LOADING_VIDEO_COMPLETED = exports.LOADING_VIDEO_COMPLETED = 'LOADING_VIDEO_COMPLETED'; +var LOADING_VIDEO_FAILED = exports.LOADING_VIDEO_FAILED = 'LOADING_VIDEO_FAILED'; +var DOWNLOADING_STARTED = exports.DOWNLOADING_STARTED = 'DOWNLOADING_STARTED'; +var DOWNLOADING_PROGRESSED = exports.DOWNLOADING_PROGRESSED = 'DOWNLOADING_PROGRESSED'; +var DOWNLOADING_COMPLETED = exports.DOWNLOADING_COMPLETED = 'DOWNLOADING_COMPLETED'; +var DOWNLOADING_CANCELED = exports.DOWNLOADING_CANCELED = 'DOWNLOADING_CANCELED'; +var PLAY_VIDEO_STARTED = exports.PLAY_VIDEO_STARTED = 'PLAY_VIDEO_STARTED'; +var FETCH_AVAILABILITY_STARTED = exports.FETCH_AVAILABILITY_STARTED = 'FETCH_AVAILABILITY_STARTED'; +var FETCH_AVAILABILITY_COMPLETED = exports.FETCH_AVAILABILITY_COMPLETED = 'FETCH_AVAILABILITY_COMPLETED'; +var FILE_DELETE = exports.FILE_DELETE = 'FILE_DELETE'; + +// Search +var SEARCH_START = exports.SEARCH_START = 'SEARCH_START'; +var SEARCH_SUCCESS = exports.SEARCH_SUCCESS = 'SEARCH_SUCCESS'; +var SEARCH_FAIL = exports.SEARCH_FAIL = 'SEARCH_FAIL'; +var UPDATE_SEARCH_QUERY = exports.UPDATE_SEARCH_QUERY = 'UPDATE_SEARCH_QUERY'; +var UPDATE_SEARCH_SUGGESTIONS = exports.UPDATE_SEARCH_SUGGESTIONS = 'UPDATE_SEARCH_SUGGESTIONS'; + +// Settings +var DAEMON_SETTINGS_RECEIVED = exports.DAEMON_SETTINGS_RECEIVED = 'DAEMON_SETTINGS_RECEIVED'; +var CLIENT_SETTING_CHANGED = exports.CLIENT_SETTING_CHANGED = 'CLIENT_SETTING_CHANGED'; +var UPDATE_IS_NIGHT = exports.UPDATE_IS_NIGHT = 'UPDATE_IS_NIGHT'; + +// User +var AUTHENTICATION_STARTED = exports.AUTHENTICATION_STARTED = 'AUTHENTICATION_STARTED'; +var AUTHENTICATION_SUCCESS = exports.AUTHENTICATION_SUCCESS = 'AUTHENTICATION_SUCCESS'; +var AUTHENTICATION_FAILURE = exports.AUTHENTICATION_FAILURE = 'AUTHENTICATION_FAILURE'; +var USER_EMAIL_DECLINE = exports.USER_EMAIL_DECLINE = 'USER_EMAIL_DECLINE'; +var USER_EMAIL_NEW_STARTED = exports.USER_EMAIL_NEW_STARTED = 'USER_EMAIL_NEW_STARTED'; +var USER_EMAIL_NEW_SUCCESS = exports.USER_EMAIL_NEW_SUCCESS = 'USER_EMAIL_NEW_SUCCESS'; +var USER_EMAIL_NEW_EXISTS = exports.USER_EMAIL_NEW_EXISTS = 'USER_EMAIL_NEW_EXISTS'; +var USER_EMAIL_NEW_FAILURE = exports.USER_EMAIL_NEW_FAILURE = 'USER_EMAIL_NEW_FAILURE'; +var USER_EMAIL_VERIFY_STARTED = exports.USER_EMAIL_VERIFY_STARTED = 'USER_EMAIL_VERIFY_STARTED'; +var USER_EMAIL_VERIFY_SUCCESS = exports.USER_EMAIL_VERIFY_SUCCESS = 'USER_EMAIL_VERIFY_SUCCESS'; +var USER_EMAIL_VERIFY_FAILURE = exports.USER_EMAIL_VERIFY_FAILURE = 'USER_EMAIL_VERIFY_FAILURE'; +var USER_PHONE_RESET = exports.USER_PHONE_RESET = 'USER_PHONE_RESET'; +var USER_PHONE_NEW_STARTED = exports.USER_PHONE_NEW_STARTED = 'USER_PHONE_NEW_STARTED'; +var USER_PHONE_NEW_SUCCESS = exports.USER_PHONE_NEW_SUCCESS = 'USER_PHONE_NEW_SUCCESS'; +var USER_PHONE_NEW_FAILURE = exports.USER_PHONE_NEW_FAILURE = 'USER_PHONE_NEW_FAILURE'; +var USER_PHONE_VERIFY_STARTED = exports.USER_PHONE_VERIFY_STARTED = 'USER_PHONE_VERIFY_STARTED'; +var USER_PHONE_VERIFY_SUCCESS = exports.USER_PHONE_VERIFY_SUCCESS = 'USER_PHONE_VERIFY_SUCCESS'; +var USER_PHONE_VERIFY_FAILURE = exports.USER_PHONE_VERIFY_FAILURE = 'USER_PHONE_VERIFY_FAILURE'; +var USER_IDENTITY_VERIFY_STARTED = exports.USER_IDENTITY_VERIFY_STARTED = 'USER_IDENTITY_VERIFY_STARTED'; +var USER_IDENTITY_VERIFY_SUCCESS = exports.USER_IDENTITY_VERIFY_SUCCESS = 'USER_IDENTITY_VERIFY_SUCCESS'; +var USER_IDENTITY_VERIFY_FAILURE = exports.USER_IDENTITY_VERIFY_FAILURE = 'USER_IDENTITY_VERIFY_FAILURE'; +var USER_FETCH_STARTED = exports.USER_FETCH_STARTED = 'USER_FETCH_STARTED'; +var USER_FETCH_SUCCESS = exports.USER_FETCH_SUCCESS = 'USER_FETCH_SUCCESS'; +var USER_FETCH_FAILURE = exports.USER_FETCH_FAILURE = 'USER_FETCH_FAILURE'; +var USER_INVITE_STATUS_FETCH_STARTED = exports.USER_INVITE_STATUS_FETCH_STARTED = 'USER_INVITE_STATUS_FETCH_STARTED'; +var USER_INVITE_STATUS_FETCH_SUCCESS = exports.USER_INVITE_STATUS_FETCH_SUCCESS = 'USER_INVITE_STATUS_FETCH_SUCCESS'; +var USER_INVITE_STATUS_FETCH_FAILURE = exports.USER_INVITE_STATUS_FETCH_FAILURE = 'USER_INVITE_STATUS_FETCH_FAILURE'; +var USER_INVITE_NEW_STARTED = exports.USER_INVITE_NEW_STARTED = 'USER_INVITE_NEW_STARTED'; +var USER_INVITE_NEW_SUCCESS = exports.USER_INVITE_NEW_SUCCESS = 'USER_INVITE_NEW_SUCCESS'; +var USER_INVITE_NEW_FAILURE = exports.USER_INVITE_NEW_FAILURE = 'USER_INVITE_NEW_FAILURE'; +var FETCH_ACCESS_TOKEN_SUCCESS = exports.FETCH_ACCESS_TOKEN_SUCCESS = 'FETCH_ACCESS_TOKEN_SUCCESS'; + +// Rewards +var FETCH_REWARDS_STARTED = exports.FETCH_REWARDS_STARTED = 'FETCH_REWARDS_STARTED'; +var FETCH_REWARDS_COMPLETED = exports.FETCH_REWARDS_COMPLETED = 'FETCH_REWARDS_COMPLETED'; +var CLAIM_REWARD_STARTED = exports.CLAIM_REWARD_STARTED = 'CLAIM_REWARD_STARTED'; +var CLAIM_REWARD_SUCCESS = exports.CLAIM_REWARD_SUCCESS = 'CLAIM_REWARD_SUCCESS'; +var CLAIM_REWARD_FAILURE = exports.CLAIM_REWARD_FAILURE = 'CLAIM_REWARD_FAILURE'; +var CLAIM_REWARD_CLEAR_ERROR = exports.CLAIM_REWARD_CLEAR_ERROR = 'CLAIM_REWARD_CLEAR_ERROR'; +var FETCH_REWARD_CONTENT_COMPLETED = exports.FETCH_REWARD_CONTENT_COMPLETED = 'FETCH_REWARD_CONTENT_COMPLETED'; + +// Language +var DOWNLOAD_LANGUAGE_SUCCEEDED = exports.DOWNLOAD_LANGUAGE_SUCCEEDED = 'DOWNLOAD_LANGUAGE_SUCCEEDED'; +var DOWNLOAD_LANGUAGE_FAILED = exports.DOWNLOAD_LANGUAGE_FAILED = 'DOWNLOAD_LANGUAGE_FAILED'; + +// ShapeShift +var GET_SUPPORTED_COINS_START = exports.GET_SUPPORTED_COINS_START = 'GET_SUPPORTED_COINS_START'; +var GET_SUPPORTED_COINS_SUCCESS = exports.GET_SUPPORTED_COINS_SUCCESS = 'GET_SUPPORTED_COINS_SUCCESS'; +var GET_SUPPORTED_COINS_FAIL = exports.GET_SUPPORTED_COINS_FAIL = 'GET_SUPPORTED_COINS_FAIL'; +var GET_COIN_STATS_START = exports.GET_COIN_STATS_START = 'GET_COIN_STATS_START'; +var GET_COIN_STATS_SUCCESS = exports.GET_COIN_STATS_SUCCESS = 'GET_COIN_STATS_SUCCESS'; +var GET_COIN_STATS_FAIL = exports.GET_COIN_STATS_FAIL = 'GET_COIN_STATS_FAIL'; +var PREPARE_SHAPE_SHIFT_START = exports.PREPARE_SHAPE_SHIFT_START = 'PREPARE_SHAPE_SHIFT_START'; +var PREPARE_SHAPE_SHIFT_SUCCESS = exports.PREPARE_SHAPE_SHIFT_SUCCESS = 'PREPARE_SHAPE_SHIFT_SUCCESS'; +var PREPARE_SHAPE_SHIFT_FAIL = exports.PREPARE_SHAPE_SHIFT_FAIL = 'PREPARE_SHAPE_SHIFT_FAIL'; +var GET_ACTIVE_SHIFT_START = exports.GET_ACTIVE_SHIFT_START = 'GET_ACTIVE_SHIFT_START'; +var GET_ACTIVE_SHIFT_SUCCESS = exports.GET_ACTIVE_SHIFT_SUCCESS = 'GET_ACTIVE_SHIFT_SUCCESS'; +var GET_ACTIVE_SHIFT_FAIL = exports.GET_ACTIVE_SHIFT_FAIL = 'GET_ACTIVE_SHIFT_FAIL'; +var CLEAR_SHAPE_SHIFT = exports.CLEAR_SHAPE_SHIFT = 'CLEAR_SHAPE_SHIFT'; + +// Subscriptions +var CHANNEL_SUBSCRIBE = exports.CHANNEL_SUBSCRIBE = 'CHANNEL_SUBSCRIBE'; +var CHANNEL_UNSUBSCRIBE = exports.CHANNEL_UNSUBSCRIBE = 'CHANNEL_UNSUBSCRIBE'; +var HAS_FETCHED_SUBSCRIPTIONS = exports.HAS_FETCHED_SUBSCRIPTIONS = 'HAS_FETCHED_SUBSCRIPTIONS'; +var SET_SUBSCRIPTION_LATEST = exports.SET_SUBSCRIPTION_LATEST = 'SET_SUBSCRIPTION_LATEST'; +var SET_SUBSCRIPTION_NOTIFICATION = exports.SET_SUBSCRIPTION_NOTIFICATION = 'SET_SUBSCRIPTION_NOTIFICATION'; +var SET_SUBSCRIPTION_NOTIFICATIONS = exports.SET_SUBSCRIPTION_NOTIFICATIONS = 'SET_SUBSCRIPTION_NOTIFICATIONS'; +var CHECK_SUBSCRIPTION_STARTED = exports.CHECK_SUBSCRIPTION_STARTED = 'CHECK_SUBSCRIPTION_STARTED'; +var CHECK_SUBSCRIPTION_COMPLETED = exports.CHECK_SUBSCRIPTION_COMPLETED = 'CHECK_SUBSCRIPTION_COMPLETED'; +var CHECK_SUBSCRIPTIONS_SUBSCRIBE = exports.CHECK_SUBSCRIPTIONS_SUBSCRIBE = 'CHECK_SUBSCRIPTIONS_SUBSCRIBE'; + +// Video controls +var SET_VIDEO_PAUSE = exports.SET_VIDEO_PAUSE = 'SET_VIDEO_PAUSE'; + +// Media controls +var MEDIA_PLAY = exports.MEDIA_PLAY = 'MEDIA_PLAY'; +var MEDIA_PAUSE = exports.MEDIA_PAUSE = 'MEDIA_PAUSE'; +var MEDIA_POSITION = exports.MEDIA_POSITION = 'MEDIA_POSITION'; + +// Publishing +var CLEAR_PUBLISH = exports.CLEAR_PUBLISH = 'CLEAR_PUBLISH'; +var UPDATE_PUBLISH_FORM = exports.UPDATE_PUBLISH_FORM = 'UPDATE_PUBLISH_FORM'; +var PUBLISH_START = exports.PUBLISH_START = 'PUBLISH_START'; +var PUBLISH_SUCCESS = exports.PUBLISH_SUCCESS = 'PUBLISH_SUCCESS'; +var PUBLISH_FAIL = exports.PUBLISH_FAIL = 'PUBLISH_FAIL'; +var CLEAR_PUBLISH_ERROR = exports.CLEAR_PUBLISH_ERROR = 'CLEAR_PUBLISH_ERROR'; +var REMOVE_PENDING_PUBLISH = exports.REMOVE_PENDING_PUBLISH = 'REMOVE_PENDING_PUBLISH'; +var DO_PREPARE_EDIT = exports.DO_PREPARE_EDIT = 'DO_PREPARE_EDIT'; + +/***/ }), +/* 1 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +exports.__esModule = true; +exports.defaultMemoize = defaultMemoize; +exports.createSelectorCreator = createSelectorCreator; +exports.createStructuredSelector = createStructuredSelector; +function defaultEqualityCheck(a, b) { + return a === b; +} + +function areArgumentsShallowlyEqual(equalityCheck, prev, next) { + if (prev === null || next === null || prev.length !== next.length) { + return false; + } + + // Do this in a for loop (and not a `forEach` or an `every`) so we can determine equality as fast as possible. + var length = prev.length; + for (var i = 0; i < length; i++) { + if (!equalityCheck(prev[i], next[i])) { + return false; + } + } + + return true; +} + +function defaultMemoize(func) { + var equalityCheck = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultEqualityCheck; + + var lastArgs = null; + var lastResult = null; + // we reference arguments instead of spreading them for performance reasons + return function () { + if (!areArgumentsShallowlyEqual(equalityCheck, lastArgs, arguments)) { + // apply arguments instead of spreading for performance. + lastResult = func.apply(null, arguments); + } + + lastArgs = arguments; + return lastResult; + }; +} + +function getDependencies(funcs) { + var dependencies = Array.isArray(funcs[0]) ? funcs[0] : funcs; + + if (!dependencies.every(function (dep) { + return typeof dep === 'function'; + })) { + var dependencyTypes = dependencies.map(function (dep) { + return typeof dep; + }).join(', '); + throw new Error('Selector creators expect all input-selectors to be functions, ' + ('instead received the following types: [' + dependencyTypes + ']')); + } + + return dependencies; +} + +function createSelectorCreator(memoize) { + for (var _len = arguments.length, memoizeOptions = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + memoizeOptions[_key - 1] = arguments[_key]; + } + + return function () { + for (var _len2 = arguments.length, funcs = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + funcs[_key2] = arguments[_key2]; + } + + var recomputations = 0; + var resultFunc = funcs.pop(); + var dependencies = getDependencies(funcs); + + var memoizedResultFunc = memoize.apply(undefined, [function () { + recomputations++; + // apply arguments instead of spreading for performance. + return resultFunc.apply(null, arguments); + }].concat(memoizeOptions)); + + // If a selector is called with the exact same arguments we don't need to traverse our dependencies again. + var selector = defaultMemoize(function () { + var params = []; + var length = dependencies.length; + + for (var i = 0; i < length; i++) { + // apply arguments instead of spreading and mutate a local list of params for performance. + params.push(dependencies[i].apply(null, arguments)); + } + + // apply arguments instead of spreading for performance. + return memoizedResultFunc.apply(null, params); + }); + + selector.resultFunc = resultFunc; + selector.recomputations = function () { + return recomputations; + }; + selector.resetRecomputations = function () { + return recomputations = 0; + }; + return selector; + }; +} + +var createSelector = exports.createSelector = createSelectorCreator(defaultMemoize); + +function createStructuredSelector(selectors) { + var selectorCreator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : createSelector; + + if (typeof selectors !== 'object') { + throw new Error('createStructuredSelector expects first argument to be an object ' + ('where each property is a selector, instead received a ' + typeof selectors)); + } + var objectKeys = Object.keys(selectors); + return selectorCreator(objectKeys.map(function (key) { + return selectors[key]; + }), function () { + for (var _len3 = arguments.length, values = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { + values[_key3] = arguments[_key3]; + } + + return values.reduce(function (composition, value, index) { + composition[objectKeys[index]] = value; + return composition; + }, {}); + }); +} + +/***/ }), +/* 2 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + +var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); + +exports.parseURI = parseURI; +exports.buildURI = buildURI; +exports.normalizeURI = normalizeURI; +exports.isURIValid = isURIValid; +exports.isNameValid = isNameValid; +exports.isURIClaimable = isURIClaimable; +var channelNameMinLength = 1; +var claimIdMaxLength = 40; + +var regexInvalidURI = exports.regexInvalidURI = /[^A-Za-z0-9-]/g; +var regexAddress = exports.regexAddress = /^b(?=[^0OIl]{32,33})[0-9A-Za-z]{32,33}$/; + +/** + * Parses a LBRY name into its component parts. Throws errors with user-friendly + * messages for invalid names. + * + * N.B. that "name" indicates the value in the name position of the URI. For + * claims for channel content, this will actually be the channel name, and + * the content name is in the path (e.g. lbry://@channel/content) + * + * In most situations, you'll want to use the contentName and channelName keys + * and ignore the name key. + * + * Returns a dictionary with keys: + * - name (string): The value in the "name" position in the URI. Note that this + * could be either content name or channel name; see above. + * - path (string, if persent) + * - claimSequence (int, if present) + * - bidPosition (int, if present) + * - claimId (string, if present) + * - isChannel (boolean) + * - contentName (string): For anon claims, the name; for channel claims, the path + * - channelName (string, if present): Channel name without @ + */ +function parseURI(URI) { + var requireProto = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + + // Break into components. Empty sub-matches are converted to null + var componentsRegex = new RegExp('^((?:lbry://)?)' + // protocol + '([^:$#/]*)' + // claim name (stops at the first separator or end) + '([:$#]?)([^/]*)' + // modifier separator, modifier (stops at the first path separator or end) + '(/?)(.*)' // path separator, path + ); + + var _componentsRegex$exec = componentsRegex.exec(URI).slice(1).map(function (match) { + return match || null; + }), + _componentsRegex$exec2 = _slicedToArray(_componentsRegex$exec, 6), + proto = _componentsRegex$exec2[0], + claimName = _componentsRegex$exec2[1], + modSep = _componentsRegex$exec2[2], + modVal = _componentsRegex$exec2[3], + pathSep = _componentsRegex$exec2[4], + path = _componentsRegex$exec2[5]; + + var contentName = void 0; + + // Validate protocol + if (requireProto && !proto) { + throw new Error(__('LBRY URIs must include a protocol prefix (lbry://).')); + } + + // Validate and process name + if (!claimName) { + throw new Error(__('URI does not include name.')); + } + + var isChannel = claimName.startsWith('@'); + var channelName = isChannel ? claimName.slice(1) : claimName; + + if (isChannel) { + if (!channelName) { + throw new Error(__('No channel name after @.')); + } + + if (channelName.length < channelNameMinLength) { + throw new Error(__('Channel names must be at least %s characters.', channelNameMinLength)); + } + + contentName = path; + } + + var nameBadChars = (channelName || claimName).match(regexInvalidURI); + if (nameBadChars) { + throw new Error(__('Invalid character %s in name: %s.', nameBadChars.length === 1 ? '' : 's', nameBadChars.join(', '))); + } + + // Validate and process modifier (claim ID, bid position or claim sequence) + var claimId = void 0; + var claimSequence = void 0; + var bidPosition = void 0; + if (modSep) { + if (!modVal) { + throw new Error(__('No modifier provided after separator %s.', modSep)); + } + + if (modSep === '#') { + claimId = modVal; + } else if (modSep === ':') { + claimSequence = modVal; + } else if (modSep === '$') { + bidPosition = modVal; + } + } + + if (claimId && (claimId.length > claimIdMaxLength || !claimId.match(/^[0-9a-f]+$/)) && !claimId.match(/^pending/) // ought to be dropped when savePendingPublish drops hack + ) { + throw new Error(__('Invalid claim ID %s.', claimId)); + } + + if (claimSequence && !claimSequence.match(/^-?[1-9][0-9]*$/)) { + throw new Error(__('Claim sequence must be a number.')); + } + + if (bidPosition && !bidPosition.match(/^-?[1-9][0-9]*$/)) { + throw new Error(__('Bid position must be a number.')); + } + + // Validate and process path + if (path) { + if (!isChannel) { + throw new Error(__('Only channel URIs may have a path.')); + } + + var pathBadChars = path.match(regexInvalidURI); + if (pathBadChars) { + throw new Error(__('Invalid character in path: %s', pathBadChars.join(', '))); + } + + contentName = path; + } else if (pathSep) { + throw new Error(__('No path provided after /')); + } + + return _extends({ + claimName: claimName, + path: path, + isChannel: isChannel + }, contentName ? { contentName: contentName } : {}, channelName ? { channelName: channelName } : {}, claimSequence ? { claimSequence: parseInt(claimSequence, 10) } : {}, bidPosition ? { bidPosition: parseInt(bidPosition, 10) } : {}, claimId ? { claimId: claimId } : {}, path ? { path: path } : {}); +} + +/** + * Takes an object in the same format returned by parse() and builds a URI. + * + * The channelName key will accept names with or without the @ prefix. + */ +function buildURI(URIObj) { + var includeProto = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + var claimId = URIObj.claimId, + claimSequence = URIObj.claimSequence, + bidPosition = URIObj.bidPosition, + contentName = URIObj.contentName, + channelName = URIObj.channelName; + var claimName = URIObj.claimName, + path = URIObj.path; + + + if (channelName) { + var channelNameFormatted = channelName.startsWith('@') ? channelName : '@' + channelName; + if (!claimName) { + claimName = channelNameFormatted; + } else if (claimName !== channelNameFormatted) { + throw new Error(__('Received a channel content URI, but claim name and channelName do not match. "name" represents the value in the name position of the URI (lbry://name...), which for channel content will be the channel name. In most cases, to construct a channel URI you should just pass channelName and contentName.')); + } + } + + if (contentName) { + if (!claimName) { + claimName = contentName; + } else if (!path) { + path = contentName; + } + if (path && path !== contentName) { + throw new Error(__('Path and contentName do not match. Only one is required; most likely you wanted contentName.')); + } + } + + return (includeProto ? 'lbry://' : '') + claimName + (claimId ? '#' + claimId : '') + (claimSequence ? ':' + claimSequence : '') + (bidPosition ? '' + bidPosition : '') + (path ? '/' + path : ''); +} + +/* Takes a parseable LBRY URI and converts it to standard, canonical format */ +function normalizeURI(URI) { + if (URI.match(/pending_claim/)) return URI; + + var _parseURI = parseURI(URI), + claimName = _parseURI.claimName, + path = _parseURI.path, + bidPosition = _parseURI.bidPosition, + claimSequence = _parseURI.claimSequence, + claimId = _parseURI.claimId; + + return buildURI({ claimName: claimName, path: path, claimSequence: claimSequence, bidPosition: bidPosition, claimId: claimId }); +} + +function isURIValid(URI) { + var parts = void 0; + try { + parts = parseURI(normalizeURI(URI)); + } catch (error) { + return false; + } + return parts && parts.claimName; +} + +function isNameValid(claimName) { + var checkCase = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; + + var regexp = new RegExp('^[a-z0-9-]+$', checkCase ? '' : 'i'); + return regexp.test(claimName); +} + +function isURIClaimable(URI) { + var parts = void 0; + try { + parts = parseURI(normalizeURI(URI)); + } catch (error) { + return false; + } + return parts && parts.claimName && !parts.claimId && !parts.bidPosition && !parts.claimSequence && !parts.isChannel && !parts.path; +} + +/***/ }), +/* 3 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.selectRewardContentClaimIds = exports.makeSelectTotalPagesForChannel = exports.makeSelectTotalItemsForChannel = exports.selectChannelClaimCounts = exports.selectPlayingUri = exports.selectFetchingFeaturedUris = exports.selectFeaturedUris = exports.makeSelectIsUriResolving = exports.selectResolvingUris = exports.selectMyChannelClaims = exports.selectFetchingMyChannels = exports.selectMyClaimsOutpoints = exports.selectAllMyClaimsByOutpoint = exports.selectMyClaimsWithoutChannels = exports.selectMyClaims = exports.selectPendingClaims = exports.selectIsFetchingClaimListMine = exports.makeSelectContentTypeForUri = exports.makeSelectTitleForUri = exports.makeSelectMetadataForUri = exports.makeSelectClaimsInChannelForCurrentPage = exports.makeSelectFetchingChannelClaims = exports.selectAllFetchingChannelClaims = exports.makeSelectClaimIsMine = exports.selectMyActiveClaims = exports.selectAbandoningIds = exports.selectMyClaimsRaw = exports.makeSelectClaimForUri = exports.selectAllClaimsByChannel = exports.selectClaimsByUri = exports.selectClaimsById = undefined; + +var _lbryURI = __webpack_require__(2); + +var _navigation = __webpack_require__(5); + +var _reselect = __webpack_require__(1); function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } +var selectState = function selectState(state) { + return state.claims || {}; +}; + +var selectClaimsById = exports.selectClaimsById = (0, _reselect.createSelector)(selectState, function (state) { + return state.byId || {}; +}); + +var selectClaimsByUri = exports.selectClaimsByUri = (0, _reselect.createSelector)(selectState, selectClaimsById, function (state, byId) { + var byUri = state.claimsByUri || {}; + var claims = {}; + + Object.keys(byUri).forEach(function (uri) { + var claimId = byUri[uri]; + + // NOTE returning a null claim allows us to differentiate between an + // undefined (never fetched claim) and one which just doesn't exist. Not + // the cleanest solution but couldn't think of anything better right now + if (claimId === null) { + claims[uri] = null; + } else { + claims[uri] = byId[claimId]; + } + }); + + return claims; +}); + +var selectAllClaimsByChannel = exports.selectAllClaimsByChannel = (0, _reselect.createSelector)(selectState, function (state) { + return state.claimsByChannel || {}; +}); + +var makeSelectClaimForUri = exports.makeSelectClaimForUri = function makeSelectClaimForUri(uri) { + return (0, _reselect.createSelector)(selectClaimsByUri, function (claims) { + return claims && claims[(0, _lbryURI.normalizeURI)(uri)]; + }); +}; + +var selectMyClaimsRaw = exports.selectMyClaimsRaw = (0, _reselect.createSelector)(selectState, function (state) { + return state.myClaims; +}); + +var selectAbandoningIds = exports.selectAbandoningIds = (0, _reselect.createSelector)(selectState, function (state) { + return Object.keys(state.abandoningById || {}); +}); + +var selectMyActiveClaims = exports.selectMyActiveClaims = (0, _reselect.createSelector)(selectMyClaimsRaw, selectAbandoningIds, function (claims, abandoningIds) { + return new Set(claims && claims.map(function (claim) { + return claim.claim_id; + }).filter(function (claimId) { + return Object.keys(abandoningIds).indexOf(claimId) === -1; + })); +}); + +var makeSelectClaimIsMine = exports.makeSelectClaimIsMine = function makeSelectClaimIsMine(rawUri) { + var uri = (0, _lbryURI.normalizeURI)(rawUri); + return (0, _reselect.createSelector)(selectClaimsByUri, selectMyActiveClaims, function (claims, myClaims) { + return claims && claims[uri] && claims[uri].claim_id && myClaims.has(claims[uri].claim_id); + }); +}; + +var selectAllFetchingChannelClaims = exports.selectAllFetchingChannelClaims = (0, _reselect.createSelector)(selectState, function (state) { + return state.fetchingChannelClaims || {}; +}); + +var makeSelectFetchingChannelClaims = exports.makeSelectFetchingChannelClaims = function makeSelectFetchingChannelClaims(uri) { + return (0, _reselect.createSelector)(selectAllFetchingChannelClaims, function (fetching) { + return fetching && fetching[uri]; + }); +}; + +var makeSelectClaimsInChannelForCurrentPage = exports.makeSelectClaimsInChannelForCurrentPage = function makeSelectClaimsInChannelForCurrentPage(uri) { + var pageSelector = (0, _navigation.makeSelectCurrentParam)('page'); + + return (0, _reselect.createSelector)(selectClaimsById, selectAllClaimsByChannel, pageSelector, function (byId, allClaims, page) { + var byChannel = allClaims[uri] || {}; + var claimIds = byChannel[page || 1]; + + if (!claimIds) return claimIds; + + return claimIds.map(function (claimId) { + return byId[claimId]; + }); + }); +}; + +var makeSelectMetadataForUri = exports.makeSelectMetadataForUri = function makeSelectMetadataForUri(uri) { + return (0, _reselect.createSelector)(makeSelectClaimForUri(uri), function (claim) { + var metadata = claim && claim.value && claim.value.stream && claim.value.stream.metadata; + + return metadata || (claim === undefined ? undefined : null); + }); +}; + +var makeSelectTitleForUri = exports.makeSelectTitleForUri = function makeSelectTitleForUri(uri) { + return (0, _reselect.createSelector)(makeSelectMetadataForUri(uri), function (metadata) { + return metadata && metadata.title; + }); +}; + +var makeSelectContentTypeForUri = exports.makeSelectContentTypeForUri = function makeSelectContentTypeForUri(uri) { + return (0, _reselect.createSelector)(makeSelectClaimForUri(uri), function (claim) { + var source = claim && claim.value && claim.value.stream && claim.value.stream.source; + return source ? source.contentType : undefined; + }); +}; + +var selectIsFetchingClaimListMine = exports.selectIsFetchingClaimListMine = (0, _reselect.createSelector)(selectState, function (state) { + return state.isFetchingClaimListMine; +}); + +var selectPendingClaims = exports.selectPendingClaims = (0, _reselect.createSelector)(selectState, function (state) { + return Object.values(state.pendingById || {}); +}); + +var selectMyClaims = exports.selectMyClaims = (0, _reselect.createSelector)(selectMyActiveClaims, selectClaimsById, selectAbandoningIds, selectPendingClaims, function (myClaimIds, byId, abandoningIds, pendingClaims) { + var claims = []; + + myClaimIds.forEach(function (id) { + var claim = byId[id]; + + if (claim && abandoningIds.indexOf(id) === -1) claims.push(claim); + }); + + return [].concat(claims, _toConsumableArray(pendingClaims)); +}); + +var selectMyClaimsWithoutChannels = exports.selectMyClaimsWithoutChannels = (0, _reselect.createSelector)(selectMyClaims, function (myClaims) { + return myClaims.filter(function (claim) { + return !claim.name.match(/^@/); + }); +}); + +var selectAllMyClaimsByOutpoint = exports.selectAllMyClaimsByOutpoint = (0, _reselect.createSelector)(selectMyClaimsRaw, function (claims) { + return new Set(claims && claims.length ? claims.map(function (claim) { + return claim.txid + ':' + claim.nout; + }) : null); +}); + +var selectMyClaimsOutpoints = exports.selectMyClaimsOutpoints = (0, _reselect.createSelector)(selectMyClaims, function (myClaims) { + var outpoints = []; + + myClaims.forEach(function (claim) { + return outpoints.push(claim.txid + ':' + claim.nout); + }); + + return outpoints; +}); + +var selectFetchingMyChannels = exports.selectFetchingMyChannels = (0, _reselect.createSelector)(selectState, function (state) { + return state.fetchingMyChannels; +}); + +var selectMyChannelClaims = exports.selectMyChannelClaims = (0, _reselect.createSelector)(selectState, selectClaimsById, function (state, byId) { + var ids = state.myChannelClaims || []; + var claims = []; + + ids.forEach(function (id) { + if (byId[id]) { + // I'm not sure why this check is necessary, but it ought to be a quick fix for https://github.com/lbryio/lbry-app/issues/544 + claims.push(byId[id]); + } + }); + + return claims; +}); + +var selectResolvingUris = exports.selectResolvingUris = (0, _reselect.createSelector)(selectState, function (state) { + return state.resolvingUris || []; +}); + +var makeSelectIsUriResolving = exports.makeSelectIsUriResolving = function makeSelectIsUriResolving(uri) { + return (0, _reselect.createSelector)(selectResolvingUris, function (resolvingUris) { + return resolvingUris && resolvingUris.indexOf(uri) !== -1; + }); +}; + +var selectFeaturedUris = exports.selectFeaturedUris = (0, _reselect.createSelector)(selectState, function (state) { + return state.featuredUris; +}); + +var selectFetchingFeaturedUris = exports.selectFetchingFeaturedUris = (0, _reselect.createSelector)(selectState, function (state) { + return state.fetchingFeaturedContent; +}); + +var selectPlayingUri = exports.selectPlayingUri = (0, _reselect.createSelector)(selectState, function (state) { + return state.playingUri; +}); + +var selectChannelClaimCounts = exports.selectChannelClaimCounts = (0, _reselect.createSelector)(selectState, function (state) { + return state.channelClaimCounts || {}; +}); + +var makeSelectTotalItemsForChannel = exports.makeSelectTotalItemsForChannel = function makeSelectTotalItemsForChannel(uri) { + return (0, _reselect.createSelector)(selectChannelClaimCounts, function (byUri) { + return byUri && byUri[uri]; + }); +}; + +var makeSelectTotalPagesForChannel = exports.makeSelectTotalPagesForChannel = function makeSelectTotalPagesForChannel(uri) { + return (0, _reselect.createSelector)(selectChannelClaimCounts, function (byUri) { + return byUri && byUri[uri] && Math.ceil(byUri[uri] / 10); + }); +}; + +var selectRewardContentClaimIds = exports.selectRewardContentClaimIds = (0, _reselect.createSelector)(selectState, function (state) { + return state.rewardedContentClaimIds; +}); + +/***/ }), +/* 4 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +__webpack_require__(16); + var CHECK_DAEMON_STARTED_TRY_NUMBER = 200; + var Lbry = { isConnected: false, daemonConnectionString: 'http://localhost:5279', pendingPublishTimeout: 20 * 60 * 1000 }; -function apiCall(method, params, resolve, reject) { - return _jsonrpc2.default.call(Lbry.daemonConnectionString, method, params, resolve, reject, reject); +function checkAndParse(response) { + if (response.status >= 200 && response.status < 300) { + return response.json(); + } + return response.json().then(function (json) { + var error = void 0; + if (json.error) { + error = new Error(json.error); + } else { + error = new Error('Protocol error with unknown response signature'); + } + return Promise.reject(error); + }); } -var lbryProxy = new Proxy(Lbry, { - get: function get(target, name) { - if (name in target) { - return target[name]; - } +function apiCall(method, params, resolve, reject) { + var counter = new Date().getTime(); + var options = { + method: 'POST', + body: JSON.stringify({ + jsonrpc: '2.0', + method: method, + params: params, + id: counter + }) + }; - return function () { - var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - return new Promise(function (resolve, reject) { - apiCall(name, params, resolve, reject); - }); - }; - } -}); + return fetch(Lbry.daemonConnectionString, options).then(checkAndParse).then(function (response) { + var error = response.error || response.result && response.result.error; + + if (error) { + return reject(error); + } + return resolve(response.result); + }).catch(reject); +} function getLocal(key) { var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; - var itemRaw = localStorage.getItem(key); + // const itemRaw = localStorage.getItem(key); + var itemRaw = null; return itemRaw === null ? fallback : JSON.parse(itemRaw); } -function setLocal(key, value) { - localStorage.setItem(key, JSON.stringify(value)); -} +function setLocal(key, value) {} +// localStorage.setItem(key, JSON.stringify(value)); -/** - * Records a publish attempt in local storage. Returns a dictionary with all the data needed to - * needed to make a dummy claim or file info object. - */ -var pendingId = 0; -function savePendingPublish(_ref) { - var name = _ref.name, - channelName = _ref.channelName; - - pendingId += 1; - var pendingPublishes = getLocal('pendingPublishes') || []; - var newPendingPublish = { - name: name, - channelName: channelName, - claim_id: 'pending-' + pendingId, - txid: 'pending-' + pendingId, - nout: 0, - outpoint: 'pending-' + pendingId + ':0', - time: Date.now() - }; - setLocal('pendingPublishes', [].concat(_toConsumableArray(pendingPublishes), [newPendingPublish])); - return newPendingPublish; -} - -/** - * If there is a pending publish with the given name or outpoint, remove it. - * A channel name may also be provided along with name. - */ -function removePendingPublishIfNeeded(_ref2) { - var name = _ref2.name, - channelName = _ref2.channelName, - outpoint = _ref2.outpoint; - - function pubMatches(pub) { - return pub.outpoint === outpoint || pub.name === name && (!channelName || pub.channel_name === channelName); - } - - setLocal('pendingPublishes', Lbry.getPendingPublishes().filter(function (pub) { - return !pubMatches(pub); - })); -} - -/** - * Gets the current list of pending publish attempts. Filters out any that have timed out and - * removes them from the list. - */ -Lbry.getPendingPublishes = function () { - var pendingPublishes = getLocal('pendingPublishes') || []; - var newPendingPublishes = pendingPublishes.filter(function (pub) { - return Date.now() - pub.time <= Lbry.pendingPublishTimeout; - }); - setLocal('pendingPublishes', newPendingPublishes); - return newPendingPublishes; -}; - -/** - * Gets a pending publish attempt by its name or (fake) outpoint. A channel name can also be - * provided along withe the name. If no pending publish is found, returns null. - */ -function getPendingPublish(_ref3) { - var name = _ref3.name, - channelName = _ref3.channelName, - outpoint = _ref3.outpoint; - - var pendingPublishes = Lbry.getPendingPublishes(); - return pendingPublishes.find(function (pub) { - return pub.outpoint === outpoint || pub.name === name && (!channelName || pub.channel_name === channelName); - }) || null; -} - -function pendingPublishToDummyClaim(_ref4) { - var channelName = _ref4.channelName, - name = _ref4.name, - outpoint = _ref4.outpoint, - claimId = _ref4.claimId, - txid = _ref4.txid, - nout = _ref4.nout; - - return { name: name, outpoint: outpoint, claimId: claimId, txid: txid, nout: nout, channelName: channelName }; -} - -function pendingPublishToDummyFileInfo(_ref5) { - var name = _ref5.name, - outpoint = _ref5.outpoint, - claimId = _ref5.claimId; - - return { name: name, outpoint: outpoint, claimId: claimId, metadata: null }; -} // core +Lbry.status = function () { + return new Promise(function (resolve, reject) { + apiCall('status', {}, function (status) { + resolve(status); + }, reject); + }); +}; + +Lbry.file_delete = function () { + var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + return new Promise(function (resolve, reject) { + apiCall('file_delete', params, resolve, reject); + }); +}; + +Lbry.file_set_status = function () { + var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + return new Promise(function (resolve, reject) { + apiCall('file_set_status', params, resolve, reject); + }); +}; + Lbry.connectPromise = null; Lbry.connect = function () { if (Lbry.connectPromise === null) { Lbry.connectPromise = new Promise(function (resolve, reject) { var tryNum = 0; - // Check every half second to see if the daemon is accepting connections function checkDaemonStarted() { tryNum += 1; - lbryProxy.status().then(resolve).catch(function () { + Lbry.status().then(resolve).catch(function () { if (tryNum <= CHECK_DAEMON_STARTED_TRY_NUMBER) { setTimeout(checkDaemonStarted, tryNum < 50 ? 400 : 1000); } else { @@ -236,37 +989,6 @@ Lbry.connect = function () { return Lbry.connectPromise; }; -/** - * Publishes a file. The optional fileListedCallback is called when the file becomes available in - * lbry.file_list() during the publish process. - * - * This currently includes a work-around to cache the file in local storage so that the pending - * publish can appear in the UI immediately. - */ -Lbry.publishDeprecated = function (params, fileListedCallback, publishedCallback, errorCallback) { - // Give a short grace period in case publish() returns right away or (more likely) gives an error - var returnPendingTimeout = setTimeout(function () { - var name = params.name, - channelName = params.channel_name; - - if (publishedCallback || fileListedCallback) { - savePendingPublish({ - name: name, - channelName: channelName - }); - publishedCallback(true); - } - }, 2000, { once: true }); - - lbryProxy.publish(params).then(function (result) { - if (returnPendingTimeout) clearTimeout(returnPendingTimeout); - publishedCallback(result); - }, function (err) { - if (returnPendingTimeout) clearTimeout(returnPendingTimeout); - errorCallback(err); - }); -}; - Lbry.getMediaType = function (contentType, fileName) { if (contentType) { return (/^[^/]+/.exec(contentType)[0] @@ -302,35 +1024,13 @@ Lbry.getMediaType = function (contentType, fileName) { Lbry.file_list = function () { var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return new Promise(function (resolve, reject) { - var name = params.name, + var claimName = params.claim_name, channelName = params.channel_name, outpoint = params.outpoint; - /** - * If we're searching by outpoint, check first to see if there's a matching pending publish. - * Pending publishes use their own faux outpoints that are always unique, so we don't need - * to check if there's a real file. - */ - - if (outpoint) { - var pendingPublish = getPendingPublish({ outpoint: outpoint }); - if (pendingPublish) { - resolve([pendingPublishToDummyFileInfo(pendingPublish)]); - return; - } - } apiCall('file_list', params, function (fileInfos) { - removePendingPublishIfNeeded({ name: name, channelName: channelName, outpoint: outpoint }); - - // if a naked file_list call, append the pending file infos - if (!name && !channelName && !outpoint) { - var dummyFileInfos = Lbry.getPendingPublishes().map(pendingPublishToDummyFileInfo); - - resolve([].concat(_toConsumableArray(fileInfos), _toConsumableArray(dummyFileInfos))); - } else { - resolve(fileInfos); - } + resolve(fileInfos); }, reject); }); }; @@ -339,21 +1039,16 @@ Lbry.claim_list_mine = function () { var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return new Promise(function (resolve, reject) { apiCall('claim_list_mine', params, function (claims) { - claims.forEach(function (_ref6) { - var name = _ref6.name, - channelName = _ref6.channel_name, - txid = _ref6.txid, - nout = _ref6.nout; + resolve(claims); + }, reject); + }); +}; - removePendingPublishIfNeeded({ - name: name, - channelName: channelName, - outpoint: txid + ':' + nout - }); - }); - - var dummyClaims = Lbry.getPendingPublishes().map(pendingPublishToDummyClaim); - resolve([].concat(_toConsumableArray(claims), _toConsumableArray(dummyClaims))); +Lbry.get = function () { + var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + return new Promise(function (resolve, reject) { + apiCall('get', params, function (streamInfo) { + resolve(streamInfo); }, reject); }); }; @@ -372,10 +1067,25 @@ Lbry.resolve = function () { }); }; +var lbryProxy = new Proxy(Lbry, { + get: function get(target, name) { + if (name in target) { + return target[name]; + } + + return function () { + var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + return new Promise(function (resolve, reject) { + apiCall(name, params, resolve, reject); + }); + }; + } +}); + exports.default = lbryProxy; /***/ }), -/* 1 */ +/* 5 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -384,115 +1094,468 @@ exports.default = lbryProxy; Object.defineProperty(exports, "__esModule", { value: true }); -exports.costInfoReducer = exports.LbryApi = exports.Lbry = undefined; +exports.selectNavLinks = exports.selectPageTitle = exports.selectActiveHistoryEntry = exports.selectHistoryStack = exports.selectHistoryIndex = exports.selectIsHome = exports.selectIsForwardDisabled = exports.selectIsBackDisabled = exports.selectPathAfterAuth = exports.makeSelectCurrentParam = exports.selectCurrentParams = exports.selectCurrentPage = exports.computePageFromPath = exports.selectCurrentPath = exports.selectState = undefined; -var _lbry = __webpack_require__(0); +var _reselect = __webpack_require__(1); -var _lbry2 = _interopRequireDefault(_lbry); +var _query_params = __webpack_require__(11); -var _lbryapi = __webpack_require__(3); +var selectState = exports.selectState = function selectState(state) { + return state.navigation || {}; +}; -var _lbryapi2 = _interopRequireDefault(_lbryapi); - -var _cost_info = __webpack_require__(8); - -var _cost_info2 = _interopRequireDefault(_cost_info); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -var Lbry = exports.Lbry = _lbry2.default; -var LbryApi = exports.LbryApi = _lbryapi2.default; -var costInfoReducer = exports.costInfoReducer = _cost_info2.default; - -/***/ }), -/* 2 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true +var selectCurrentPath = exports.selectCurrentPath = (0, _reselect.createSelector)(selectState, function (state) { + return state.currentPath; }); -var jsonrpc = {}; -jsonrpc.call = function (connectionString, method, params, callback, errorCallback, connectFailedCallback) { - function checkAndParse(response) { - if (response.status >= 200 && response.status < 300) { - return response.json(); - } - return response.json().then(function (json) { - var error = void 0; - if (json.error) { - error = new Error(json.error); - } else { - error = new Error('Protocol error with unknown response signature'); - } - return Promise.reject(error); - }); - } +var computePageFromPath = exports.computePageFromPath = function computePageFromPath(path) { + return path.replace(/^\//, '').split('?')[0]; +}; - var counter = parseInt(sessionStorage.getItem('JSONRPCCounter') || 0, 10); - var url = connectionString; - var options = { - method: 'POST', - body: JSON.stringify({ - jsonrpc: '2.0', - method: method, - params: params, - id: counter - }) - }; +var selectCurrentPage = exports.selectCurrentPage = (0, _reselect.createSelector)(selectCurrentPath, function (path) { + return computePageFromPath(path); +}); - sessionStorage.setItem('JSONRPCCounter', counter + 1); +var selectCurrentParams = exports.selectCurrentParams = (0, _reselect.createSelector)(selectCurrentPath, function (path) { + if (path === undefined) return {}; + if (!path.match(/\?/)) return {}; - return fetch(url, options).then(checkAndParse).then(function (response) { - var error = response.error || response.result && response.result.error; + return (0, _query_params.parseQueryParams)(path.split('?')[1]); +}); - if (!error && typeof callback === 'function') { - return callback(response.result); - } - - if (error && typeof errorCallback === 'function') { - return errorCallback(error); - } - - var errorEvent = new CustomEvent('unhandledError', { - detail: { - connectionString: connectionString, - method: method, - params: params, - code: error.code, - message: error.message || error, - data: error.data - } - }); - document.dispatchEvent(errorEvent); - - return Promise.resolve(); - }).catch(function (error) { - if (connectFailedCallback) { - return connectFailedCallback(error); - } - - var errorEvent = new CustomEvent('unhandledError', { - detail: { - connectionString: connectionString, - method: method, - params: params, - code: error.response && error.response.status, - message: __('Connection to API server failed') - } - }); - document.dispatchEvent(errorEvent); - return Promise.resolve(); +var makeSelectCurrentParam = exports.makeSelectCurrentParam = function makeSelectCurrentParam(param) { + return (0, _reselect.createSelector)(selectCurrentParams, function (params) { + return params ? params[param] : undefined; }); }; -exports.default = jsonrpc; +var selectPathAfterAuth = exports.selectPathAfterAuth = (0, _reselect.createSelector)(selectState, function (state) { + return state.pathAfterAuth; +}); + +var selectIsBackDisabled = exports.selectIsBackDisabled = (0, _reselect.createSelector)(selectState, function (state) { + return state.index === 0; +}); + +var selectIsForwardDisabled = exports.selectIsForwardDisabled = (0, _reselect.createSelector)(selectState, function (state) { + return state.index === state.stack.length - 1; +}); + +var selectIsHome = exports.selectIsHome = (0, _reselect.createSelector)(selectCurrentPage, function (page) { + return page === 'discover'; +}); + +var selectHistoryIndex = exports.selectHistoryIndex = (0, _reselect.createSelector)(selectState, function (state) { + return state.index; +}); + +var selectHistoryStack = exports.selectHistoryStack = (0, _reselect.createSelector)(selectState, function (state) { + return state.stack; +}); + +// returns current page attributes (scrollY, path) +var selectActiveHistoryEntry = exports.selectActiveHistoryEntry = (0, _reselect.createSelector)(selectState, function (state) { + return state.stack[state.index]; +}); + +var selectPageTitle = exports.selectPageTitle = (0, _reselect.createSelector)(selectCurrentPage, function (page) { + switch (page) { + default: + return ''; + } +}); + +var selectNavLinks = exports.selectNavLinks = (0, _reselect.createSelector)(selectCurrentPage, selectHistoryStack, function (currentPage, historyStack) { + var isWalletPage = function isWalletPage(page) { + return page === 'wallet' || page === 'send' || page === 'getcredits' || page === 'rewards' || page === 'history' || page === 'invite'; + }; + + var isMyLbryPage = function isMyLbryPage(page) { + return page === 'downloaded' || page === 'published' || page === 'settings'; + }; + + var previousStack = historyStack.slice().reverse(); + + var getPreviousSubLinkPath = function getPreviousSubLinkPath(checkIfValidPage) { + for (var i = 0; i < previousStack.length; i += 1) { + var currentStackItem = previousStack[i]; + + // Trim off the "/" from the path + var pageInStack = currentStackItem.path.slice(1); + if (checkIfValidPage(pageInStack)) { + return currentStackItem.path; + } + } + + return undefined; + }; + + // Gets the last active sublink in a section + var getActiveSublink = function getActiveSublink(category) { + if (category === 'wallet') { + var previousPath = getPreviousSubLinkPath(isWalletPage); + return previousPath || '/wallet'; + } else if (category === 'myLbry') { + var _previousPath = getPreviousSubLinkPath(isMyLbryPage); + return _previousPath || '/downloaded'; + } + + return undefined; + }; + + var isCurrentlyWalletPage = isWalletPage(currentPage); + var isCurrentlyMyLbryPage = isMyLbryPage(currentPage); + + var walletSubLinks = [{ + label: 'Overview', + path: '/wallet', + active: currentPage === 'wallet' + }, { + label: 'Send & Recieve', + path: '/send', + active: currentPage === 'send' + }, { + label: 'Get Credits', + path: '/getcredits', + active: currentPage === 'getcredits' + }, { + label: 'Rewards', + path: '/rewards', + active: currentPage === 'rewards' + }, { + label: 'Invites', + path: '/invite', + active: currentPage === 'invite' + }, { + label: 'Transactions', + path: '/history', + active: currentPage === 'history' + }]; + + var myLbrySubLinks = [{ + label: 'Downloads', + path: '/downloaded', + active: currentPage === 'downloaded' + }, { + label: 'Publishes', + path: '/published', + active: currentPage === 'published' + }, { + label: 'Settings', + path: '/settings', + active: currentPage === 'settings' + }, { + label: 'Backup', + path: '/backup', + active: currentPage === 'backup' + }]; + + var navLinks = { + primary: [{ + label: 'Explore', + path: '/discover', + active: currentPage === 'discover', + icon: 'Compass' + }, { + label: 'Subscriptions', + path: '/subscriptions', + active: currentPage === 'subscriptions', + icon: 'AtSign' + }], + secondary: [{ + label: 'Wallet', + icon: 'CreditCard', + subLinks: walletSubLinks, + path: isCurrentlyWalletPage ? '/wallet' : getActiveSublink('wallet'), + active: isWalletPage(currentPage) + }, { + label: 'My LBRY', + icon: 'Settings', + subLinks: myLbrySubLinks, + path: isCurrentlyMyLbryPage ? '/downloaded' : getActiveSublink('myLbry'), + active: isMyLbryPage(currentPage) + }, { + label: 'Publish', + icon: 'UploadCloud', + path: '/publish', + active: currentPage === 'publish' + }, { + label: 'Help', + path: '/help', + active: currentPage === 'help', + icon: 'HelpCircle' + }] + }; + + return navLinks; +}); /***/ }), -/* 3 */ +/* 6 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.doNotify = doNotify; + +var _action_types = __webpack_require__(0); + +var ACTIONS = _interopRequireWildcard(_action_types); + +var _Notification = __webpack_require__(10); + +var _Notification2 = _interopRequireDefault(_Notification); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +function doNotify(data) { + return { + type: ACTIONS.CREATE_NOTIFICATION, + data: data + }; +} + +/***/ }), +/* 7 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); + +exports.doResolveUris = doResolveUris; +exports.doResolveUri = doResolveUri; +exports.doFetchClaimListMine = doFetchClaimListMine; +exports.doAbandonClaim = doAbandonClaim; +exports.doFetchFeaturedUris = doFetchFeaturedUris; +exports.doFetchRewardedContent = doFetchRewardedContent; + +var _action_types = __webpack_require__(0); + +var ACTIONS = _interopRequireWildcard(_action_types); + +var _lbry = __webpack_require__(4); + +var _lbry2 = _interopRequireDefault(_lbry); + +var _lbryapi = __webpack_require__(8); + +var _lbryapi2 = _interopRequireDefault(_lbryapi); + +var _lbryURI = __webpack_require__(2); + +var _notifications = __webpack_require__(6); + +var _claims = __webpack_require__(3); + +var _batchActions = __webpack_require__(9); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } + +function doResolveUris(uris) { + return function (dispatch, getState) { + var normalizedUris = uris.map(_lbryURI.normalizeURI); + var state = getState(); + + // Filter out URIs that are already resolving + var resolvingUris = (0, _claims.selectResolvingUris)(state); + var urisToResolve = normalizedUris.filter(function (uri) { + return !resolvingUris.includes(uri); + }); + + if (urisToResolve.length === 0) { + return; + } + + dispatch({ + type: ACTIONS.RESOLVE_URIS_STARTED, + data: { uris: normalizedUris } + }); + + var resolveInfo = {}; + _lbry2.default.resolve({ uris: urisToResolve }).then(function (result) { + Object.entries(result).forEach(function (_ref) { + var _ref2 = _slicedToArray(_ref, 2), + uri = _ref2[0], + uriResolveInfo = _ref2[1]; + + var fallbackResolveInfo = { + claim: null, + claimsInChannel: null, + certificate: null + }; + + var _ref3 = uriResolveInfo && !uriResolveInfo.error ? uriResolveInfo : fallbackResolveInfo, + claim = _ref3.claim, + certificate = _ref3.certificate, + claimsInChannel = _ref3.claims_in_channel; + + resolveInfo[uri] = { claim: claim, certificate: certificate, claimsInChannel: claimsInChannel }; + }); + + dispatch({ + type: ACTIONS.RESOLVE_URIS_COMPLETED, + data: { resolveInfo: resolveInfo } + }); + }); + }; +} + +function doResolveUri(uri) { + return doResolveUris([uri]); +} + +function doFetchClaimListMine() { + return function (dispatch) { + dispatch({ + type: ACTIONS.FETCH_CLAIM_LIST_MINE_STARTED + }); + + _lbry2.default.claim_list_mine().then(function (claims) { + dispatch({ + type: ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED, + data: { + claims: claims + } + }); + }); + }; +} + +function doAbandonClaim(txid, nout) { + return function (dispatch, getState) { + var state = getState(); + var myClaims = (0, _claims.selectMyClaimsRaw)(state); + + var _myClaims$find = myClaims.find(function (claim) { + return claim.txid === txid && claim.nout === nout; + }), + claimId = _myClaims$find.claim_id, + name = _myClaims$find.name; + + dispatch({ + type: ACTIONS.ABANDON_CLAIM_STARTED, + data: { + claimId: claimId + } + }); + + var errorCallback = function errorCallback() { + dispatch((0, _notifications.doNotify)({ + title: 'Transaction failed', + message: 'Transaction failed', + type: 'error', + displayType: ['modal', 'toast'] + })); + }; + + var successCallback = function successCallback(results) { + if (results.txid) { + dispatch({ + type: ACTIONS.ABANDON_CLAIM_SUCCEEDED, + data: { + claimId: claimId + } + }); + dispatch(doResolveUri((0, _lbryURI.buildURI)({ name: name, claimId: claimId }))); + dispatch(doFetchClaimListMine()); + } else { + dispatch((0, _notifications.doNotify)({ + title: 'Transaction failed', + message: 'Transaction failed', + type: 'error', + displayType: ['modal', 'toast'] + })); + } + }; + + _lbry2.default.claim_abandon({ + txid: txid, + nout: nout + }).then(successCallback, errorCallback); + }; +} + +function doFetchFeaturedUris() { + return function (dispatch) { + dispatch({ + type: ACTIONS.FETCH_FEATURED_CONTENT_STARTED + }); + + var success = function success(_ref4) { + var Uris = _ref4.Uris; + + var urisToResolve = []; + Object.keys(Uris).forEach(function (category) { + urisToResolve = [].concat(_toConsumableArray(urisToResolve), _toConsumableArray(Uris[category])); + }); + + var actions = [doResolveUris(urisToResolve), { + type: ACTIONS.FETCH_FEATURED_CONTENT_COMPLETED, + data: { + uris: Uris, + success: true + } + }]; + dispatch(_batchActions.batchActions.apply(undefined, actions)); + }; + + var failure = function failure() { + dispatch({ + type: ACTIONS.FETCH_FEATURED_CONTENT_COMPLETED, + data: { + uris: {} + } + }); + }; + + _lbryapi2.default.call('file', 'list_homepage').then(success, failure); + }; +} + +function doFetchRewardedContent() { + return function (dispatch) { + var success = function success(nameToClaimId) { + dispatch({ + type: ACTIONS.FETCH_REWARD_CONTENT_COMPLETED, + data: { + claimIds: Object.values(nameToClaimId), + success: true + } + }); + }; + + var failure = function failure() { + dispatch({ + type: ACTIONS.FETCH_REWARD_CONTENT_COMPLETED, + data: { + claimIds: [], + success: false + } + }); + }; + + _lbryapi2.default.call('reward', 'list_featured').then(success, failure); + }; +} + +/***/ }), +/* 8 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -504,17 +1567,14 @@ Object.defineProperty(exports, "__esModule", { var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; -var _lbry = __webpack_require__(0); - -var _lbry2 = _interopRequireDefault(_lbry); - -var _querystring = __webpack_require__(5); +var _querystring = __webpack_require__(19); var _querystring2 = _interopRequireDefault(_querystring); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -var LbryApi = { +var Lbryapi = { + enabled: true, exchangePromise: null, exchangeLastFetched: null }; @@ -524,10 +1584,10 @@ var CONNECTION_STRING = process.env.LBRY_APP_API_URL ? process.env.LBRY_APP_API_ var EXCHANGE_RATE_TIMEOUT = 20 * 60 * 1000; -LbryApi.getExchangeRates = function () { - if (!LbryApi.exchangeLastFetched || Date.now() - LbryApi.exchangeLastFetched > EXCHANGE_RATE_TIMEOUT) { - LbryApi.exchangePromise = new Promise(function (resolve, reject) { - LbryApi.call('lbc', 'exchange_rate', {}, 'get', true).then(function (_ref) { +Lbryapi.getExchangeRates = function () { + if (!Lbryapi.exchangeLastFetched || Date.now() - Lbryapi.exchangeLastFetched > EXCHANGE_RATE_TIMEOUT) { + Lbryapi.exchangePromise = new Promise(function (resolve, reject) { + Lbryapi.call('lbc', 'exchange_rate', {}, 'get', true).then(function (_ref) { var LBC_USD = _ref.lbc_usd, LBC_BTC = _ref.lbc_btc, BTC_USD = _ref.btc_usd; @@ -536,17 +1596,16 @@ LbryApi.getExchangeRates = function () { resolve(rates); }).catch(reject); }); - LbryApi.exchangeLastFetched = Date.now(); + Lbryapi.exchangeLastFetched = Date.now(); } - return LbryApi.exchangePromise; + return Lbryapi.exchangePromise; }; -LbryApi.call = function (resource, action) { +Lbryapi.call = function (resource, action) { var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var method = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'get'; - if (!Lbryio.enabled) { - console.log(__('Internal API disabled')); + if (!Lbryapi.enabled) { return Promise.reject(new Error(__('LBRY internal API is disabled'))); } @@ -598,11 +1657,1563 @@ LbryApi.call = function (resource, action) { }); }; -exports.default = LbryApi; -/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4))) +exports.default = Lbryapi; +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(18))) /***/ }), -/* 4 */ +/* 9 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.batchActions = batchActions; +// https://github.com/reactjs/redux/issues/911 +function batchActions() { + for (var _len = arguments.length, actions = Array(_len), _key = 0; _key < _len; _key++) { + actions[_key] = arguments[_key]; + } + + return { + type: 'BATCH_ACTIONS', + actions: actions + }; +} + +/***/ }), +/* 10 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +/***/ }), +/* 11 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); + +exports.parseQueryParams = parseQueryParams; +exports.toQueryString = toQueryString; +function parseQueryParams(queryString) { + if (queryString === '') return {}; + var parts = queryString.split('?').pop().split('&').map(function (p) { + return p.split('='); + }); + + var params = {}; + parts.forEach(function (array) { + var _array = _slicedToArray(array, 2), + first = _array[0], + second = _array[1]; + + params[first] = second; + }); + return params; +} + +function toQueryString(params) { + if (!params) return ''; + + var parts = []; + Object.keys(params).forEach(function (key) { + if (Object.prototype.hasOwnProperty.call(params, key) && params[key]) { + parts.push(key + '=' + params[key]); + } + }); + + return parts.join('&'); +} + +/***/ }), +/* 12 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.selectSearchDownloadUris = exports.selectTotalDownloadProgress = exports.selectDownloadingFileInfos = exports.selectFileInfosDownloaded = exports.makeSelectLoadingForUri = exports.selectUrisLoading = exports.makeSelectDownloadingForUri = exports.selectDownloadingByOutpoint = exports.makeSelectFileInfoForUri = exports.selectIsFetchingFileListDownloadedOrPublished = exports.selectIsFetchingFileList = exports.selectFileInfosByOutpoint = exports.selectState = undefined; + +var _claims = __webpack_require__(3); + +var _reselect = __webpack_require__(1); + +var _lbryURI = __webpack_require__(2); + +var selectState = exports.selectState = function selectState(state) { + return state.fileInfo || {}; +}; + +var selectFileInfosByOutpoint = exports.selectFileInfosByOutpoint = (0, _reselect.createSelector)(selectState, function (state) { + return state.byOutpoint || {}; +}); + +var selectIsFetchingFileList = exports.selectIsFetchingFileList = (0, _reselect.createSelector)(selectState, function (state) { + return state.isFetchingFileList; +}); + +var selectIsFetchingFileListDownloadedOrPublished = exports.selectIsFetchingFileListDownloadedOrPublished = (0, _reselect.createSelector)(selectIsFetchingFileList, _claims.selectIsFetchingClaimListMine, function (isFetchingFileList, isFetchingClaimListMine) { + return isFetchingFileList || isFetchingClaimListMine; +}); + +var makeSelectFileInfoForUri = exports.makeSelectFileInfoForUri = function makeSelectFileInfoForUri(uri) { + return (0, _reselect.createSelector)(_claims.selectClaimsByUri, selectFileInfosByOutpoint, function (claims, byOutpoint) { + var claim = claims[uri]; + var outpoint = claim ? claim.txid + ':' + claim.nout : undefined; + return outpoint ? byOutpoint[outpoint] : undefined; + }); +}; + +var selectDownloadingByOutpoint = exports.selectDownloadingByOutpoint = (0, _reselect.createSelector)(selectState, function (state) { + return state.downloadingByOutpoint || {}; +}); + +var makeSelectDownloadingForUri = exports.makeSelectDownloadingForUri = function makeSelectDownloadingForUri(uri) { + return (0, _reselect.createSelector)(selectDownloadingByOutpoint, makeSelectFileInfoForUri(uri), function (byOutpoint, fileInfo) { + if (!fileInfo) return false; + return byOutpoint[fileInfo.outpoint]; + }); +}; + +var selectUrisLoading = exports.selectUrisLoading = (0, _reselect.createSelector)(selectState, function (state) { + return state.urisLoading || {}; +}); + +var makeSelectLoadingForUri = exports.makeSelectLoadingForUri = function makeSelectLoadingForUri(uri) { + return (0, _reselect.createSelector)(selectUrisLoading, function (byUri) { + return byUri && byUri[uri]; + }); +}; + +var selectFileInfosDownloaded = exports.selectFileInfosDownloaded = (0, _reselect.createSelector)(selectFileInfosByOutpoint, _claims.selectMyClaims, function (byOutpoint, myClaims) { + return Object.values(byOutpoint).filter(function (fileInfo) { + var myClaimIds = myClaims.map(function (claim) { + return claim.claim_id; + }); + + return fileInfo && myClaimIds.indexOf(fileInfo.claim_id) === -1 && (fileInfo.completed || fileInfo.written_bytes); + }); +}); + +// export const selectFileInfoForUri = (state, props) => { +// const claims = selectClaimsByUri(state), +// claim = claims[props.uri], +// fileInfos = selectAllFileInfos(state), +// outpoint = claim ? `${claim.txid}:${claim.nout}` : undefined; + +// return outpoint && fileInfos ? fileInfos[outpoint] : undefined; +// }; + +var selectDownloadingFileInfos = exports.selectDownloadingFileInfos = (0, _reselect.createSelector)(selectDownloadingByOutpoint, selectFileInfosByOutpoint, function (downloadingByOutpoint, fileInfosByOutpoint) { + var outpoints = Object.keys(downloadingByOutpoint); + var fileInfos = []; + + outpoints.forEach(function (outpoint) { + var fileInfo = fileInfosByOutpoint[outpoint]; + + if (fileInfo) fileInfos.push(fileInfo); + }); + + return fileInfos; +}); + +var selectTotalDownloadProgress = exports.selectTotalDownloadProgress = (0, _reselect.createSelector)(selectDownloadingFileInfos, function (fileInfos) { + var progress = []; + + fileInfos.forEach(function (fileInfo) { + progress.push(fileInfo.written_bytes / fileInfo.total_bytes * 100); + }); + + var totalProgress = progress.reduce(function (a, b) { + return a + b; + }, 0); + + if (fileInfos.length > 0) return totalProgress / fileInfos.length / 100.0; + return -1; +}); + +var selectSearchDownloadUris = exports.selectSearchDownloadUris = function selectSearchDownloadUris(query) { + return (0, _reselect.createSelector)(selectFileInfosDownloaded, _claims.selectClaimsById, function (fileInfos, claimsById) { + if (!query || !fileInfos.length) { + return null; + } + + var queryParts = query.toLowerCase().split(' '); + var searchQueryDictionary = {}; + queryParts.forEach(function (subQuery) { + searchQueryDictionary[subQuery] = subQuery; + }); + + var arrayContainsQueryPart = function arrayContainsQueryPart(array) { + for (var i = 0; i < array.length; i += 1) { + var subQuery = array[i]; + if (searchQueryDictionary[subQuery]) { + return true; + } + } + return false; + }; + + var downloadResultsFromQuery = []; + fileInfos.forEach(function (fileInfo) { + var channelName = fileInfo.channel_name, + claimName = fileInfo.claim_name, + metadata = fileInfo.metadata; + var author = metadata.author, + description = metadata.description, + title = metadata.title; + + + if (channelName) { + var lowerCaseChannel = channelName.toLowerCase(); + var strippedOutChannelName = lowerCaseChannel.slice(1); // trim off the @ + if (searchQueryDictionary[channelName] || searchQueryDictionary[strippedOutChannelName]) { + downloadResultsFromQuery.push(fileInfo); + return; + } + } + + var nameParts = claimName.toLowerCase().split('-'); + if (arrayContainsQueryPart(nameParts)) { + downloadResultsFromQuery.push(fileInfo); + return; + } + + var titleParts = title.toLowerCase().split(' '); + if (arrayContainsQueryPart(titleParts)) { + downloadResultsFromQuery.push(fileInfo); + return; + } + + if (author) { + var authorParts = author.toLowerCase().split(' '); + if (arrayContainsQueryPart(authorParts)) { + downloadResultsFromQuery.push(fileInfo); + return; + } + } + + if (description) { + var descriptionParts = description.toLowerCase().split(' '); + if (arrayContainsQueryPart(descriptionParts)) { + downloadResultsFromQuery.push(fileInfo); + } + } + }); + + return downloadResultsFromQuery.length ? downloadResultsFromQuery.map(function (fileInfo) { + var channelName = fileInfo.channel_name, + claimId = fileInfo.claim_id, + claimName = fileInfo.claim_name; + + + var uriParams = {}; + + if (channelName) { + var claim = claimsById[claimId]; + if (claim.value) { + uriParams.claimId = claim.value.publisherSignature.certificateId; + } else { + uriParams.claimId = claimId; + } + uriParams.channelName = channelName; + uriParams.contentName = claimName; + } else { + uriParams.claimId = claimId; + uriParams.claimName = claimName; + } + + var uri = (0, _lbryURI.buildURI)(uriParams); + return uri; + }) : null; + }); +}; + +/***/ }), +/* 13 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.selectWunderBarAddress = exports.makeSelectSearchUris = exports.selectSearchUrisByQuery = exports.selectIsSearching = exports.selectSearchQuery = exports.selectSearchValue = exports.selectState = undefined; + +var _navigation = __webpack_require__(5); + +var _reselect = __webpack_require__(1); + +var selectState = exports.selectState = function selectState(state) { + return state.search || {}; +}; + +var selectSearchValue = exports.selectSearchValue = (0, _reselect.createSelector)(selectState, function (state) { + return state.searchQuery; +}); + +var selectSearchQuery = exports.selectSearchQuery = (0, _reselect.createSelector)(_navigation.selectCurrentPage, _navigation.selectCurrentParams, function (page, params) { + return page === 'search' ? params && params.query : null; +}); + +var selectIsSearching = exports.selectIsSearching = (0, _reselect.createSelector)(selectState, function (state) { + return state.searching; +}); + +var selectSearchUrisByQuery = exports.selectSearchUrisByQuery = (0, _reselect.createSelector)(selectState, function (state) { + return state.urisByQuery; +}); + +var makeSelectSearchUris = exports.makeSelectSearchUris = function makeSelectSearchUris(query) { + return ( + // replace statement below is kind of ugly, and repeated in doSearch action + (0, _reselect.createSelector)(selectSearchUrisByQuery, function (byQuery) { + return byQuery[query ? query.replace(/^lbry:\/\//i, '') : query]; + }) + ); +}; + +var selectWunderBarAddress = exports.selectWunderBarAddress = (0, _reselect.createSelector)(_navigation.selectCurrentPage, selectSearchQuery, _navigation.selectCurrentParams, function (page, query, params) { + // only populate the wunderbar address if we are on the file/channel pages + // or show the search query + if (page === 'show') { + return params.uri; + } + return query; +}); + +/***/ }), +/* 14 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.makeSelectBlockDate = exports.selectBlocks = exports.selectDraftTransactionError = exports.selectDraftTransactionAddress = exports.selectDraftTransactionAmount = exports.selectDraftTransaction = exports.selectGettingNewAddress = exports.selectReceiveAddress = exports.selectIsSendingSupport = exports.selectIsFetchingTransactions = exports.selectHasTransactions = exports.selectRecentTransactions = exports.selectTransactionItems = exports.selectTransactionsById = exports.selectBalance = exports.selectState = undefined; + +var _reselect = __webpack_require__(1); + +function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } + +var selectState = exports.selectState = function selectState(state) { + return state.wallet || {}; +}; + +var selectBalance = exports.selectBalance = (0, _reselect.createSelector)(selectState, function (state) { + return state.balance; +}); + +var selectTransactionsById = exports.selectTransactionsById = (0, _reselect.createSelector)(selectState, function (state) { + return state.transactions; +}); + +var selectTransactionItems = exports.selectTransactionItems = (0, _reselect.createSelector)(selectTransactionsById, function (byId) { + var items = []; + + Object.keys(byId).forEach(function (txid) { + var tx = byId[txid]; + + // ignore dust/fees + // it is fee only txn if all infos are also empty + if (Math.abs(tx.value) === Math.abs(tx.fee) && tx.claim_info.length === 0 && tx.support_info.length === 0 && tx.update_info.length === 0) { + return; + } + + var append = []; + + append.push.apply(append, _toConsumableArray(tx.claim_info.map(function (item) { + return Object.assign({}, tx, item, { + type: item.claim_name[0] === '@' ? 'channel' : 'publish' + }); + }))); + append.push.apply(append, _toConsumableArray(tx.support_info.map(function (item) { + return Object.assign({}, tx, item, { + type: !item.is_tip ? 'support' : 'tip' + }); + }))); + append.push.apply(append, _toConsumableArray(tx.update_info.map(function (item) { + return Object.assign({}, tx, item, { type: 'update' }); + }))); + + if (!append.length) { + append.push(Object.assign({}, tx, { + type: tx.value < 0 ? 'spend' : 'receive' + })); + } + + items.push.apply(items, _toConsumableArray(append.map(function (item) { + // value on transaction, amount on outpoint + // amount is always positive, but should match sign of value + var amount = parseFloat(item.balance_delta ? item.balance_delta : item.value); + + return { + txid: txid, + date: tx.timestamp ? new Date(Number(tx.timestamp) * 1000) : null, + amount: amount, + fee: amount < 0 ? -1 * tx.fee / append.length : 0, + claim_id: item.claim_id, + claim_name: item.claim_name, + type: item.type || 'send', + nout: item.nout + }; + }))); + }); + return items.reverse(); +}); + +var selectRecentTransactions = exports.selectRecentTransactions = (0, _reselect.createSelector)(selectTransactionItems, function (transactions) { + var threshold = new Date(); + threshold.setDate(threshold.getDate() - 7); + return transactions.filter(function (transaction) { + return transaction.date > threshold; + }); +}); + +var selectHasTransactions = exports.selectHasTransactions = (0, _reselect.createSelector)(selectTransactionItems, function (transactions) { + return transactions && transactions.length > 0; +}); + +var selectIsFetchingTransactions = exports.selectIsFetchingTransactions = (0, _reselect.createSelector)(selectState, function (state) { + return state.fetchingTransactions; +}); + +var selectIsSendingSupport = exports.selectIsSendingSupport = (0, _reselect.createSelector)(selectState, function (state) { + return state.sendingSupport; +}); + +var selectReceiveAddress = exports.selectReceiveAddress = (0, _reselect.createSelector)(selectState, function (state) { + return state.receiveAddress; +}); + +var selectGettingNewAddress = exports.selectGettingNewAddress = (0, _reselect.createSelector)(selectState, function (state) { + return state.gettingNewAddress; +}); + +var selectDraftTransaction = exports.selectDraftTransaction = (0, _reselect.createSelector)(selectState, function (state) { + return state.draftTransaction || {}; +}); + +var selectDraftTransactionAmount = exports.selectDraftTransactionAmount = (0, _reselect.createSelector)(selectDraftTransaction, function (draft) { + return draft.amount; +}); + +var selectDraftTransactionAddress = exports.selectDraftTransactionAddress = (0, _reselect.createSelector)(selectDraftTransaction, function (draft) { + return draft.address; +}); + +var selectDraftTransactionError = exports.selectDraftTransactionError = (0, _reselect.createSelector)(selectDraftTransaction, function (draft) { + return draft.error; +}); + +var selectBlocks = exports.selectBlocks = (0, _reselect.createSelector)(selectState, function (state) { + return state.blocks; +}); + +var makeSelectBlockDate = exports.makeSelectBlockDate = function makeSelectBlockDate(block) { + return (0, _reselect.createSelector)(selectBlocks, function (blocks) { + return blocks && blocks[block] ? new Date(blocks[block].time * 1000) : undefined; + }); +}; + +/***/ }), +/* 15 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.selectBlocks = exports.selectDraftTransactionError = exports.selectDraftTransactionAddress = exports.selectDraftTransactionAmount = exports.selectDraftTransaction = exports.selectGettingNewAddress = exports.selectReceiveAddress = exports.selectIsSendingSupport = exports.selectIsFetchingTransactions = exports.selectHasTransactions = exports.selectRecentTransactions = exports.selectTransactionItems = exports.selectTransactionsById = exports.selectBalance = exports.makeSelectBlockDate = exports.selectWunderBarAddress = exports.selectSearchUrisByQuery = exports.selectIsSearching = exports.selectSearchValue = exports.selectSearchQuery = exports.makeSelectSearchUris = exports.selectSearchState = exports.selectNavLinks = exports.selectActiveHistoryEntry = exports.selectHistoryStack = exports.selectHistoryIndex = exports.selectIsForwardDisabled = exports.selectIsBackDisabled = exports.selectPathAfterAuth = exports.selectPageTitle = exports.selectHeaderLinks = undefined; +exports.selectCurrentParams = exports.selectCurrentPage = exports.selectCurrentPath = exports.makeSelectCurrentParam = exports.computePageFromPath = exports.selectSearchDownloadUris = exports.selectTotalDownloadProgress = exports.selectDownloadingFileInfos = exports.selectFileInfosDownloaded = exports.selectUrisLoading = exports.selectDownloadingByOutpoint = exports.selectIsFetchingFileListDownloadedOrPublished = exports.selectIsFetchingFileList = exports.selectFileInfosByOutpoint = exports.makeSelectLoadingForUri = exports.makeSelectDownloadingForUri = exports.makeSelectFileInfoForUri = exports.selectFetchingCostInfo = exports.selectCostForCurrentPageUri = exports.selectAllCostInfoByUri = exports.makeSelectCostInfoForUri = exports.makeSelectFetchingCostInfoForUri = exports.selectRewardContentClaimIds = exports.selectChannelClaimCounts = exports.selectPlayingUri = exports.selectFetchingFeaturedUris = exports.selectFeaturedUris = exports.selectResolvingUris = exports.selectMyChannelClaims = exports.selectFetchingMyChannels = exports.selectMyClaimsOutpoints = exports.selectAllMyClaimsByOutpoint = exports.selectMyClaimsWithoutChannels = exports.selectMyClaims = exports.selectPendingClaims = exports.selectIsFetchingClaimListMine = exports.selectAllFetchingChannelClaims = exports.selectMyActiveClaims = exports.selectAbandoningIds = exports.selectMyClaimsRaw = exports.selectAllClaimsByChannel = exports.selectClaimsByUri = exports.selectClaimsById = exports.makeSelectTotalPagesForChannel = exports.makeSelectTotalItemsForChannel = exports.makeSelectIsUriResolving = exports.makeSelectContentTypeForUri = exports.makeSelectTitleForUri = exports.makeSelectMetadataForUri = exports.makeSelectClaimsInChannelForCurrentPage = exports.makeSelectFetchingChannelClaims = exports.makeSelectClaimIsMine = exports.makeSelectClaimForUri = exports.selectNotification = exports.walletReducer = exports.searchReducer = exports.notificationsReducer = exports.fileInfoReducer = exports.costInfoReducer = exports.claimsReducer = exports.formatFullPrice = exports.formatCredits = exports.toQueryString = exports.parseQueryParams = exports.batchActions = exports.doSendSupport = exports.doSetDraftTransactionAddress = exports.doSetDraftTransactionAmount = exports.doSendDraftTransaction = exports.doCheckAddressIsMine = exports.doGetNewAddress = exports.doFetchBlock = exports.doFetchTransactions = exports.doBalanceSubscribe = exports.doUpdateBalance = exports.doUpdateSearchQuery = exports.doSearch = exports.doFetchFileInfosAndPublishedClaims = exports.doFileList = exports.doFetchFileInfo = exports.doFetchCostInfoForUri = exports.doFetchRewardedContent = exports.doFetchFeaturedUris = exports.doResolveUri = exports.doResolveUris = exports.doAbandonClaim = exports.doFetchClaimListMine = exports.doNotify = exports.isURIClaimable = exports.isURIValid = exports.normalizeURI = exports.buildURI = exports.parseURI = exports.regexAddress = exports.regexInvalidURI = exports.Lbryapi = exports.Lbry = exports.SETTINGS = exports.ACTIONS = exports.Notification = undefined; + +var _Notification = __webpack_require__(10); + +Object.defineProperty(exports, 'Notification', { + enumerable: true, + get: function get() { + return _Notification.Notification; + } +}); + +var _lbryURI = __webpack_require__(2); + +Object.defineProperty(exports, 'regexInvalidURI', { + enumerable: true, + get: function get() { + return _lbryURI.regexInvalidURI; + } +}); +Object.defineProperty(exports, 'regexAddress', { + enumerable: true, + get: function get() { + return _lbryURI.regexAddress; + } +}); +Object.defineProperty(exports, 'parseURI', { + enumerable: true, + get: function get() { + return _lbryURI.parseURI; + } +}); +Object.defineProperty(exports, 'buildURI', { + enumerable: true, + get: function get() { + return _lbryURI.buildURI; + } +}); +Object.defineProperty(exports, 'normalizeURI', { + enumerable: true, + get: function get() { + return _lbryURI.normalizeURI; + } +}); +Object.defineProperty(exports, 'isURIValid', { + enumerable: true, + get: function get() { + return _lbryURI.isURIValid; + } +}); +Object.defineProperty(exports, 'isURIClaimable', { + enumerable: true, + get: function get() { + return _lbryURI.isURIClaimable; + } +}); + +var _notifications = __webpack_require__(6); + +Object.defineProperty(exports, 'doNotify', { + enumerable: true, + get: function get() { + return _notifications.doNotify; + } +}); + +var _claims = __webpack_require__(7); + +Object.defineProperty(exports, 'doFetchClaimListMine', { + enumerable: true, + get: function get() { + return _claims.doFetchClaimListMine; + } +}); +Object.defineProperty(exports, 'doAbandonClaim', { + enumerable: true, + get: function get() { + return _claims.doAbandonClaim; + } +}); +Object.defineProperty(exports, 'doResolveUris', { + enumerable: true, + get: function get() { + return _claims.doResolveUris; + } +}); +Object.defineProperty(exports, 'doResolveUri', { + enumerable: true, + get: function get() { + return _claims.doResolveUri; + } +}); +Object.defineProperty(exports, 'doFetchFeaturedUris', { + enumerable: true, + get: function get() { + return _claims.doFetchFeaturedUris; + } +}); +Object.defineProperty(exports, 'doFetchRewardedContent', { + enumerable: true, + get: function get() { + return _claims.doFetchRewardedContent; + } +}); + +var _cost_info = __webpack_require__(22); + +Object.defineProperty(exports, 'doFetchCostInfoForUri', { + enumerable: true, + get: function get() { + return _cost_info.doFetchCostInfoForUri; + } +}); + +var _file_info = __webpack_require__(23); + +Object.defineProperty(exports, 'doFetchFileInfo', { + enumerable: true, + get: function get() { + return _file_info.doFetchFileInfo; + } +}); +Object.defineProperty(exports, 'doFileList', { + enumerable: true, + get: function get() { + return _file_info.doFileList; + } +}); +Object.defineProperty(exports, 'doFetchFileInfosAndPublishedClaims', { + enumerable: true, + get: function get() { + return _file_info.doFetchFileInfosAndPublishedClaims; + } +}); + +var _search = __webpack_require__(24); + +Object.defineProperty(exports, 'doSearch', { + enumerable: true, + get: function get() { + return _search.doSearch; + } +}); +Object.defineProperty(exports, 'doUpdateSearchQuery', { + enumerable: true, + get: function get() { + return _search.doUpdateSearchQuery; + } +}); + +var _wallet = __webpack_require__(27); + +Object.defineProperty(exports, 'doUpdateBalance', { + enumerable: true, + get: function get() { + return _wallet.doUpdateBalance; + } +}); +Object.defineProperty(exports, 'doBalanceSubscribe', { + enumerable: true, + get: function get() { + return _wallet.doBalanceSubscribe; + } +}); +Object.defineProperty(exports, 'doFetchTransactions', { + enumerable: true, + get: function get() { + return _wallet.doFetchTransactions; + } +}); +Object.defineProperty(exports, 'doFetchBlock', { + enumerable: true, + get: function get() { + return _wallet.doFetchBlock; + } +}); +Object.defineProperty(exports, 'doGetNewAddress', { + enumerable: true, + get: function get() { + return _wallet.doGetNewAddress; + } +}); +Object.defineProperty(exports, 'doCheckAddressIsMine', { + enumerable: true, + get: function get() { + return _wallet.doCheckAddressIsMine; + } +}); +Object.defineProperty(exports, 'doSendDraftTransaction', { + enumerable: true, + get: function get() { + return _wallet.doSendDraftTransaction; + } +}); +Object.defineProperty(exports, 'doSetDraftTransactionAmount', { + enumerable: true, + get: function get() { + return _wallet.doSetDraftTransactionAmount; + } +}); +Object.defineProperty(exports, 'doSetDraftTransactionAddress', { + enumerable: true, + get: function get() { + return _wallet.doSetDraftTransactionAddress; + } +}); +Object.defineProperty(exports, 'doSendSupport', { + enumerable: true, + get: function get() { + return _wallet.doSendSupport; + } +}); + +var _batchActions = __webpack_require__(9); + +Object.defineProperty(exports, 'batchActions', { + enumerable: true, + get: function get() { + return _batchActions.batchActions; + } +}); + +var _query_params = __webpack_require__(11); + +Object.defineProperty(exports, 'parseQueryParams', { + enumerable: true, + get: function get() { + return _query_params.parseQueryParams; + } +}); +Object.defineProperty(exports, 'toQueryString', { + enumerable: true, + get: function get() { + return _query_params.toQueryString; + } +}); + +var _formatCredits = __webpack_require__(28); + +Object.defineProperty(exports, 'formatCredits', { + enumerable: true, + get: function get() { + return _formatCredits.formatCredits; + } +}); +Object.defineProperty(exports, 'formatFullPrice', { + enumerable: true, + get: function get() { + return _formatCredits.formatFullPrice; + } +}); + +var _claims2 = __webpack_require__(29); + +Object.defineProperty(exports, 'claimsReducer', { + enumerable: true, + get: function get() { + return _claims2.claimsReducer; + } +}); + +var _cost_info2 = __webpack_require__(30); + +Object.defineProperty(exports, 'costInfoReducer', { + enumerable: true, + get: function get() { + return _cost_info2.costInfoReducer; + } +}); + +var _file_info2 = __webpack_require__(31); + +Object.defineProperty(exports, 'fileInfoReducer', { + enumerable: true, + get: function get() { + return _file_info2.fileInfoReducer; + } +}); + +var _notifications2 = __webpack_require__(32); + +Object.defineProperty(exports, 'notificationsReducer', { + enumerable: true, + get: function get() { + return _notifications2.notificationsReducer; + } +}); + +var _search2 = __webpack_require__(33); + +Object.defineProperty(exports, 'searchReducer', { + enumerable: true, + get: function get() { + return _search2.searchReducer; + } +}); + +var _wallet2 = __webpack_require__(35); + +Object.defineProperty(exports, 'walletReducer', { + enumerable: true, + get: function get() { + return _wallet2.walletReducer; + } +}); + +var _notifications3 = __webpack_require__(36); + +Object.defineProperty(exports, 'selectNotification', { + enumerable: true, + get: function get() { + return _notifications3.selectNotification; + } +}); + +var _claims3 = __webpack_require__(3); + +Object.defineProperty(exports, 'makeSelectClaimForUri', { + enumerable: true, + get: function get() { + return _claims3.makeSelectClaimForUri; + } +}); +Object.defineProperty(exports, 'makeSelectClaimIsMine', { + enumerable: true, + get: function get() { + return _claims3.makeSelectClaimIsMine; + } +}); +Object.defineProperty(exports, 'makeSelectFetchingChannelClaims', { + enumerable: true, + get: function get() { + return _claims3.makeSelectFetchingChannelClaims; + } +}); +Object.defineProperty(exports, 'makeSelectClaimsInChannelForCurrentPage', { + enumerable: true, + get: function get() { + return _claims3.makeSelectClaimsInChannelForCurrentPage; + } +}); +Object.defineProperty(exports, 'makeSelectMetadataForUri', { + enumerable: true, + get: function get() { + return _claims3.makeSelectMetadataForUri; + } +}); +Object.defineProperty(exports, 'makeSelectTitleForUri', { + enumerable: true, + get: function get() { + return _claims3.makeSelectTitleForUri; + } +}); +Object.defineProperty(exports, 'makeSelectContentTypeForUri', { + enumerable: true, + get: function get() { + return _claims3.makeSelectContentTypeForUri; + } +}); +Object.defineProperty(exports, 'makeSelectIsUriResolving', { + enumerable: true, + get: function get() { + return _claims3.makeSelectIsUriResolving; + } +}); +Object.defineProperty(exports, 'makeSelectTotalItemsForChannel', { + enumerable: true, + get: function get() { + return _claims3.makeSelectTotalItemsForChannel; + } +}); +Object.defineProperty(exports, 'makeSelectTotalPagesForChannel', { + enumerable: true, + get: function get() { + return _claims3.makeSelectTotalPagesForChannel; + } +}); +Object.defineProperty(exports, 'selectClaimsById', { + enumerable: true, + get: function get() { + return _claims3.selectClaimsById; + } +}); +Object.defineProperty(exports, 'selectClaimsByUri', { + enumerable: true, + get: function get() { + return _claims3.selectClaimsByUri; + } +}); +Object.defineProperty(exports, 'selectAllClaimsByChannel', { + enumerable: true, + get: function get() { + return _claims3.selectAllClaimsByChannel; + } +}); +Object.defineProperty(exports, 'selectMyClaimsRaw', { + enumerable: true, + get: function get() { + return _claims3.selectMyClaimsRaw; + } +}); +Object.defineProperty(exports, 'selectAbandoningIds', { + enumerable: true, + get: function get() { + return _claims3.selectAbandoningIds; + } +}); +Object.defineProperty(exports, 'selectMyActiveClaims', { + enumerable: true, + get: function get() { + return _claims3.selectMyActiveClaims; + } +}); +Object.defineProperty(exports, 'selectAllFetchingChannelClaims', { + enumerable: true, + get: function get() { + return _claims3.selectAllFetchingChannelClaims; + } +}); +Object.defineProperty(exports, 'selectIsFetchingClaimListMine', { + enumerable: true, + get: function get() { + return _claims3.selectIsFetchingClaimListMine; + } +}); +Object.defineProperty(exports, 'selectPendingClaims', { + enumerable: true, + get: function get() { + return _claims3.selectPendingClaims; + } +}); +Object.defineProperty(exports, 'selectMyClaims', { + enumerable: true, + get: function get() { + return _claims3.selectMyClaims; + } +}); +Object.defineProperty(exports, 'selectMyClaimsWithoutChannels', { + enumerable: true, + get: function get() { + return _claims3.selectMyClaimsWithoutChannels; + } +}); +Object.defineProperty(exports, 'selectAllMyClaimsByOutpoint', { + enumerable: true, + get: function get() { + return _claims3.selectAllMyClaimsByOutpoint; + } +}); +Object.defineProperty(exports, 'selectMyClaimsOutpoints', { + enumerable: true, + get: function get() { + return _claims3.selectMyClaimsOutpoints; + } +}); +Object.defineProperty(exports, 'selectFetchingMyChannels', { + enumerable: true, + get: function get() { + return _claims3.selectFetchingMyChannels; + } +}); +Object.defineProperty(exports, 'selectMyChannelClaims', { + enumerable: true, + get: function get() { + return _claims3.selectMyChannelClaims; + } +}); +Object.defineProperty(exports, 'selectResolvingUris', { + enumerable: true, + get: function get() { + return _claims3.selectResolvingUris; + } +}); +Object.defineProperty(exports, 'selectFeaturedUris', { + enumerable: true, + get: function get() { + return _claims3.selectFeaturedUris; + } +}); +Object.defineProperty(exports, 'selectFetchingFeaturedUris', { + enumerable: true, + get: function get() { + return _claims3.selectFetchingFeaturedUris; + } +}); +Object.defineProperty(exports, 'selectPlayingUri', { + enumerable: true, + get: function get() { + return _claims3.selectPlayingUri; + } +}); +Object.defineProperty(exports, 'selectChannelClaimCounts', { + enumerable: true, + get: function get() { + return _claims3.selectChannelClaimCounts; + } +}); +Object.defineProperty(exports, 'selectRewardContentClaimIds', { + enumerable: true, + get: function get() { + return _claims3.selectRewardContentClaimIds; + } +}); + +var _cost_info3 = __webpack_require__(37); + +Object.defineProperty(exports, 'makeSelectFetchingCostInfoForUri', { + enumerable: true, + get: function get() { + return _cost_info3.makeSelectFetchingCostInfoForUri; + } +}); +Object.defineProperty(exports, 'makeSelectCostInfoForUri', { + enumerable: true, + get: function get() { + return _cost_info3.makeSelectCostInfoForUri; + } +}); +Object.defineProperty(exports, 'selectAllCostInfoByUri', { + enumerable: true, + get: function get() { + return _cost_info3.selectAllCostInfoByUri; + } +}); +Object.defineProperty(exports, 'selectCostForCurrentPageUri', { + enumerable: true, + get: function get() { + return _cost_info3.selectCostForCurrentPageUri; + } +}); +Object.defineProperty(exports, 'selectFetchingCostInfo', { + enumerable: true, + get: function get() { + return _cost_info3.selectFetchingCostInfo; + } +}); + +var _file_info3 = __webpack_require__(12); + +Object.defineProperty(exports, 'makeSelectFileInfoForUri', { + enumerable: true, + get: function get() { + return _file_info3.makeSelectFileInfoForUri; + } +}); +Object.defineProperty(exports, 'makeSelectDownloadingForUri', { + enumerable: true, + get: function get() { + return _file_info3.makeSelectDownloadingForUri; + } +}); +Object.defineProperty(exports, 'makeSelectLoadingForUri', { + enumerable: true, + get: function get() { + return _file_info3.makeSelectLoadingForUri; + } +}); +Object.defineProperty(exports, 'selectFileInfosByOutpoint', { + enumerable: true, + get: function get() { + return _file_info3.selectFileInfosByOutpoint; + } +}); +Object.defineProperty(exports, 'selectIsFetchingFileList', { + enumerable: true, + get: function get() { + return _file_info3.selectIsFetchingFileList; + } +}); +Object.defineProperty(exports, 'selectIsFetchingFileListDownloadedOrPublished', { + enumerable: true, + get: function get() { + return _file_info3.selectIsFetchingFileListDownloadedOrPublished; + } +}); +Object.defineProperty(exports, 'selectDownloadingByOutpoint', { + enumerable: true, + get: function get() { + return _file_info3.selectDownloadingByOutpoint; + } +}); +Object.defineProperty(exports, 'selectUrisLoading', { + enumerable: true, + get: function get() { + return _file_info3.selectUrisLoading; + } +}); +Object.defineProperty(exports, 'selectFileInfosDownloaded', { + enumerable: true, + get: function get() { + return _file_info3.selectFileInfosDownloaded; + } +}); +Object.defineProperty(exports, 'selectDownloadingFileInfos', { + enumerable: true, + get: function get() { + return _file_info3.selectDownloadingFileInfos; + } +}); +Object.defineProperty(exports, 'selectTotalDownloadProgress', { + enumerable: true, + get: function get() { + return _file_info3.selectTotalDownloadProgress; + } +}); +Object.defineProperty(exports, 'selectSearchDownloadUris', { + enumerable: true, + get: function get() { + return _file_info3.selectSearchDownloadUris; + } +}); + +var _navigation = __webpack_require__(5); + +Object.defineProperty(exports, 'computePageFromPath', { + enumerable: true, + get: function get() { + return _navigation.computePageFromPath; + } +}); +Object.defineProperty(exports, 'makeSelectCurrentParam', { + enumerable: true, + get: function get() { + return _navigation.makeSelectCurrentParam; + } +}); +Object.defineProperty(exports, 'selectCurrentPath', { + enumerable: true, + get: function get() { + return _navigation.selectCurrentPath; + } +}); +Object.defineProperty(exports, 'selectCurrentPage', { + enumerable: true, + get: function get() { + return _navigation.selectCurrentPage; + } +}); +Object.defineProperty(exports, 'selectCurrentParams', { + enumerable: true, + get: function get() { + return _navigation.selectCurrentParams; + } +}); +Object.defineProperty(exports, 'selectHeaderLinks', { + enumerable: true, + get: function get() { + return _navigation.selectHeaderLinks; + } +}); +Object.defineProperty(exports, 'selectPageTitle', { + enumerable: true, + get: function get() { + return _navigation.selectPageTitle; + } +}); +Object.defineProperty(exports, 'selectPathAfterAuth', { + enumerable: true, + get: function get() { + return _navigation.selectPathAfterAuth; + } +}); +Object.defineProperty(exports, 'selectIsBackDisabled', { + enumerable: true, + get: function get() { + return _navigation.selectIsBackDisabled; + } +}); +Object.defineProperty(exports, 'selectIsForwardDisabled', { + enumerable: true, + get: function get() { + return _navigation.selectIsForwardDisabled; + } +}); +Object.defineProperty(exports, 'selectHistoryIndex', { + enumerable: true, + get: function get() { + return _navigation.selectHistoryIndex; + } +}); +Object.defineProperty(exports, 'selectHistoryStack', { + enumerable: true, + get: function get() { + return _navigation.selectHistoryStack; + } +}); +Object.defineProperty(exports, 'selectActiveHistoryEntry', { + enumerable: true, + get: function get() { + return _navigation.selectActiveHistoryEntry; + } +}); +Object.defineProperty(exports, 'selectNavLinks', { + enumerable: true, + get: function get() { + return _navigation.selectNavLinks; + } +}); + +var _search3 = __webpack_require__(13); + +Object.defineProperty(exports, 'makeSelectSearchUris', { + enumerable: true, + get: function get() { + return _search3.makeSelectSearchUris; + } +}); +Object.defineProperty(exports, 'selectSearchQuery', { + enumerable: true, + get: function get() { + return _search3.selectSearchQuery; + } +}); +Object.defineProperty(exports, 'selectSearchValue', { + enumerable: true, + get: function get() { + return _search3.selectSearchValue; + } +}); +Object.defineProperty(exports, 'selectIsSearching', { + enumerable: true, + get: function get() { + return _search3.selectIsSearching; + } +}); +Object.defineProperty(exports, 'selectSearchUrisByQuery', { + enumerable: true, + get: function get() { + return _search3.selectSearchUrisByQuery; + } +}); +Object.defineProperty(exports, 'selectWunderBarAddress', { + enumerable: true, + get: function get() { + return _search3.selectWunderBarAddress; + } +}); + +var _wallet3 = __webpack_require__(14); + +Object.defineProperty(exports, 'makeSelectBlockDate', { + enumerable: true, + get: function get() { + return _wallet3.makeSelectBlockDate; + } +}); +Object.defineProperty(exports, 'selectBalance', { + enumerable: true, + get: function get() { + return _wallet3.selectBalance; + } +}); +Object.defineProperty(exports, 'selectTransactionsById', { + enumerable: true, + get: function get() { + return _wallet3.selectTransactionsById; + } +}); +Object.defineProperty(exports, 'selectTransactionItems', { + enumerable: true, + get: function get() { + return _wallet3.selectTransactionItems; + } +}); +Object.defineProperty(exports, 'selectRecentTransactions', { + enumerable: true, + get: function get() { + return _wallet3.selectRecentTransactions; + } +}); +Object.defineProperty(exports, 'selectHasTransactions', { + enumerable: true, + get: function get() { + return _wallet3.selectHasTransactions; + } +}); +Object.defineProperty(exports, 'selectIsFetchingTransactions', { + enumerable: true, + get: function get() { + return _wallet3.selectIsFetchingTransactions; + } +}); +Object.defineProperty(exports, 'selectIsSendingSupport', { + enumerable: true, + get: function get() { + return _wallet3.selectIsSendingSupport; + } +}); +Object.defineProperty(exports, 'selectReceiveAddress', { + enumerable: true, + get: function get() { + return _wallet3.selectReceiveAddress; + } +}); +Object.defineProperty(exports, 'selectGettingNewAddress', { + enumerable: true, + get: function get() { + return _wallet3.selectGettingNewAddress; + } +}); +Object.defineProperty(exports, 'selectDraftTransaction', { + enumerable: true, + get: function get() { + return _wallet3.selectDraftTransaction; + } +}); +Object.defineProperty(exports, 'selectDraftTransactionAmount', { + enumerable: true, + get: function get() { + return _wallet3.selectDraftTransactionAmount; + } +}); +Object.defineProperty(exports, 'selectDraftTransactionAddress', { + enumerable: true, + get: function get() { + return _wallet3.selectDraftTransactionAddress; + } +}); +Object.defineProperty(exports, 'selectDraftTransactionError', { + enumerable: true, + get: function get() { + return _wallet3.selectDraftTransactionError; + } +}); +Object.defineProperty(exports, 'selectBlocks', { + enumerable: true, + get: function get() { + return _wallet3.selectBlocks; + } +}); + +var _action_types = __webpack_require__(0); + +var ACTIONS = _interopRequireWildcard(_action_types); + +var _settings = __webpack_require__(38); + +var SETTINGS = _interopRequireWildcard(_settings); + +var _lbry = __webpack_require__(4); + +var _lbry2 = _interopRequireDefault(_lbry); + +var _lbryapi = __webpack_require__(8); + +var _lbryapi2 = _interopRequireDefault(_lbryapi); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +// constants +exports.ACTIONS = ACTIONS; +exports.SETTINGS = SETTINGS; + +// common + +exports.Lbry = _lbry2.default; +exports.Lbryapi = _lbryapi2.default; +exports.selectSearchState = _search3.selectState; + +/***/ }), +/* 16 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; +/* WEBPACK VAR INJECTION */(function(global) {/* + * Copyright 2016 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + + + + +(function(scope) { + if (scope['Proxy']) { + return; + } + let lastRevokeFn = null; + + /** + * @param {*} o + * @return {boolean} whether this is probably a (non-null) Object + */ + function isObject(o) { + return o ? (typeof o == 'object' || typeof o == 'function') : false; + } + + /** + * @constructor + * @param {!Object} target + * @param {{apply, construct, get, set}} handler + */ + scope.Proxy = function(target, handler) { + if (!isObject(target) || !isObject(handler)) { + throw new TypeError('Cannot create proxy with a non-object as target or handler'); + } + + // Construct revoke function, and set lastRevokeFn so that Proxy.revocable can steal it. + // The caller might get the wrong revoke function if a user replaces or wraps scope.Proxy + // to call itself, but that seems unlikely especially when using the polyfill. + let throwRevoked = function() {}; + lastRevokeFn = function() { + throwRevoked = function(trap) { + throw new TypeError(`Cannot perform '${trap}' on a proxy that has been revoked`); + }; + }; + + // Fail on unsupported traps: Chrome doesn't do this, but ensure that users of the polyfill + // are a bit more careful. Copy the internal parts of handler to prevent user changes. + let unsafeHandler = handler; + handler = {'get': null, 'set': null, 'apply': null, 'construct': null}; + for (let k in unsafeHandler) { + if (!(k in handler)) { + throw new TypeError(`Proxy polyfill does not support trap '${k}'`); + } + handler[k] = unsafeHandler[k]; + } + if (typeof unsafeHandler == 'function') { + // Allow handler to be a function (which has an 'apply' method). This matches what is + // probably a bug in native versions. It treats the apply call as a trap to be configured. + handler.apply = unsafeHandler.apply.bind(unsafeHandler); + } + + // Define proxy as this, or a Function (if either it's callable, or apply is set). + // TODO(samthor): Closure compiler doesn't know about 'construct', attempts to rename it. + let proxy = this; + let isMethod = false; + let targetIsFunction = typeof target == 'function'; + if (handler.apply || handler['construct'] || targetIsFunction) { + proxy = function Proxy() { + let usingNew = (this && this.constructor === proxy); + throwRevoked(usingNew ? 'construct' : 'apply'); + + if (usingNew && handler['construct']) { + return handler['construct'].call(this, target, arguments); + } else if (!usingNew && handler.apply) { + return handler.apply(target, this, arguments); + } else if (targetIsFunction) { + // since the target was a function, fallback to calling it directly. + if (usingNew) { + // inspired by answers to https://stackoverflow.com/q/1606797 + let all = Array.prototype.slice.call(arguments); + all.unshift(target); // pass class as first arg to constructor, although irrelevant + // nb. cast to convince Closure compiler that this is a constructor + let f = /** @type {!Function} */ (target.bind.apply(target, all)); + return new f(); + } + return target.apply(this, arguments); + } + throw new TypeError(usingNew ? 'not a constructor' : 'not a function'); + }; + isMethod = true; + } + + // Create default getters/setters. Create different code paths as handler.get/handler.set can't + // change after creation. + let getter = handler.get ? function(prop) { + throwRevoked('get'); + return handler.get(this, prop, proxy); + } : function(prop) { + throwRevoked('get'); + return this[prop]; + }; + let setter = handler.set ? function(prop, value) { + throwRevoked('set'); + let status = handler.set(this, prop, value, proxy); + if (!status) { + // TODO(samthor): If the calling code is in strict mode, throw TypeError. + // It's (sometimes) possible to work this out, if this code isn't strict- try to load the + // callee, and if it's available, that code is non-strict. However, this isn't exhaustive. + } + } : function(prop, value) { + throwRevoked('set'); + this[prop] = value; + }; + + // Clone direct properties (i.e., not part of a prototype). + let propertyNames = Object.getOwnPropertyNames(target); + let propertyMap = {}; + propertyNames.forEach(function(prop) { + if (isMethod && prop in proxy) { + return; // ignore properties already here, e.g. 'bind', 'prototype' etc + } + let real = Object.getOwnPropertyDescriptor(target, prop); + let desc = { + enumerable: !!real.enumerable, + get: getter.bind(target, prop), + set: setter.bind(target, prop), + }; + Object.defineProperty(proxy, prop, desc); + propertyMap[prop] = true; + }); + + // Set the prototype, or clone all prototype methods (always required if a getter is provided). + // TODO(samthor): We don't allow prototype methods to be set. It's (even more) awkward. + // An alternative here would be to _just_ clone methods to keep behavior consistent. + let prototypeOk = true; + if (Object.setPrototypeOf) { + Object.setPrototypeOf(proxy, Object.getPrototypeOf(target)); + } else if (proxy.__proto__) { + proxy.__proto__ = target.__proto__; + } else { + prototypeOk = false; + } + if (handler.get || !prototypeOk) { + for (let k in target) { + if (propertyMap[k]) { + continue; + } + Object.defineProperty(proxy, k, {get: getter.bind(target, k)}); + } + } + + // The Proxy polyfill cannot handle adding new properties. Seal the target and proxy. + Object.seal(target); + Object.seal(proxy); + + return proxy; // nb. if isMethod is true, proxy != this + }; + + scope.Proxy.revocable = function(target, handler) { + let p = new scope.Proxy(target, handler); + return {'proxy': p, 'revoke': lastRevokeFn}; + }; + + scope.Proxy['revocable'] = scope.Proxy.revocable; + scope['Proxy'] = scope.Proxy; +})(typeof module !== 'undefined' && module['exports'] ? global : window); + +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(17))) + +/***/ }), +/* 17 */ +/***/ (function(module, exports) { + +var g; + +// This works in non-strict mode +g = (function() { + return this; +})(); + +try { + // This works if eval is allowed (see CSP) + g = g || Function("return this")() || (1,eval)("this"); +} catch(e) { + // This works if the window reference is available + if(typeof window === "object") + g = window; +} + +// g can still be undefined, but nothing to do about it... +// We return undefined, instead of nothing here, so it's +// easier to handle this case. if(!global) { ...} + +module.exports = g; + + +/***/ }), +/* 18 */ /***/ (function(module, exports) { // shim for using process in browser @@ -792,18 +3403,18 @@ process.umask = function() { return 0; }; /***/ }), -/* 5 */ +/* 19 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -exports.decode = exports.parse = __webpack_require__(6); -exports.encode = exports.stringify = __webpack_require__(7); +exports.decode = exports.parse = __webpack_require__(20); +exports.encode = exports.stringify = __webpack_require__(21); /***/ }), -/* 6 */ +/* 20 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -894,7 +3505,7 @@ var isArray = Array.isArray || function (xs) { /***/ }), -/* 7 */ +/* 21 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -986,7 +3597,7 @@ var objectKeys = Object.keys || function (obj) { /***/ }), -/* 8 */ +/* 22 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -995,9 +3606,971 @@ var objectKeys = Object.keys || function (obj) { Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = reducer; +exports.doFetchCostInfoForUri = doFetchCostInfoForUri; -var _action_types = __webpack_require__(9); +var _action_types = __webpack_require__(0); + +var ACTIONS = _interopRequireWildcard(_action_types); + +var _lbryapi = __webpack_require__(8); + +var _lbryapi2 = _interopRequireDefault(_lbryapi); + +var _claims = __webpack_require__(3); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +// eslint-disable-next-line import/prefer-default-export +function doFetchCostInfoForUri(uri) { + return function (dispatch, getState) { + var state = getState(); + var claim = (0, _claims.selectClaimsByUri)(state)[uri]; + + if (!claim) return; + + function resolve(costInfo) { + dispatch({ + type: ACTIONS.FETCH_COST_INFO_COMPLETED, + data: { + uri: uri, + costInfo: costInfo + } + }); + } + + var fee = claim.value && claim.value.stream && claim.value.stream.metadata ? claim.value.stream.metadata.fee : undefined; + + if (fee === undefined) { + resolve({ cost: 0, includesData: true }); + } else if (fee.currency === 'LBC') { + resolve({ cost: fee.amount, includesData: true }); + } else { + _lbryapi2.default.getExchangeRates().then(function (_ref) { + var LBC_USD = _ref.LBC_USD; + + resolve({ cost: fee.amount / LBC_USD, includesData: true }); + }); + } + }; +} + +/***/ }), +/* 23 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.doFetchFileInfo = doFetchFileInfo; +exports.doFileList = doFileList; +exports.doFetchFileInfosAndPublishedClaims = doFetchFileInfosAndPublishedClaims; + +var _action_types = __webpack_require__(0); + +var ACTIONS = _interopRequireWildcard(_action_types); + +var _lbry = __webpack_require__(4); + +var _lbry2 = _interopRequireDefault(_lbry); + +var _claims = __webpack_require__(7); + +var _claims2 = __webpack_require__(3); + +var _file_info = __webpack_require__(12); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +function doFetchFileInfo(uri) { + return function (dispatch, getState) { + var state = getState(); + var claim = (0, _claims2.selectClaimsByUri)(state)[uri]; + var outpoint = claim ? claim.txid + ':' + claim.nout : null; + var alreadyFetching = !!(0, _file_info.selectUrisLoading)(state)[uri]; + + if (!alreadyFetching) { + dispatch({ + type: ACTIONS.FETCH_FILE_INFO_STARTED, + data: { + outpoint: outpoint + } + }); + + _lbry2.default.file_list({ outpoint: outpoint, full_status: true }).then(function (fileInfos) { + dispatch({ + type: ACTIONS.FETCH_FILE_INFO_COMPLETED, + data: { + outpoint: outpoint, + fileInfo: fileInfos && fileInfos.length ? fileInfos[0] : null + } + }); + }); + } + }; +} + +function doFileList() { + return function (dispatch, getState) { + var state = getState(); + var isFetching = (0, _file_info.selectIsFetchingFileList)(state); + + if (!isFetching) { + dispatch({ + type: ACTIONS.FILE_LIST_STARTED + }); + + _lbry2.default.file_list().then(function (fileInfos) { + dispatch({ + type: ACTIONS.FILE_LIST_SUCCEEDED, + data: { + fileInfos: fileInfos + } + }); + }); + } + }; +} + +function doFetchFileInfosAndPublishedClaims() { + return function (dispatch, getState) { + var state = getState(); + var isFetchingClaimListMine = (0, _claims2.selectIsFetchingClaimListMine)(state); + var isFetchingFileInfo = (0, _file_info.selectIsFetchingFileList)(state); + + if (!isFetchingClaimListMine) dispatch((0, _claims.doFetchClaimListMine)()); + if (!isFetchingFileInfo) dispatch(doFileList()); + }; +} + +/***/ }), +/* 24 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.getSearchSuggestions = exports.doUpdateSearchQuery = exports.doSearch = undefined; + +var _action_types = __webpack_require__(0); + +var ACTIONS = _interopRequireWildcard(_action_types); + +var _search = __webpack_require__(25); + +var SEARCH_TYPES = _interopRequireWildcard(_search); + +var _lbryURI = __webpack_require__(2); + +var _claims = __webpack_require__(7); + +var _search2 = __webpack_require__(13); + +var _batchActions = __webpack_require__(9); + +var _handleFetch = __webpack_require__(26); + +var _handleFetch2 = _interopRequireDefault(_handleFetch); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +var doSearch = exports.doSearch = function doSearch(rawQuery) { + return function (dispatch, getState) { + var state = getState(); + var query = rawQuery.replace(/^lbry:\/\//i, ''); + + if (!query) { + dispatch({ + type: ACTIONS.SEARCH_FAIL + }); + return; + } + + // If we have already searched for something, we don't need to do anything + var urisForQuery = (0, _search2.makeSelectSearchUris)(query)(state); + if (urisForQuery && !!urisForQuery.length) { + return; + } + + dispatch({ + type: ACTIONS.SEARCH_START + }); + + // If the user is on the file page with a pre-populated uri and they select + // the search option without typing anything, searchQuery will be empty + // We need to populate it so the input is filled on the search page + if (!state.search.searchQuery) { + dispatch({ + type: ACTIONS.UPDATE_SEARCH_QUERY, + data: { searchQuery: query } + }); + } + + fetch('https://lighthouse.lbry.io/search?s=' + query).then(_handleFetch2.default).then(function (data) { + var uris = []; + var actions = []; + + data.forEach(function (result) { + var uri = (0, _lbryURI.buildURI)({ + claimName: result.name, + claimId: result.claimId + }); + actions.push((0, _claims.doResolveUri)(uri)); + uris.push(uri); + }); + + actions.push({ + type: ACTIONS.SEARCH_SUCCESS, + data: { + query: query, + uris: uris + } + }); + dispatch(_batchActions.batchActions.apply(undefined, actions)); + }).catch(function () { + dispatch({ + type: ACTIONS.SEARCH_FAIL + }); + }); + }; +}; +var doUpdateSearchQuery = exports.doUpdateSearchQuery = function doUpdateSearchQuery(query, shouldSkipSuggestions) { + return function (dispatch) { + dispatch({ + type: ACTIONS.UPDATE_SEARCH_QUERY, + data: { query: query } + }); + + // Don't fetch new suggestions if the user just added a space + if (!query.endsWith(' ') || !shouldSkipSuggestions) { + dispatch(getSearchSuggestions(query)); + } + }; +}; + +var getSearchSuggestions = exports.getSearchSuggestions = function getSearchSuggestions(value) { + return function (dispatch) { + var query = value.trim(); + + var isPrefix = function isPrefix() { + return query === '@' || query === 'lbry:' || query === 'lbry:/' || query === 'lbry://'; + }; + + if (!query || isPrefix()) { + dispatch({ + type: ACTIONS.UPDATE_SEARCH_SUGGESTIONS, + data: { suggestions: [] } + }); + return; + } + + var suggestions = []; + try { + // If the user is about to manually add the claim id ignore it until they + // actually add one. This would hardly ever happen, but then the search + // suggestions won't change just from adding a '#' after a uri + var uriQuery = query; + if (uriQuery.endsWith('#')) { + uriQuery = uriQuery.slice(0, -1); + } + + var uri = (0, _lbryURI.normalizeURI)(uriQuery); + + var _parseURI = (0, _lbryURI.parseURI)(uri), + claimName = _parseURI.claimName, + isChannel = _parseURI.isChannel; + + suggestions.push({ + value: uri, + shorthand: isChannel ? claimName.slice(1) : claimName, + type: isChannel ? SEARCH_TYPES.CHANNEL : SEARCH_TYPES.FILE + }, { + value: claimName, + type: SEARCH_TYPES.SEARCH + }); + + // If it's a valid url, don't fetch any extra search results + return dispatch({ + type: ACTIONS.UPDATE_SEARCH_SUGGESTIONS, + data: { suggestions: suggestions } + }); + } catch (e) { + suggestions.push({ + value: query, + type: SEARCH_TYPES.SEARCH + }); + } + + // Populate the current search query suggestion before fetching results + dispatch({ + type: ACTIONS.UPDATE_SEARCH_SUGGESTIONS, + data: { suggestions: suggestions } + }); + + // strip out any basic stuff for more accurate search results + var searchValue = value.replace(/lbry:\/\//g, '').replace(/-/g, ' '); + if (searchValue.includes('#')) { + // This should probably be more robust, but I think it's fine for now + // Remove everything after # to get rid of the claim id + searchValue = searchValue.substring(0, searchValue.indexOf('#')); + } + + return fetch('https://lighthouse.lbry.io/autocomplete?s=' + searchValue).then(_handleFetch2.default).then(function (apiSuggestions) { + var formattedSuggestions = apiSuggestions.slice(0, 6).map(function (suggestion) { + // This will need to be more robust when the api starts returning lbry uris + var isChannel = suggestion.startsWith('@'); + var suggestionObj = { + value: isChannel ? 'lbry://' + suggestion : suggestion, + shorthand: isChannel ? suggestion.slice(1) : '', + type: isChannel ? 'channel' : 'search' + }; + + return suggestionObj; + }); + + suggestions = suggestions.concat(formattedSuggestions); + dispatch({ + type: ACTIONS.UPDATE_SEARCH_SUGGESTIONS, + data: { suggestions: suggestions } + }); + }).catch(function () { + // If the fetch fails, do nothing + // Basic search suggestions are already populated at this point + }); + }; +}; + +/***/ }), +/* 25 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +var FILE = exports.FILE = 'file'; +var CHANNEL = exports.CHANNEL = 'channel'; +var SEARCH = exports.SEARCH = 'search'; + +/***/ }), +/* 26 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = handleFetchResponse; +function handleFetchResponse(response) { + return response.status === 200 ? Promise.resolve(response.json()) : Promise.reject(new Error(response.statusText)); +} + +/***/ }), +/* 27 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.doUpdateBalance = doUpdateBalance; +exports.doBalanceSubscribe = doBalanceSubscribe; +exports.doFetchTransactions = doFetchTransactions; +exports.doFetchBlock = doFetchBlock; +exports.doGetNewAddress = doGetNewAddress; +exports.doCheckAddressIsMine = doCheckAddressIsMine; +exports.doSendDraftTransaction = doSendDraftTransaction; +exports.doSetDraftTransactionAmount = doSetDraftTransactionAmount; +exports.doSetDraftTransactionAddress = doSetDraftTransactionAddress; +exports.doSendSupport = doSendSupport; + +var _action_types = __webpack_require__(0); + +var ACTIONS = _interopRequireWildcard(_action_types); + +var _lbry = __webpack_require__(4); + +var _lbry2 = _interopRequireDefault(_lbry); + +var _notifications = __webpack_require__(6); + +var _wallet = __webpack_require__(14); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +function doUpdateBalance() { + return function (dispatch, getState) { + var _getState = getState(), + balanceInStore = _getState.wallet.balance; + + _lbry2.default.wallet_balance().then(function (balance) { + if (balanceInStore !== balance) { + return dispatch({ + type: ACTIONS.UPDATE_BALANCE, + data: { + balance: balance + } + }); + } + }); + }; +} + +function doBalanceSubscribe() { + return function (dispatch) { + dispatch(doUpdateBalance()); + setInterval(function () { + return dispatch(doUpdateBalance()); + }, 5000); + }; +} + +function doFetchTransactions() { + return function (dispatch) { + dispatch({ + type: ACTIONS.FETCH_TRANSACTIONS_STARTED + }); + + _lbry2.default.transaction_list().then(function (results) { + dispatch({ + type: ACTIONS.FETCH_TRANSACTIONS_COMPLETED, + data: { + transactions: results + } + }); + }); + }; +} + +function doFetchBlock(height) { + return function (dispatch) { + _lbry2.default.block_show({ height: height }).then(function (block) { + dispatch({ + type: ACTIONS.FETCH_BLOCK_SUCCESS, + data: { block: block } + }); + }); + }; +} + +function doGetNewAddress() { + return function (dispatch) { + dispatch({ + type: ACTIONS.GET_NEW_ADDRESS_STARTED + }); + + // Removed localStorage use, since address is expected to be stored in redux store + _lbry2.default.wallet_new_address().then(function (address) { + dispatch({ + type: ACTIONS.GET_NEW_ADDRESS_COMPLETED, + data: { address: address } + }); + }); + }; +} + +function doCheckAddressIsMine(address) { + return function (dispatch) { + dispatch({ + type: ACTIONS.CHECK_ADDRESS_IS_MINE_STARTED + }); + + _lbry2.default.wallet_is_address_mine({ address: address }).then(function (isMine) { + if (!isMine) dispatch(doGetNewAddress()); + + dispatch({ + type: ACTIONS.CHECK_ADDRESS_IS_MINE_COMPLETED + }); + }); + }; +} + +function doSendDraftTransaction() { + return function (dispatch, getState) { + var state = getState(); + var draftTx = (0, _wallet.selectDraftTransaction)(state); + var balance = (0, _wallet.selectBalance)(state); + var amount = (0, _wallet.selectDraftTransactionAmount)(state); + + if (balance - amount <= 0) { + dispatch((0, _notifications.doNotify)({ + title: 'Insufficient credits', + message: 'Insufficient credits', + type: 'error', + displayType: ['modal', 'toast'] + })); + return; + } + + dispatch({ + type: ACTIONS.SEND_TRANSACTION_STARTED + }); + + var successCallback = function successCallback(results) { + if (results === true) { + dispatch({ + type: ACTIONS.SEND_TRANSACTION_COMPLETED + }); + dispatch((0, _notifications.doNotify)({ + title: 'Credits sent', + message: 'You sent ' + amount + ' LBC', + type: 'error', + displayType: ['snackbar', 'toast'], + linkText: 'History', + linkTarget: '/wallet' + })); + } else { + dispatch({ + type: ACTIONS.SEND_TRANSACTION_FAILED, + data: { error: results } + }); + dispatch((0, _notifications.doNotify)({ + title: 'Transaction failed', + message: 'Transaction failed', + type: 'error', + displayType: ['modal', 'toast'] + })); + } + }; + + var errorCallback = function errorCallback(error) { + dispatch({ + type: ACTIONS.SEND_TRANSACTION_FAILED, + data: { error: error.message } + }); + dispatch((0, _notifications.doNotify)({ + title: 'Transaction failed', + message: 'Transaction failed', + type: 'error', + displayType: ['modal', 'toast'] + })); + }; + + _lbry2.default.wallet_send({ + amount: draftTx.amount, + address: draftTx.address + }).then(successCallback, errorCallback); + }; +} + +function doSetDraftTransactionAmount(amount) { + return { + type: ACTIONS.SET_DRAFT_TRANSACTION_AMOUNT, + data: { amount: amount } + }; +} + +function doSetDraftTransactionAddress(address) { + return { + type: ACTIONS.SET_DRAFT_TRANSACTION_ADDRESS, + data: { address: address } + }; +} + +function doSendSupport(amount, claimId, uri, successCallback, errorCallback) { + return function (dispatch, getState) { + var state = getState(); + var balance = (0, _wallet.selectBalance)(state); + + if (balance - amount <= 0) { + dispatch((0, _notifications.doNotify)({ + title: 'Insufficient credits', + message: 'Insufficient credits', + type: 'error', + displayType: ['modal', 'toast'] + })); + return; + } + + dispatch({ + type: ACTIONS.SUPPORT_TRANSACTION_STARTED + }); + + _lbry2.default.wallet_send({ + claim_id: claimId, + amount: amount + }).then(successCallback, errorCallback); + }; +} + +/***/ }), +/* 28 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.formatCredits = formatCredits; +exports.formatFullPrice = formatFullPrice; +function formatCredits(amount, precision) { + return amount.toFixed(precision || 1).replace(/\.?0+$/, ''); +} + +function formatFullPrice(amount) { + var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + + var formated = ''; + + var quantity = amount.toString().split('.'); + var fraction = quantity[1]; + + if (fraction) { + var decimals = fraction.split(''); + var first = decimals.filter(function (number) { + return number !== '0'; + })[0]; + var index = decimals.indexOf(first); + + // Set format fraction + formated = '.' + fraction.substring(0, index + precision); + } + + return parseFloat(quantity[0] + formated); +} + +/***/ }), +/* 29 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); + +exports.claimsReducer = claimsReducer; + +var _action_types = __webpack_require__(0); + +var ACTIONS = _interopRequireWildcard(_action_types); + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +var reducers = {}; + +var defaultState = { + rewardedContentClaimIds: [], + channelClaimCounts: {} +}; + +reducers[ACTIONS.RESOLVE_URIS_COMPLETED] = function (state, action) { + var resolveInfo = action.data.resolveInfo; + + var byUri = Object.assign({}, state.claimsByUri); + var byId = Object.assign({}, state.byId); + var channelClaimCounts = Object.assign({}, state.channelClaimCounts); + + Object.entries(resolveInfo).forEach(function (_ref) { + var _ref2 = _slicedToArray(_ref, 2), + uri = _ref2[0], + _ref2$ = _ref2[1], + certificate = _ref2$.certificate, + claimsInChannel = _ref2$.claimsInChannel; + + if (certificate && !Number.isNaN(claimsInChannel)) { + channelClaimCounts[uri] = claimsInChannel; + } + }); + + Object.entries(resolveInfo).forEach(function (_ref3) { + var _ref4 = _slicedToArray(_ref3, 2), + uri = _ref4[0], + _ref4$ = _ref4[1], + certificate = _ref4$.certificate, + claim = _ref4$.claim; + + if (claim) { + byId[claim.claim_id] = claim; + byUri[uri] = claim.claim_id; + } else if (claim === undefined && certificate !== undefined) { + byId[certificate.claim_id] = certificate; + // Don't point URI at the channel certificate unless it actually is + // a channel URI. This is brittle. + if (!uri.split(certificate.name)[1].match(/\//)) { + byUri[uri] = certificate.claim_id; + } else { + byUri[uri] = null; + } + } else { + byUri[uri] = null; + } + }); + + return Object.assign({}, state, { + byId: byId, + claimsByUri: byUri, + channelClaimCounts: channelClaimCounts, + resolvingUris: (state.resolvingUris || []).filter(function (uri) { + return !resolveInfo[uri]; + }) + }); +}; + +reducers[ACTIONS.FETCH_CLAIM_LIST_MINE_STARTED] = function (state) { + return Object.assign({}, state, { + isFetchingClaimListMine: true + }); +}; + +reducers[ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED] = function (state, action) { + var claims = action.data.claims; + + var byId = Object.assign({}, state.byId); + var pendingById = Object.assign({}, state.pendingById); + + claims.filter(function (claim) { + return claim.category && claim.category.match(/claim/); + }).forEach(function (claim) { + byId[claim.claim_id] = claim; + + var pending = Object.values(pendingById).find(function (pendingClaim) { + return pendingClaim.name === claim.name && pendingClaim.channel_name === claim.channel_name; + }); + + if (pending) { + delete pendingById[pending.claim_id]; + } + }); + + // Remove old timed out pending publishes + Object.values(pendingById).filter(function (pendingClaim) { + return Date.now() - pendingClaim.time >= 20 * 60 * 1000; + }).forEach(function (pendingClaim) { + delete pendingById[pendingClaim.claim_id]; + }); + + return Object.assign({}, state, { + isFetchingClaimListMine: false, + myClaims: claims, + byId: byId, + pendingById: pendingById + }); +}; + +reducers[ACTIONS.FETCH_CHANNEL_LIST_MINE_STARTED] = function (state) { + return Object.assign({}, state, { fetchingMyChannels: true }); +}; + +reducers[ACTIONS.FETCH_CHANNEL_LIST_MINE_COMPLETED] = function (state, action) { + var claims = action.data.claims; + + var myChannelClaims = new Set(state.myChannelClaims); + var byId = Object.assign({}, state.byId); + + claims.forEach(function (claim) { + myChannelClaims.add(claim.claim_id); + byId[claims.claim_id] = claim; + }); + + return Object.assign({}, state, { + byId: byId, + fetchingMyChannels: false, + myChannelClaims: myChannelClaims + }); +}; + +reducers[ACTIONS.FETCH_CHANNEL_CLAIMS_STARTED] = function (state, action) { + var _action$data = action.data, + uri = _action$data.uri, + page = _action$data.page; + + var fetchingChannelClaims = Object.assign({}, state.fetchingChannelClaims); + + fetchingChannelClaims[uri] = page; + + return Object.assign({}, state, { + fetchingChannelClaims: fetchingChannelClaims + }); +}; + +reducers[ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED] = function (state, action) { + var _action$data2 = action.data, + uri = _action$data2.uri, + claims = _action$data2.claims, + page = _action$data2.page; + + + var claimsByChannel = Object.assign({}, state.claimsByChannel); + var byChannel = Object.assign({}, claimsByChannel[uri]); + var allClaimIds = new Set(byChannel.all); + var currentPageClaimIds = []; + var byId = Object.assign({}, state.byId); + var fetchingChannelClaims = Object.assign({}, state.fetchingChannelClaims); + + if (claims !== undefined) { + claims.forEach(function (claim) { + allClaimIds.add(claim.claim_id); + currentPageClaimIds.push(claim.claim_id); + byId[claim.claim_id] = claim; + }); + } + + byChannel.all = allClaimIds; + byChannel[page] = currentPageClaimIds; + claimsByChannel[uri] = byChannel; + delete fetchingChannelClaims[uri]; + + return Object.assign({}, state, { + claimsByChannel: claimsByChannel, + byId: byId, + fetchingChannelClaims: fetchingChannelClaims + }); +}; + +reducers[ACTIONS.ABANDON_CLAIM_STARTED] = function (state, action) { + var claimId = action.data.claimId; + + var abandoningById = Object.assign({}, state.abandoningById); + + abandoningById[claimId] = true; + + return Object.assign({}, state, { + abandoningById: abandoningById + }); +}; + +reducers[ACTIONS.ABANDON_CLAIM_SUCCEEDED] = function (state, action) { + var claimId = action.data.claimId; + + var byId = Object.assign({}, state.byId); + var claimsByUri = Object.assign({}, state.claimsByUri); + + Object.keys(claimsByUri).forEach(function (uri) { + if (claimsByUri[uri] === claimId) { + delete claimsByUri[uri]; + } + }); + + delete byId[claimId]; + + return Object.assign({}, state, { + byId: byId, + claimsByUri: claimsByUri + }); +}; + +reducers[ACTIONS.CREATE_CHANNEL_COMPLETED] = function (state, action) { + var channelClaim = action.data.channelClaim; + + var byId = Object.assign({}, state.byId); + var myChannelClaims = new Set(state.myChannelClaims); + + byId[channelClaim.claim_id] = channelClaim; + myChannelClaims.add(channelClaim.claim_id); + + return Object.assign({}, state, { + byId: byId, + myChannelClaims: myChannelClaims + }); +}; + +reducers[ACTIONS.FETCH_FEATURED_CONTENT_STARTED] = function (state) { + return Object.assign({}, state, { + fetchingFeaturedContent: true + }); +}; + +reducers[ACTIONS.FETCH_FEATURED_CONTENT_COMPLETED] = function (state, action) { + var _action$data3 = action.data, + uris = _action$data3.uris, + success = _action$data3.success; + + + return Object.assign({}, state, { + fetchingFeaturedContent: false, + fetchingFeaturedContentFailed: !success, + featuredUris: uris + }); +}; + +reducers[ACTIONS.FETCH_REWARD_CONTENT_COMPLETED] = function (state, action) { + var claimIds = action.data.claimIds; + + + return Object.assign({}, state, { + rewardedContentClaimIds: claimIds + }); +}; + +reducers[ACTIONS.RESOLVE_URIS_STARTED] = function (state, action) { + var uris = action.data.uris; + + + var oldResolving = state.resolvingUris || []; + var newResolving = Object.assign([], oldResolving); + + uris.forEach(function (uri) { + if (!newResolving.includes(uri)) { + newResolving.push(uri); + } + }); + + return Object.assign({}, state, { + resolvingUris: newResolving + }); +}; + +reducers[ACTIONS.FETCH_CHANNEL_CLAIM_COUNT_COMPLETED] = function (state, action) { + var channelClaimCounts = Object.assign({}, state.channelClaimCounts); + var _action$data4 = action.data, + uri = _action$data4.uri, + totalClaims = _action$data4.totalClaims; + + + channelClaimCounts[uri] = totalClaims; + + return Object.assign({}, state, { + channelClaimCounts: channelClaimCounts + }); +}; + +function claimsReducer() { + var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState; + var action = arguments[1]; + + var handler = reducers[action.type]; + if (handler) return handler(state, action); + return state; +} + +/***/ }), +/* 30 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.costInfoReducer = costInfoReducer; + +var _action_types = __webpack_require__(0); var ACTIONS = _interopRequireWildcard(_action_types); @@ -1034,7 +4607,7 @@ reducers[ACTIONS.FETCH_COST_INFO_COMPLETED] = function (state, action) { }); }; -function reducer() { +function costInfoReducer() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState; var action = arguments[1]; @@ -1044,7 +4617,7 @@ function reducer() { } /***/ }), -/* 9 */ +/* 31 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -1053,170 +4626,639 @@ function reducer() { Object.defineProperty(exports, "__esModule", { value: true }); -var OPEN_MODAL = exports.OPEN_MODAL = 'OPEN_MODAL'; -var CLOSE_MODAL = exports.CLOSE_MODAL = 'CLOSE_MODAL'; -var SHOW_SNACKBAR = exports.SHOW_SNACKBAR = 'SHOW_SNACKBAR'; -var REMOVE_SNACKBAR_SNACK = exports.REMOVE_SNACKBAR_SNACK = 'REMOVE_SNACKBAR_SNACK'; -var WINDOW_FOCUSED = exports.WINDOW_FOCUSED = 'WINDOW_FOCUSED'; -var DAEMON_READY = exports.DAEMON_READY = 'DAEMON_READY'; -var DAEMON_VERSION_MATCH = exports.DAEMON_VERSION_MATCH = 'DAEMON_VERSION_MATCH'; -var DAEMON_VERSION_MISMATCH = exports.DAEMON_VERSION_MISMATCH = 'DAEMON_VERSION_MISMATCH'; -var VOLUME_CHANGED = exports.VOLUME_CHANGED = 'VOLUME_CHANGED'; +exports.fileInfoReducer = fileInfoReducer; -// Navigation -var CHANGE_AFTER_AUTH_PATH = exports.CHANGE_AFTER_AUTH_PATH = 'CHANGE_AFTER_AUTH_PATH'; -var WINDOW_SCROLLED = exports.WINDOW_SCROLLED = 'WINDOW_SCROLLED'; -var HISTORY_NAVIGATE = exports.HISTORY_NAVIGATE = 'HISTORY_NAVIGATE'; +var _action_types = __webpack_require__(0); -// Upgrades -var UPGRADE_CANCELLED = exports.UPGRADE_CANCELLED = 'UPGRADE_CANCELLED'; -var DOWNLOAD_UPGRADE = exports.DOWNLOAD_UPGRADE = 'DOWNLOAD_UPGRADE'; -var UPGRADE_DOWNLOAD_STARTED = exports.UPGRADE_DOWNLOAD_STARTED = 'UPGRADE_DOWNLOAD_STARTED'; -var UPGRADE_DOWNLOAD_COMPLETED = exports.UPGRADE_DOWNLOAD_COMPLETED = 'UPGRADE_DOWNLOAD_COMPLETED'; -var UPGRADE_DOWNLOAD_PROGRESSED = exports.UPGRADE_DOWNLOAD_PROGRESSED = 'UPGRADE_DOWNLOAD_PROGRESSED'; -var CHECK_UPGRADE_AVAILABLE = exports.CHECK_UPGRADE_AVAILABLE = 'CHECK_UPGRADE_AVAILABLE'; -var CHECK_UPGRADE_START = exports.CHECK_UPGRADE_START = 'CHECK_UPGRADE_START'; -var CHECK_UPGRADE_SUCCESS = exports.CHECK_UPGRADE_SUCCESS = 'CHECK_UPGRADE_SUCCESS'; -var CHECK_UPGRADE_FAIL = exports.CHECK_UPGRADE_FAIL = 'CHECK_UPGRADE_FAIL'; -var CHECK_UPGRADE_SUBSCRIBE = exports.CHECK_UPGRADE_SUBSCRIBE = 'CHECK_UPGRADE_SUBSCRIBE'; -var UPDATE_VERSION = exports.UPDATE_VERSION = 'UPDATE_VERSION'; -var UPDATE_REMOTE_VERSION = exports.UPDATE_REMOTE_VERSION = 'UPDATE_REMOTE_VERSION'; -var SKIP_UPGRADE = exports.SKIP_UPGRADE = 'SKIP_UPGRADE'; -var START_UPGRADE = exports.START_UPGRADE = 'START_UPGRADE'; +var ACTIONS = _interopRequireWildcard(_action_types); -// Wallet -var GET_NEW_ADDRESS_STARTED = exports.GET_NEW_ADDRESS_STARTED = 'GET_NEW_ADDRESS_STARTED'; -var GET_NEW_ADDRESS_COMPLETED = exports.GET_NEW_ADDRESS_COMPLETED = 'GET_NEW_ADDRESS_COMPLETED'; -var FETCH_TRANSACTIONS_STARTED = exports.FETCH_TRANSACTIONS_STARTED = 'FETCH_TRANSACTIONS_STARTED'; -var FETCH_TRANSACTIONS_COMPLETED = exports.FETCH_TRANSACTIONS_COMPLETED = 'FETCH_TRANSACTIONS_COMPLETED'; -var UPDATE_BALANCE = exports.UPDATE_BALANCE = 'UPDATE_BALANCE'; -var CHECK_ADDRESS_IS_MINE_STARTED = exports.CHECK_ADDRESS_IS_MINE_STARTED = 'CHECK_ADDRESS_IS_MINE_STARTED'; -var CHECK_ADDRESS_IS_MINE_COMPLETED = exports.CHECK_ADDRESS_IS_MINE_COMPLETED = 'CHECK_ADDRESS_IS_MINE_COMPLETED'; -var SET_DRAFT_TRANSACTION_AMOUNT = exports.SET_DRAFT_TRANSACTION_AMOUNT = 'SET_DRAFT_TRANSACTION_AMOUNT'; -var SET_DRAFT_TRANSACTION_ADDRESS = exports.SET_DRAFT_TRANSACTION_ADDRESS = 'SET_DRAFT_TRANSACTION_ADDRESS'; -var SEND_TRANSACTION_STARTED = exports.SEND_TRANSACTION_STARTED = 'SEND_TRANSACTION_STARTED'; -var SEND_TRANSACTION_COMPLETED = exports.SEND_TRANSACTION_COMPLETED = 'SEND_TRANSACTION_COMPLETED'; -var SEND_TRANSACTION_FAILED = exports.SEND_TRANSACTION_FAILED = 'SEND_TRANSACTION_FAILED'; -var FETCH_BLOCK_SUCCESS = exports.FETCH_BLOCK_SUCCESS = 'FETCH_BLOCK_SUCCESS'; -var SUPPORT_TRANSACTION_STARTED = exports.SUPPORT_TRANSACTION_STARTED = 'SUPPORT_TRANSACTION_STARTED'; -var SUPPORT_TRANSACTION_COMPLETED = exports.SUPPORT_TRANSACTION_COMPLETED = 'SUPPORT_TRANSACTION_COMPLETED'; -var SUPPORT_TRANSACTION_FAILED = exports.SUPPORT_TRANSACTION_FAILED = 'SUPPORT_TRANSACTION_FAILED'; +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } -// Claims -var FETCH_FEATURED_CONTENT_STARTED = exports.FETCH_FEATURED_CONTENT_STARTED = 'FETCH_FEATURED_CONTENT_STARTED'; -var FETCH_FEATURED_CONTENT_COMPLETED = exports.FETCH_FEATURED_CONTENT_COMPLETED = 'FETCH_FEATURED_CONTENT_COMPLETED'; -var RESOLVE_URIS_STARTED = exports.RESOLVE_URIS_STARTED = 'RESOLVE_URIS_STARTED'; -var RESOLVE_URIS_COMPLETED = exports.RESOLVE_URIS_COMPLETED = 'RESOLVE_URIS_COMPLETED'; -var FETCH_CHANNEL_CLAIMS_STARTED = exports.FETCH_CHANNEL_CLAIMS_STARTED = 'FETCH_CHANNEL_CLAIMS_STARTED'; -var FETCH_CHANNEL_CLAIMS_COMPLETED = exports.FETCH_CHANNEL_CLAIMS_COMPLETED = 'FETCH_CHANNEL_CLAIMS_COMPLETED'; -var FETCH_CHANNEL_CLAIM_COUNT_STARTED = exports.FETCH_CHANNEL_CLAIM_COUNT_STARTED = 'FETCH_CHANNEL_CLAIM_COUNT_STARTED'; -var FETCH_CHANNEL_CLAIM_COUNT_COMPLETED = exports.FETCH_CHANNEL_CLAIM_COUNT_COMPLETED = 'FETCH_CHANNEL_CLAIM_COUNT_COMPLETED'; -var FETCH_CLAIM_LIST_MINE_STARTED = exports.FETCH_CLAIM_LIST_MINE_STARTED = 'FETCH_CLAIM_LIST_MINE_STARTED'; -var FETCH_CLAIM_LIST_MINE_COMPLETED = exports.FETCH_CLAIM_LIST_MINE_COMPLETED = 'FETCH_CLAIM_LIST_MINE_COMPLETED'; -var ABANDON_CLAIM_STARTED = exports.ABANDON_CLAIM_STARTED = 'ABANDON_CLAIM_STARTED'; -var ABANDON_CLAIM_SUCCEEDED = exports.ABANDON_CLAIM_SUCCEEDED = 'ABANDON_CLAIM_SUCCEEDED'; -var FETCH_CHANNEL_LIST_MINE_STARTED = exports.FETCH_CHANNEL_LIST_MINE_STARTED = 'FETCH_CHANNEL_LIST_MINE_STARTED'; -var FETCH_CHANNEL_LIST_MINE_COMPLETED = exports.FETCH_CHANNEL_LIST_MINE_COMPLETED = 'FETCH_CHANNEL_LIST_MINE_COMPLETED'; -var CREATE_CHANNEL_STARTED = exports.CREATE_CHANNEL_STARTED = 'CREATE_CHANNEL_STARTED'; -var CREATE_CHANNEL_COMPLETED = exports.CREATE_CHANNEL_COMPLETED = 'CREATE_CHANNEL_COMPLETED'; -var PUBLISH_STARTED = exports.PUBLISH_STARTED = 'PUBLISH_STARTED'; -var PUBLISH_COMPLETED = exports.PUBLISH_COMPLETED = 'PUBLISH_COMPLETED'; -var PUBLISH_FAILED = exports.PUBLISH_FAILED = 'PUBLISH_FAILED'; -var SET_PLAYING_URI = exports.SET_PLAYING_URI = 'PLAY_URI'; +var reducers = {}; +var defaultState = {}; -// Files -var FILE_LIST_STARTED = exports.FILE_LIST_STARTED = 'FILE_LIST_STARTED'; -var FILE_LIST_SUCCEEDED = exports.FILE_LIST_SUCCEEDED = 'FILE_LIST_SUCCEEDED'; -var FETCH_FILE_INFO_STARTED = exports.FETCH_FILE_INFO_STARTED = 'FETCH_FILE_INFO_STARTED'; -var FETCH_FILE_INFO_COMPLETED = exports.FETCH_FILE_INFO_COMPLETED = 'FETCH_FILE_INFO_COMPLETED'; -var FETCH_COST_INFO_STARTED = exports.FETCH_COST_INFO_STARTED = 'FETCH_COST_INFO_STARTED'; -var FETCH_COST_INFO_COMPLETED = exports.FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED'; -var LOADING_VIDEO_STARTED = exports.LOADING_VIDEO_STARTED = 'LOADING_VIDEO_STARTED'; -var LOADING_VIDEO_COMPLETED = exports.LOADING_VIDEO_COMPLETED = 'LOADING_VIDEO_COMPLETED'; -var LOADING_VIDEO_FAILED = exports.LOADING_VIDEO_FAILED = 'LOADING_VIDEO_FAILED'; -var DOWNLOADING_STARTED = exports.DOWNLOADING_STARTED = 'DOWNLOADING_STARTED'; -var DOWNLOADING_PROGRESSED = exports.DOWNLOADING_PROGRESSED = 'DOWNLOADING_PROGRESSED'; -var DOWNLOADING_COMPLETED = exports.DOWNLOADING_COMPLETED = 'DOWNLOADING_COMPLETED'; -var PLAY_VIDEO_STARTED = exports.PLAY_VIDEO_STARTED = 'PLAY_VIDEO_STARTED'; -var FETCH_AVAILABILITY_STARTED = exports.FETCH_AVAILABILITY_STARTED = 'FETCH_AVAILABILITY_STARTED'; -var FETCH_AVAILABILITY_COMPLETED = exports.FETCH_AVAILABILITY_COMPLETED = 'FETCH_AVAILABILITY_COMPLETED'; -var FILE_DELETE = exports.FILE_DELETE = 'FILE_DELETE'; +reducers[ACTIONS.FILE_LIST_STARTED] = function (state) { + return Object.assign({}, state, { + isFetchingFileList: true + }); +}; -// Search -var SEARCH_STARTED = exports.SEARCH_STARTED = 'SEARCH_STARTED'; -var SEARCH_COMPLETED = exports.SEARCH_COMPLETED = 'SEARCH_COMPLETED'; -var SEARCH_CANCELLED = exports.SEARCH_CANCELLED = 'SEARCH_CANCELLED'; +reducers[ACTIONS.FILE_LIST_SUCCEEDED] = function (state, action) { + var fileInfos = action.data.fileInfos; -// Settings -var DAEMON_SETTINGS_RECEIVED = exports.DAEMON_SETTINGS_RECEIVED = 'DAEMON_SETTINGS_RECEIVED'; -var CLIENT_SETTING_CHANGED = exports.CLIENT_SETTING_CHANGED = 'CLIENT_SETTING_CHANGED'; + var newByOutpoint = Object.assign({}, state.byOutpoint); + var pendingByOutpoint = Object.assign({}, state.pendingByOutpoint); -// User -var AUTHENTICATION_STARTED = exports.AUTHENTICATION_STARTED = 'AUTHENTICATION_STARTED'; -var AUTHENTICATION_SUCCESS = exports.AUTHENTICATION_SUCCESS = 'AUTHENTICATION_SUCCESS'; -var AUTHENTICATION_FAILURE = exports.AUTHENTICATION_FAILURE = 'AUTHENTICATION_FAILURE'; -var USER_EMAIL_DECLINE = exports.USER_EMAIL_DECLINE = 'USER_EMAIL_DECLINE'; -var USER_EMAIL_NEW_STARTED = exports.USER_EMAIL_NEW_STARTED = 'USER_EMAIL_NEW_STARTED'; -var USER_EMAIL_NEW_SUCCESS = exports.USER_EMAIL_NEW_SUCCESS = 'USER_EMAIL_NEW_SUCCESS'; -var USER_EMAIL_NEW_EXISTS = exports.USER_EMAIL_NEW_EXISTS = 'USER_EMAIL_NEW_EXISTS'; -var USER_EMAIL_NEW_FAILURE = exports.USER_EMAIL_NEW_FAILURE = 'USER_EMAIL_NEW_FAILURE'; -var USER_EMAIL_VERIFY_STARTED = exports.USER_EMAIL_VERIFY_STARTED = 'USER_EMAIL_VERIFY_STARTED'; -var USER_EMAIL_VERIFY_SUCCESS = exports.USER_EMAIL_VERIFY_SUCCESS = 'USER_EMAIL_VERIFY_SUCCESS'; -var USER_EMAIL_VERIFY_FAILURE = exports.USER_EMAIL_VERIFY_FAILURE = 'USER_EMAIL_VERIFY_FAILURE'; -var USER_IDENTITY_VERIFY_STARTED = exports.USER_IDENTITY_VERIFY_STARTED = 'USER_IDENTITY_VERIFY_STARTED'; -var USER_IDENTITY_VERIFY_SUCCESS = exports.USER_IDENTITY_VERIFY_SUCCESS = 'USER_IDENTITY_VERIFY_SUCCESS'; -var USER_IDENTITY_VERIFY_FAILURE = exports.USER_IDENTITY_VERIFY_FAILURE = 'USER_IDENTITY_VERIFY_FAILURE'; -var USER_FETCH_STARTED = exports.USER_FETCH_STARTED = 'USER_FETCH_STARTED'; -var USER_FETCH_SUCCESS = exports.USER_FETCH_SUCCESS = 'USER_FETCH_SUCCESS'; -var USER_FETCH_FAILURE = exports.USER_FETCH_FAILURE = 'USER_FETCH_FAILURE'; -var USER_INVITE_STATUS_FETCH_STARTED = exports.USER_INVITE_STATUS_FETCH_STARTED = 'USER_INVITE_STATUS_FETCH_STARTED'; -var USER_INVITE_STATUS_FETCH_SUCCESS = exports.USER_INVITE_STATUS_FETCH_SUCCESS = 'USER_INVITE_STATUS_FETCH_SUCCESS'; -var USER_INVITE_STATUS_FETCH_FAILURE = exports.USER_INVITE_STATUS_FETCH_FAILURE = 'USER_INVITE_STATUS_FETCH_FAILURE'; -var USER_INVITE_NEW_STARTED = exports.USER_INVITE_NEW_STARTED = 'USER_INVITE_NEW_STARTED'; -var USER_INVITE_NEW_SUCCESS = exports.USER_INVITE_NEW_SUCCESS = 'USER_INVITE_NEW_SUCCESS'; -var USER_INVITE_NEW_FAILURE = exports.USER_INVITE_NEW_FAILURE = 'USER_INVITE_NEW_FAILURE'; -var FETCH_ACCESS_TOKEN_SUCCESS = exports.FETCH_ACCESS_TOKEN_SUCCESS = 'FETCH_ACCESS_TOKEN_SUCCESS'; + fileInfos.forEach(function (fileInfo) { + var outpoint = fileInfo.outpoint; -// Rewards -var FETCH_REWARDS_STARTED = exports.FETCH_REWARDS_STARTED = 'FETCH_REWARDS_STARTED'; -var FETCH_REWARDS_COMPLETED = exports.FETCH_REWARDS_COMPLETED = 'FETCH_REWARDS_COMPLETED'; -var CLAIM_REWARD_STARTED = exports.CLAIM_REWARD_STARTED = 'CLAIM_REWARD_STARTED'; -var CLAIM_REWARD_SUCCESS = exports.CLAIM_REWARD_SUCCESS = 'CLAIM_REWARD_SUCCESS'; -var CLAIM_REWARD_FAILURE = exports.CLAIM_REWARD_FAILURE = 'CLAIM_REWARD_FAILURE'; -var CLAIM_REWARD_CLEAR_ERROR = exports.CLAIM_REWARD_CLEAR_ERROR = 'CLAIM_REWARD_CLEAR_ERROR'; -var FETCH_REWARD_CONTENT_COMPLETED = exports.FETCH_REWARD_CONTENT_COMPLETED = 'FETCH_REWARD_CONTENT_COMPLETED'; -// Language -var DOWNLOAD_LANGUAGE_SUCCEEDED = exports.DOWNLOAD_LANGUAGE_SUCCEEDED = 'DOWNLOAD_LANGUAGE_SUCCEEDED'; -var DOWNLOAD_LANGUAGE_FAILED = exports.DOWNLOAD_LANGUAGE_FAILED = 'DOWNLOAD_LANGUAGE_FAILED'; + if (outpoint) newByOutpoint[fileInfo.outpoint] = fileInfo; + }); -// ShapeShift -var GET_SUPPORTED_COINS_START = exports.GET_SUPPORTED_COINS_START = 'GET_SUPPORTED_COINS_START'; -var GET_SUPPORTED_COINS_SUCCESS = exports.GET_SUPPORTED_COINS_SUCCESS = 'GET_SUPPORTED_COINS_SUCCESS'; -var GET_SUPPORTED_COINS_FAIL = exports.GET_SUPPORTED_COINS_FAIL = 'GET_SUPPORTED_COINS_FAIL'; -var GET_COIN_STATS_START = exports.GET_COIN_STATS_START = 'GET_COIN_STATS_START'; -var GET_COIN_STATS_SUCCESS = exports.GET_COIN_STATS_SUCCESS = 'GET_COIN_STATS_SUCCESS'; -var GET_COIN_STATS_FAIL = exports.GET_COIN_STATS_FAIL = 'GET_COIN_STATS_FAIL'; -var PREPARE_SHAPE_SHIFT_START = exports.PREPARE_SHAPE_SHIFT_START = 'PREPARE_SHAPE_SHIFT_START'; -var PREPARE_SHAPE_SHIFT_SUCCESS = exports.PREPARE_SHAPE_SHIFT_SUCCESS = 'PREPARE_SHAPE_SHIFT_SUCCESS'; -var PREPARE_SHAPE_SHIFT_FAIL = exports.PREPARE_SHAPE_SHIFT_FAIL = 'PREPARE_SHAPE_SHIFT_FAIL'; -var GET_ACTIVE_SHIFT_START = exports.GET_ACTIVE_SHIFT_START = 'GET_ACTIVE_SHIFT_START'; -var GET_ACTIVE_SHIFT_SUCCESS = exports.GET_ACTIVE_SHIFT_SUCCESS = 'GET_ACTIVE_SHIFT_SUCCESS'; -var GET_ACTIVE_SHIFT_FAIL = exports.GET_ACTIVE_SHIFT_FAIL = 'GET_ACTIVE_SHIFT_FAIL'; -var CLEAR_SHAPE_SHIFT = exports.CLEAR_SHAPE_SHIFT = 'CLEAR_SHAPE_SHIFT'; + return Object.assign({}, state, { + isFetchingFileList: false, + byOutpoint: newByOutpoint, + pendingByOutpoint: pendingByOutpoint + }); +}; -// Subscriptions -var CHANNEL_SUBSCRIBE = exports.CHANNEL_SUBSCRIBE = 'CHANNEL_SUBSCRIBE'; -var CHANNEL_UNSUBSCRIBE = exports.CHANNEL_UNSUBSCRIBE = 'CHANNEL_UNSUBSCRIBE'; -var HAS_FETCHED_SUBSCRIPTIONS = exports.HAS_FETCHED_SUBSCRIPTIONS = 'HAS_FETCHED_SUBSCRIPTIONS'; +reducers[ACTIONS.FETCH_FILE_INFO_STARTED] = function (state, action) { + var outpoint = action.data.outpoint; -// Video controls -var SET_VIDEO_PAUSE = exports.SET_VIDEO_PAUSE = 'SET_VIDEO_PAUSE'; + var newFetching = Object.assign({}, state.fetching); -// Media controls -var MEDIA_PLAY = exports.MEDIA_PLAY = 'MEDIA_PLAY'; -var MEDIA_PAUSE = exports.MEDIA_PAUSE = 'MEDIA_PAUSE'; -var MEDIA_POSITION = exports.MEDIA_POSITION = 'MEDIA_POSITION'; + newFetching[outpoint] = true; + + return Object.assign({}, state, { + fetching: newFetching + }); +}; + +reducers[ACTIONS.FETCH_FILE_INFO_COMPLETED] = function (state, action) { + var _action$data = action.data, + fileInfo = _action$data.fileInfo, + outpoint = _action$data.outpoint; + + + var newByOutpoint = Object.assign({}, state.byOutpoint); + var newFetching = Object.assign({}, state.fetching); + + newByOutpoint[outpoint] = fileInfo; + delete newFetching[outpoint]; + + return Object.assign({}, state, { + byOutpoint: newByOutpoint, + fetching: newFetching + }); +}; + +reducers[ACTIONS.DOWNLOADING_STARTED] = function (state, action) { + var _action$data2 = action.data, + uri = _action$data2.uri, + outpoint = _action$data2.outpoint, + fileInfo = _action$data2.fileInfo; + + + var newByOutpoint = Object.assign({}, state.byOutpoint); + var newDownloading = Object.assign({}, state.downloadingByOutpoint); + var newLoading = Object.assign({}, state.urisLoading); + + newDownloading[outpoint] = true; + newByOutpoint[outpoint] = fileInfo; + delete newLoading[uri]; + + return Object.assign({}, state, { + downloadingByOutpoint: newDownloading, + urisLoading: newLoading, + byOutpoint: newByOutpoint + }); +}; + +reducers[ACTIONS.DOWNLOADING_PROGRESSED] = function (state, action) { + var _action$data3 = action.data, + outpoint = _action$data3.outpoint, + fileInfo = _action$data3.fileInfo; + + + var newByOutpoint = Object.assign({}, state.byOutpoint); + var newDownloading = Object.assign({}, state.downloadingByOutpoint); + + newByOutpoint[outpoint] = fileInfo; + newDownloading[outpoint] = true; + + return Object.assign({}, state, { + byOutpoint: newByOutpoint, + downloadingByOutpoint: newDownloading + }); +}; + +reducers[ACTIONS.DOWNLOADING_COMPLETED] = function (state, action) { + var _action$data4 = action.data, + outpoint = _action$data4.outpoint, + fileInfo = _action$data4.fileInfo; + + + var newByOutpoint = Object.assign({}, state.byOutpoint); + var newDownloading = Object.assign({}, state.downloadingByOutpoint); + + newByOutpoint[outpoint] = fileInfo; + delete newDownloading[outpoint]; + + return Object.assign({}, state, { + byOutpoint: newByOutpoint, + downloadingByOutpoint: newDownloading + }); +}; + +reducers[ACTIONS.FILE_DELETE] = function (state, action) { + var outpoint = action.data.outpoint; + + + var newByOutpoint = Object.assign({}, state.byOutpoint); + var downloadingByOutpoint = Object.assign({}, state.downloadingByOutpoint); + + delete newByOutpoint[outpoint]; + delete downloadingByOutpoint[outpoint]; + + return Object.assign({}, state, { + byOutpoint: newByOutpoint, + downloadingByOutpoint: downloadingByOutpoint + }); +}; + +reducers[ACTIONS.LOADING_VIDEO_STARTED] = function (state, action) { + var uri = action.data.uri; + + + var newLoading = Object.assign({}, state.urisLoading); + + newLoading[uri] = true; + + return Object.assign({}, state, { + urisLoading: newLoading + }); +}; + +reducers[ACTIONS.LOADING_VIDEO_FAILED] = function (state, action) { + var uri = action.data.uri; + + + var newLoading = Object.assign({}, state.urisLoading); + + delete newLoading[uri]; + + return Object.assign({}, state, { + urisLoading: newLoading + }); +}; + +reducers[ACTIONS.FETCH_DATE] = function (state, action) { + var time = action.data.time; + + if (time) { + return Object.assign({}, state, { + publishedDate: time + }); + } + return null; +}; + +function fileInfoReducer() { + var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState; + var action = arguments[1]; + + var handler = reducers[action.type]; + if (handler) return handler(state, action); + return state; +} + +/***/ }), +/* 32 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.notificationsReducer = notificationsReducer; + +var _action_types = __webpack_require__(0); + +var ACTIONS = _interopRequireWildcard(_action_types); + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +var reducers = {}; + +var defaultState = { + // First-in, first-out + queue: [] +}; + +reducers[ACTIONS.NOTIFICATION_CREATED] = function (state, action) { + var _action$data = action.data, + title = _action$data.title, + message = _action$data.message, + type = _action$data.type, + errorCode = _action$data.errorCode, + displayType = _action$data.displayType; + + var queue = Object.assign([], state.queue); + queue.push({ + title: title, + message: message, + type: type, + errorCode: errorCode, + displayType: displayType + }); + + return Object.assign({}, state, { + queue: queue + }); +}; + +reducers[ACTIONS.NOTIFICATION_DISPLAYED] = function (state) { + var queue = Object.assign([], state.queue); + queue.shift(); + + return Object.assign({}, state, { + queue: queue + }); +}; + +function notificationsReducer() { + var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState; + var action = arguments[1]; + + var handler = reducers[action.type]; + if (handler) return handler(state, action); + return state; +} + +/***/ }), +/* 33 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.searchReducer = undefined; + +var _handleActions; + +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + +var _action_types = __webpack_require__(0); + +var ACTIONS = _interopRequireWildcard(_action_types); + +var _reduxUtils = __webpack_require__(34); + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +var defaultState = { + isActive: false, + searchQuery: '', // needs to be an empty string for input focusing + suggestions: [], + urisByQuery: {} +}; + +var searchReducer = exports.searchReducer = (0, _reduxUtils.handleActions)((_handleActions = {}, _defineProperty(_handleActions, ACTIONS.SEARCH_START, function (state) { + return _extends({}, state, { + searching: true + }); +}), _defineProperty(_handleActions, ACTIONS.SEARCH_SUCCESS, function (state, action) { + var _action$data = action.data, + query = _action$data.query, + uris = _action$data.uris; + + + return _extends({}, state, { + searching: false, + urisByQuery: Object.assign({}, state.urisByQuery, _defineProperty({}, query, uris)) + }); +}), _defineProperty(_handleActions, ACTIONS.SEARCH_FAIL, function (state) { + return _extends({}, state, { + searching: false + }); +}), _defineProperty(_handleActions, ACTIONS.UPDATE_SEARCH_QUERY, function (state, action) { + return _extends({}, state, { + searchQuery: action.data.query, + isActive: true + }); +}), _defineProperty(_handleActions, ACTIONS.UPDATE_SEARCH_SUGGESTIONS, function (state, action) { + return _extends({}, state, { + suggestions: action.data.suggestions + }); +}), _defineProperty(_handleActions, ACTIONS.HISTORY_NAVIGATE, function (state) { + return _extends({}, state, { + searchQuery: '', + suggestions: [], + isActive: false + }); +}), _defineProperty(_handleActions, ACTIONS.CLOSE_MODAL, function (state) { + return _extends({}, state, { + isActive: false + }); +}), _handleActions), defaultState); + +/***/ }), +/* 34 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +// 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 +var handleActions = exports.handleActions = function handleActions(actionMap, defaultState) { + return function () { + var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState; + var action = arguments[1]; + + var handler = actionMap[action.type]; + + if (handler) { + var newState = handler(state, action); + return Object.assign({}, state, newState); + } + + // just return the original state if no handler + // returning a copy here breaks redux-persist + return state; + }; +}; + +/***/ }), +/* 35 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.walletReducer = walletReducer; + +var _action_types = __webpack_require__(0); + +var ACTIONS = _interopRequireWildcard(_action_types); + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +var reducers = {}; +var buildDraftTransaction = function buildDraftTransaction() { + return { + amount: undefined, + address: undefined + }; +}; + +var defaultState = { + balance: undefined, + blocks: {}, + transactions: {}, + fetchingTransactions: false, + gettingNewAddress: false, + draftTransaction: buildDraftTransaction(), + sendingSupport: false +}; + +reducers[ACTIONS.FETCH_TRANSACTIONS_STARTED] = function (state) { + return Object.assign({}, state, { + fetchingTransactions: true + }); +}; + +reducers[ACTIONS.FETCH_TRANSACTIONS_COMPLETED] = function (state, action) { + var byId = Object.assign({}, state.transactions); + + var transactions = action.data.transactions; + + + transactions.forEach(function (transaction) { + byId[transaction.txid] = transaction; + }); + + return Object.assign({}, state, { + transactions: byId, + fetchingTransactions: false + }); +}; + +reducers[ACTIONS.GET_NEW_ADDRESS_STARTED] = function (state) { + return Object.assign({}, state, { + gettingNewAddress: true + }); +}; + +reducers[ACTIONS.GET_NEW_ADDRESS_COMPLETED] = function (state, action) { + var address = action.data.address; + + // Say no to localStorage! + + return Object.assign({}, state, { + gettingNewAddress: false, + receiveAddress: address + }); +}; + +reducers[ACTIONS.UPDATE_BALANCE] = function (state, action) { + return Object.assign({}, state, { + balance: action.data.balance + }); +}; + +reducers[ACTIONS.CHECK_ADDRESS_IS_MINE_STARTED] = function (state) { + return Object.assign({}, state, { + checkingAddressOwnership: true + }); +}; + +reducers[ACTIONS.CHECK_ADDRESS_IS_MINE_COMPLETED] = function (state) { + return Object.assign({}, state, { + checkingAddressOwnership: false + }); +}; + +reducers[ACTIONS.SET_DRAFT_TRANSACTION_AMOUNT] = function (state, action) { + var oldDraft = state.draftTransaction; + var newDraft = Object.assign({}, oldDraft, { + amount: parseFloat(action.data.amount) + }); + + return Object.assign({}, state, { + draftTransaction: newDraft + }); +}; + +reducers[ACTIONS.SET_DRAFT_TRANSACTION_ADDRESS] = function (state, action) { + var oldDraft = state.draftTransaction; + var newDraft = Object.assign({}, oldDraft, { + address: action.data.address + }); + + return Object.assign({}, state, { + draftTransaction: newDraft + }); +}; + +reducers[ACTIONS.SEND_TRANSACTION_STARTED] = function (state) { + var newDraftTransaction = Object.assign({}, state.draftTransaction, { + sending: true + }); + + return Object.assign({}, state, { + draftTransaction: newDraftTransaction + }); +}; + +reducers[ACTIONS.SEND_TRANSACTION_COMPLETED] = function (state) { + return Object.assign({}, state, { + draftTransaction: buildDraftTransaction() + }); +}; + +reducers[ACTIONS.SEND_TRANSACTION_FAILED] = function (state, action) { + var newDraftTransaction = Object.assign({}, state.draftTransaction, { + sending: false, + error: action.data.error + }); + + return Object.assign({}, state, { + draftTransaction: newDraftTransaction + }); +}; + +reducers[ACTIONS.SUPPORT_TRANSACTION_STARTED] = function (state) { + return Object.assign({}, state, { + sendingSupport: true + }); +}; + +reducers[ACTIONS.SUPPORT_TRANSACTION_COMPLETED] = function (state) { + return Object.assign({}, state, { + sendingSupport: false + }); +}; + +reducers[ACTIONS.SUPPORT_TRANSACTION_FAILED] = function (state, action) { + return Object.assign({}, state, { + error: action.data.error, + sendingSupport: false + }); +}; + +reducers[ACTIONS.FETCH_BLOCK_SUCCESS] = function (state, action) { + var _action$data = action.data, + block = _action$data.block, + height = _action$data.block.height; + + var blocks = Object.assign({}, state.blocks); + + blocks[height] = block; + + return Object.assign({}, state, { blocks: blocks }); +}; + +function walletReducer() { + var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState; + var action = arguments[1]; + + var handler = reducers[action.type]; + if (handler) return handler(state, action); + return state; +} + +/***/ }), +/* 36 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.selectNotification = exports.selectState = undefined; + +var _reselect = __webpack_require__(1); + +var selectState = exports.selectState = function selectState(state) { + return state.notifications || {}; +}; + +var selectNotification = exports.selectNotification = (0, _reselect.createSelector)(selectState, function (state) { + return state.queue.length > 0 ? state.queue[0] : {}; +}); + +/***/ }), +/* 37 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.makeSelectFetchingCostInfoForUri = exports.selectFetchingCostInfo = exports.selectCostForCurrentPageUri = exports.makeSelectCostInfoForUri = exports.selectAllCostInfoByUri = exports.selectState = undefined; + +var _reselect = __webpack_require__(1); + +var _navigation = __webpack_require__(5); + +var selectState = exports.selectState = function selectState(state) { + return state.costInfo || {}; +}; + +var selectAllCostInfoByUri = exports.selectAllCostInfoByUri = (0, _reselect.createSelector)(selectState, function (state) { + return state.byUri || {}; +}); + +var makeSelectCostInfoForUri = exports.makeSelectCostInfoForUri = function makeSelectCostInfoForUri(uri) { + return (0, _reselect.createSelector)(selectAllCostInfoByUri, function (costInfos) { + return costInfos && costInfos[uri]; + }); +}; + +var selectCostForCurrentPageUri = exports.selectCostForCurrentPageUri = (0, _reselect.createSelector)(selectAllCostInfoByUri, _navigation.selectCurrentParams, function (costInfo, params) { + return params.uri && costInfo[params.uri] ? costInfo[params.uri].cost : undefined; +}); + +var selectFetchingCostInfo = exports.selectFetchingCostInfo = (0, _reselect.createSelector)(selectState, function (state) { + return state.fetching || {}; +}); + +var makeSelectFetchingCostInfoForUri = exports.makeSelectFetchingCostInfoForUri = function makeSelectFetchingCostInfoForUri(uri) { + return (0, _reselect.createSelector)(selectFetchingCostInfo, function (fetchingByUri) { + return fetchingByUri && fetchingByUri[uri]; + }); +}; + +/***/ }), +/* 38 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +/* hardcoded names still exist for these in reducers/settings.js - only discovered when debugging */ +/* Many SETTINGS are stored in the localStorage by their name - + be careful about changing the value of a SETTINGS constant, as doing so can invalidate existing SETTINGS */ +var CREDIT_REQUIRED_ACKNOWLEDGED = exports.CREDIT_REQUIRED_ACKNOWLEDGED = 'credit_required_acknowledged'; +var NEW_USER_ACKNOWLEDGED = exports.NEW_USER_ACKNOWLEDGED = 'welcome_acknowledged'; +var EMAIL_COLLECTION_ACKNOWLEDGED = exports.EMAIL_COLLECTION_ACKNOWLEDGED = 'email_collection_acknowledged'; +var LANGUAGE = exports.LANGUAGE = 'language'; +var SHOW_NSFW = exports.SHOW_NSFW = 'showNsfw'; +var SHOW_UNAVAILABLE = exports.SHOW_UNAVAILABLE = 'showUnavailable'; +var INSTANT_PURCHASE_ENABLED = exports.INSTANT_PURCHASE_ENABLED = 'instantPurchaseEnabled'; +var INSTANT_PURCHASE_MAX = exports.INSTANT_PURCHASE_MAX = 'instantPurchaseMax'; +var THEME = exports.THEME = 'theme'; +var THEMES = exports.THEMES = 'themes'; +var AUTOMATIC_DARK_MODE_ENABLED = exports.AUTOMATIC_DARK_MODE_ENABLED = 'automaticDarkModeEnabled'; + +// mobile settings +var KEEP_DAEMON_RUNNING = exports.KEEP_DAEMON_RUNNING = 'keepDaemonRunning'; /***/ }) -/******/ ]); \ No newline at end of file +/******/ ]); +}); \ No newline at end of file diff --git a/package.json b/package.json index f66958f..f0c3be8 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "main": "build/index.js", "scripts": { "build": "webpack", + "precommit": "lint-staged", "lint": "eslint 'src/**/*.{js,jsx}' --fix", "format": "prettier 'src/**/*.{js,jsx,scss,json}' --write" }, @@ -28,35 +29,22 @@ "bluebird": "^3.5.1", "classnames": "^2.2.5", "electron-dl": "^1.6.0", - "formik": "^0.10.4", "from2": "^2.3.0", "install": "^0.10.2", "jayson": "^2.0.2", "jshashes": "^1.0.7", - "keytar": "^4.0.3", - "localforage": "^1.5.0", - "npm": "^5.5.1", - "qrcode.react": "^0.7.2", + "proxy-polyfill": "0.1.6", "rc-progress": "^2.0.6", "react": "^16.2.0", - "react-dom": "^16.2.0", - "react-markdown": "^2.5.0", - "react-modal": "^3.1.7", - "react-paginate": "^5.0.0", "react-redux": "^5.0.3", - "react-simplemde-editor": "^3.6.11", "redux": "^3.6.0", "redux-action-buffer": "^1.1.0", "redux-logger": "^3.0.1", "redux-persist": "^4.8.0", "redux-persist-transform-compress": "^4.2.0", "redux-persist-transform-filter": "0.0.10", - "redux-thunk": "^2.2.0", - "render-media": "^2.10.0", "reselect": "^3.0.0", "semver": "^5.3.0", - "shapeshift.io": "^1.3.1", - "source-map-support": "^0.5.0", "tree-kill": "^1.1.0", "y18n": "^4.0.0" }, @@ -96,13 +84,6 @@ "webpack": "^3.10.0", "webpack-build-notifier": "^0.1.18" }, - "resolutions": { - "webpack/webpack-sources": "1.0.1" - }, - "engines": { - "node": ">=6", - "yarn": "^1.3" - }, "license": "MIT", "lbrySettings": { "lbrynetDaemonVersion": "0.18.0", diff --git a/src/constants/action_types.js b/src/constants/action_types.js index 3c828f5..dce993d 100644 --- a/src/constants/action_types.js +++ b/src/constants/action_types.js @@ -28,6 +28,8 @@ export const UPDATE_VERSION = 'UPDATE_VERSION'; export const UPDATE_REMOTE_VERSION = 'UPDATE_REMOTE_VERSION'; export const SKIP_UPGRADE = 'SKIP_UPGRADE'; export const START_UPGRADE = 'START_UPGRADE'; +export const AUTO_UPDATE_DECLINED = 'AUTO_UPDATE_DECLINED'; +export const AUTO_UPDATE_DOWNLOADED = 'AUTO_UPDATE_DOWNLOADED'; // Wallet export const GET_NEW_ADDRESS_STARTED = 'GET_NEW_ADDRESS_STARTED'; @@ -37,8 +39,6 @@ export const FETCH_TRANSACTIONS_COMPLETED = 'FETCH_TRANSACTIONS_COMPLETED'; export const UPDATE_BALANCE = 'UPDATE_BALANCE'; export const CHECK_ADDRESS_IS_MINE_STARTED = 'CHECK_ADDRESS_IS_MINE_STARTED'; export const CHECK_ADDRESS_IS_MINE_COMPLETED = 'CHECK_ADDRESS_IS_MINE_COMPLETED'; -export const SET_DRAFT_TRANSACTION_AMOUNT = 'SET_DRAFT_TRANSACTION_AMOUNT'; -export const SET_DRAFT_TRANSACTION_ADDRESS = 'SET_DRAFT_TRANSACTION_ADDRESS'; export const SEND_TRANSACTION_STARTED = 'SEND_TRANSACTION_STARTED'; export const SEND_TRANSACTION_COMPLETED = 'SEND_TRANSACTION_COMPLETED'; export const SEND_TRANSACTION_FAILED = 'SEND_TRANSACTION_FAILED'; @@ -60,8 +60,8 @@ export const FETCH_CLAIM_LIST_MINE_STARTED = 'FETCH_CLAIM_LIST_MINE_STARTED'; export const FETCH_CLAIM_LIST_MINE_COMPLETED = 'FETCH_CLAIM_LIST_MINE_COMPLETED'; export const ABANDON_CLAIM_STARTED = 'ABANDON_CLAIM_STARTED'; export const ABANDON_CLAIM_SUCCEEDED = 'ABANDON_CLAIM_SUCCEEDED'; -export const FETCH_CHANNEL_LIST_MINE_STARTED = 'FETCH_CHANNEL_LIST_MINE_STARTED'; -export const FETCH_CHANNEL_LIST_MINE_COMPLETED = 'FETCH_CHANNEL_LIST_MINE_COMPLETED'; +export const FETCH_CHANNEL_LIST_STARTED = 'FETCH_CHANNEL_LIST_STARTED'; +export const FETCH_CHANNEL_LIST_COMPLETED = 'FETCH_CHANNEL_LIST_COMPLETED'; export const CREATE_CHANNEL_STARTED = 'CREATE_CHANNEL_STARTED'; export const CREATE_CHANNEL_COMPLETED = 'CREATE_CHANNEL_COMPLETED'; export const PUBLISH_STARTED = 'PUBLISH_STARTED'; @@ -82,19 +82,23 @@ export const LOADING_VIDEO_FAILED = 'LOADING_VIDEO_FAILED'; export const DOWNLOADING_STARTED = 'DOWNLOADING_STARTED'; export const DOWNLOADING_PROGRESSED = 'DOWNLOADING_PROGRESSED'; export const DOWNLOADING_COMPLETED = 'DOWNLOADING_COMPLETED'; +export const DOWNLOADING_CANCELED = 'DOWNLOADING_CANCELED'; export const PLAY_VIDEO_STARTED = 'PLAY_VIDEO_STARTED'; export const FETCH_AVAILABILITY_STARTED = 'FETCH_AVAILABILITY_STARTED'; export const FETCH_AVAILABILITY_COMPLETED = 'FETCH_AVAILABILITY_COMPLETED'; export const FILE_DELETE = 'FILE_DELETE'; // Search -export const SEARCH_STARTED = 'SEARCH_STARTED'; -export const SEARCH_COMPLETED = 'SEARCH_COMPLETED'; -export const SEARCH_CANCELLED = 'SEARCH_CANCELLED'; +export const SEARCH_START = 'SEARCH_START'; +export const SEARCH_SUCCESS = 'SEARCH_SUCCESS'; +export const SEARCH_FAIL = 'SEARCH_FAIL'; +export const UPDATE_SEARCH_QUERY = 'UPDATE_SEARCH_QUERY'; +export const UPDATE_SEARCH_SUGGESTIONS = 'UPDATE_SEARCH_SUGGESTIONS'; // Settings export const DAEMON_SETTINGS_RECEIVED = 'DAEMON_SETTINGS_RECEIVED'; export const CLIENT_SETTING_CHANGED = 'CLIENT_SETTING_CHANGED'; +export const UPDATE_IS_NIGHT = 'UPDATE_IS_NIGHT'; // User export const AUTHENTICATION_STARTED = 'AUTHENTICATION_STARTED'; @@ -108,6 +112,13 @@ export const USER_EMAIL_NEW_FAILURE = 'USER_EMAIL_NEW_FAILURE'; export const USER_EMAIL_VERIFY_STARTED = 'USER_EMAIL_VERIFY_STARTED'; export const USER_EMAIL_VERIFY_SUCCESS = 'USER_EMAIL_VERIFY_SUCCESS'; export const USER_EMAIL_VERIFY_FAILURE = 'USER_EMAIL_VERIFY_FAILURE'; +export const USER_PHONE_RESET = 'USER_PHONE_RESET'; +export const USER_PHONE_NEW_STARTED = 'USER_PHONE_NEW_STARTED'; +export const USER_PHONE_NEW_SUCCESS = 'USER_PHONE_NEW_SUCCESS'; +export const USER_PHONE_NEW_FAILURE = 'USER_PHONE_NEW_FAILURE'; +export const USER_PHONE_VERIFY_STARTED = 'USER_PHONE_VERIFY_STARTED'; +export const USER_PHONE_VERIFY_SUCCESS = 'USER_PHONE_VERIFY_SUCCESS'; +export const USER_PHONE_VERIFY_FAILURE = 'USER_PHONE_VERIFY_FAILURE'; export const USER_IDENTITY_VERIFY_STARTED = 'USER_IDENTITY_VERIFY_STARTED'; export const USER_IDENTITY_VERIFY_SUCCESS = 'USER_IDENTITY_VERIFY_SUCCESS'; export const USER_IDENTITY_VERIFY_FAILURE = 'USER_IDENTITY_VERIFY_FAILURE'; @@ -154,6 +165,12 @@ export const CLEAR_SHAPE_SHIFT = 'CLEAR_SHAPE_SHIFT'; export const CHANNEL_SUBSCRIBE = 'CHANNEL_SUBSCRIBE'; export const CHANNEL_UNSUBSCRIBE = 'CHANNEL_UNSUBSCRIBE'; export const HAS_FETCHED_SUBSCRIPTIONS = 'HAS_FETCHED_SUBSCRIPTIONS'; +export const SET_SUBSCRIPTION_LATEST = 'SET_SUBSCRIPTION_LATEST'; +export const SET_SUBSCRIPTION_NOTIFICATION = 'SET_SUBSCRIPTION_NOTIFICATION'; +export const SET_SUBSCRIPTION_NOTIFICATIONS = 'SET_SUBSCRIPTION_NOTIFICATIONS'; +export const CHECK_SUBSCRIPTION_STARTED = 'CHECK_SUBSCRIPTION_STARTED'; +export const CHECK_SUBSCRIPTION_COMPLETED = 'CHECK_SUBSCRIPTION_COMPLETED'; +export const CHECK_SUBSCRIPTIONS_SUBSCRIBE = 'CHECK_SUBSCRIPTIONS_SUBSCRIBE'; // Video controls export const SET_VIDEO_PAUSE = 'SET_VIDEO_PAUSE'; @@ -162,3 +179,13 @@ export const SET_VIDEO_PAUSE = 'SET_VIDEO_PAUSE'; export const MEDIA_PLAY = 'MEDIA_PLAY'; export const MEDIA_PAUSE = 'MEDIA_PAUSE'; export const MEDIA_POSITION = 'MEDIA_POSITION'; + +// Publishing +export const CLEAR_PUBLISH = 'CLEAR_PUBLISH'; +export const UPDATE_PUBLISH_FORM = 'UPDATE_PUBLISH_FORM'; +export const PUBLISH_START = 'PUBLISH_START'; +export const PUBLISH_SUCCESS = 'PUBLISH_SUCCESS'; +export const PUBLISH_FAIL = 'PUBLISH_FAIL'; +export const CLEAR_PUBLISH_ERROR = 'CLEAR_PUBLISH_ERROR'; +export const REMOVE_PENDING_PUBLISH = 'REMOVE_PENDING_PUBLISH'; +export const DO_PREPARE_EDIT = 'DO_PREPARE_EDIT'; diff --git a/src/constants/search.js b/src/constants/search.js new file mode 100644 index 0000000..5bdbcd1 --- /dev/null +++ b/src/constants/search.js @@ -0,0 +1,3 @@ +export const FILE = 'file'; +export const CHANNEL = 'channel'; +export const SEARCH = 'search'; diff --git a/src/constants/settings.js b/src/constants/settings.js index dcb90ab..ca6652c 100644 --- a/src/constants/settings.js +++ b/src/constants/settings.js @@ -11,3 +11,7 @@ export const INSTANT_PURCHASE_ENABLED = 'instantPurchaseEnabled'; export const INSTANT_PURCHASE_MAX = 'instantPurchaseMax'; export const THEME = 'theme'; export const THEMES = 'themes'; +export const AUTOMATIC_DARK_MODE_ENABLED = 'automaticDarkModeEnabled'; + +// mobile settings +export const KEEP_DAEMON_RUNNING = 'keepDaemonRunning'; diff --git a/src/index.js b/src/index.js index 03af8ef..6a1af48 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,176 @@ -export { Lbry } from 'lbry'; -export { LbryApi } from 'lbryapi'; +import * as ACTIONS from 'constants/action_types'; +import * as SETTINGS from 'constants/settings'; +import Lbry from 'lbry'; +import Lbryapi from 'lbryapi'; +import { selectState as selectSearchState } from 'redux/selectors/search'; -export { costInfoReducer } from 'redux/reducers/cost_info'; \ No newline at end of file +// types +export { Notification } from 'types/Notification'; + +// constants +export { ACTIONS, SETTINGS }; + +// common +export { Lbry, Lbryapi }; +export { + regexInvalidURI, + regexAddress, + parseURI, + buildURI, + normalizeURI, + isURIValid, + isURIClaimable, +} from 'lbryURI'; + +// actions +export { doNotify } from 'redux/actions/notifications'; + +export { + doFetchClaimListMine, + doAbandonClaim, + doResolveUris, + doResolveUri, + doFetchFeaturedUris, + doFetchRewardedContent, +} from 'redux/actions/claims'; + +export { doFetchCostInfoForUri } from 'redux/actions/cost_info'; + +export { + doFetchFileInfo, + doFileList, + doFetchFileInfosAndPublishedClaims, +} from 'redux/actions/file_info'; + +export { doSearch, doUpdateSearchQuery } from 'redux/actions/search'; + +export { + doUpdateBalance, + doBalanceSubscribe, + doFetchTransactions, + doFetchBlock, + doGetNewAddress, + doCheckAddressIsMine, + doSendDraftTransaction, + doSetDraftTransactionAmount, + doSetDraftTransactionAddress, + doSendSupport, +} from 'redux/actions/wallet'; + +// utils +export { batchActions } from 'util/batchActions'; +export { parseQueryParams, toQueryString } from 'util/query_params'; +export { formatCredits, formatFullPrice } from 'util/formatCredits'; + +// reducers +export { claimsReducer } from 'redux/reducers/claims'; +export { costInfoReducer } from 'redux/reducers/cost_info'; +export { fileInfoReducer } from 'redux/reducers/file_info'; +export { notificationsReducer } from 'redux/reducers/notifications'; +export { searchReducer } from 'redux/reducers/search'; +export { walletReducer } from 'redux/reducers/wallet'; + +// selectors +export { selectNotification } from 'redux/selectors/notifications'; + +export { + makeSelectClaimForUri, + makeSelectClaimIsMine, + makeSelectFetchingChannelClaims, + makeSelectClaimsInChannelForCurrentPage, + makeSelectMetadataForUri, + makeSelectTitleForUri, + makeSelectContentTypeForUri, + makeSelectIsUriResolving, + makeSelectTotalItemsForChannel, + makeSelectTotalPagesForChannel, + selectClaimsById, + selectClaimsByUri, + selectAllClaimsByChannel, + selectMyClaimsRaw, + selectAbandoningIds, + selectMyActiveClaims, + selectAllFetchingChannelClaims, + selectIsFetchingClaimListMine, + selectPendingClaims, + selectMyClaims, + selectMyClaimsWithoutChannels, + selectAllMyClaimsByOutpoint, + selectMyClaimsOutpoints, + selectFetchingMyChannels, + selectMyChannelClaims, + selectResolvingUris, + selectFeaturedUris, + selectFetchingFeaturedUris, + selectPlayingUri, + selectChannelClaimCounts, + selectRewardContentClaimIds, +} from 'redux/selectors/claims'; + +export { + makeSelectFetchingCostInfoForUri, + makeSelectCostInfoForUri, + selectAllCostInfoByUri, + selectCostForCurrentPageUri, + selectFetchingCostInfo, +} from 'redux/selectors/cost_info'; + +export { + makeSelectFileInfoForUri, + makeSelectDownloadingForUri, + makeSelectLoadingForUri, + selectFileInfosByOutpoint, + selectIsFetchingFileList, + selectIsFetchingFileListDownloadedOrPublished, + selectDownloadingByOutpoint, + selectUrisLoading, + selectFileInfosDownloaded, + selectDownloadingFileInfos, + selectTotalDownloadProgress, + selectSearchDownloadUris, +} from 'redux/selectors/file_info'; + +export { + computePageFromPath, + makeSelectCurrentParam, + selectCurrentPath, + selectCurrentPage, + selectCurrentParams, + selectHeaderLinks, + selectPageTitle, + selectPathAfterAuth, + selectIsBackDisabled, + selectIsForwardDisabled, + selectHistoryIndex, + selectHistoryStack, + selectActiveHistoryEntry, + selectNavLinks, +} from 'redux/selectors/navigation'; + +export { selectSearchState }; +export { + makeSelectSearchUris, + selectSearchQuery, + selectSearchValue, + selectIsSearching, + selectSearchUrisByQuery, + selectWunderBarAddress, +} from 'redux/selectors/search'; + +export { + makeSelectBlockDate, + selectBalance, + selectTransactionsById, + selectTransactionItems, + selectRecentTransactions, + selectHasTransactions, + selectIsFetchingTransactions, + selectIsSendingSupport, + selectReceiveAddress, + selectGettingNewAddress, + selectDraftTransaction, + selectDraftTransactionAmount, + selectDraftTransactionAddress, + selectDraftTransactionError, + selectBlocks, +} from 'redux/selectors/wallet'; diff --git a/src/jsonrpc.js b/src/jsonrpc.js deleted file mode 100644 index 8e11c4f..0000000 --- a/src/jsonrpc.js +++ /dev/null @@ -1,86 +0,0 @@ -const jsonrpc = {}; - -jsonrpc.call = ( - connectionString, - method, - params, - callback, - errorCallback, - connectFailedCallback -) => { - 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('Protocol error with unknown response signature'); - } - return Promise.reject(error); - }); - } - - const counter = parseInt(sessionStorage.getItem('JSONRPCCounter') || 0, 10); - const url = connectionString; - const options = { - method: 'POST', - body: JSON.stringify({ - jsonrpc: '2.0', - method, - params, - id: counter, - }), - }; - - sessionStorage.setItem('JSONRPCCounter', counter + 1); - - return fetch(url, options) - .then(checkAndParse) - .then(response => { - const error = response.error || (response.result && response.result.error); - - if (!error && typeof callback === 'function') { - return callback(response.result); - } - - if (error && typeof errorCallback === 'function') { - return errorCallback(error); - } - - const errorEvent = new CustomEvent('unhandledError', { - detail: { - connectionString, - method, - params, - code: error.code, - message: error.message || error, - data: error.data, - }, - }); - document.dispatchEvent(errorEvent); - - return Promise.resolve(); - }) - .catch(error => { - if (connectFailedCallback) { - return connectFailedCallback(error); - } - - const errorEvent = new CustomEvent('unhandledError', { - detail: { - connectionString, - method, - params, - code: error.response && error.response.status, - message: __('Connection to API server failed'), - }, - }); - document.dispatchEvent(errorEvent); - return Promise.resolve(); - }); -}; - -export default jsonrpc; diff --git a/src/lbry.js b/src/lbry.js index 1a3b50f..f287d1f 100644 --- a/src/lbry.js +++ b/src/lbry.js @@ -1,4 +1,5 @@ -import jsonrpc from 'jsonrpc'; +// @flow +import 'proxy-polyfill'; const CHECK_DAEMON_STARTED_TRY_NUMBER = 200; @@ -8,116 +9,88 @@ const Lbry = { pendingPublishTimeout: 20 * 60 * 1000, }; -function apiCall(method, params, resolve, reject) { - return jsonrpc.call(Lbry.daemonConnectionString, method, params, resolve, reject, reject); +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('Protocol error with unknown response signature'); + } + return Promise.reject(error); + }); } -const lbryProxy = new Proxy(Lbry, { - get(target, name) { - if (name in target) { - return target[name]; - } +function apiCall(method: string, params: ?{}, resolve: Function, reject: Function) { + const counter = new Date().getTime(); + const options = { + method: 'POST', + body: JSON.stringify({ + jsonrpc: '2.0', + method, + params, + id: counter, + }), + }; - return (params = {}) => - new Promise((resolve, reject) => { - apiCall(name, params, resolve, reject); - }); - }, -}); + return fetch(Lbry.daemonConnectionString, options) + .then(checkAndParse) + .then(response => { + const error = response.error || (response.result && response.result.error); + + if (error) { + return reject(error); + } + return resolve(response.result); + }) + .catch(reject); +} function getLocal(key, fallback = undefined) { - const itemRaw = localStorage.getItem(key); + // const itemRaw = localStorage.getItem(key); + const itemRaw = null; return itemRaw === null ? fallback : JSON.parse(itemRaw); } function setLocal(key, value) { - localStorage.setItem(key, JSON.stringify(value)); -} - -/** - * Records a publish attempt in local storage. Returns a dictionary with all the data needed to - * needed to make a dummy claim or file info object. - */ -let pendingId = 0; -function savePendingPublish({ name, channelName }) { - pendingId += 1; - const pendingPublishes = getLocal('pendingPublishes') || []; - const newPendingPublish = { - name, - channelName, - claim_id: `pending-${pendingId}`, - txid: `pending-${pendingId}`, - nout: 0, - outpoint: `pending-${pendingId}:0`, - time: Date.now(), - }; - setLocal('pendingPublishes', [...pendingPublishes, newPendingPublish]); - return newPendingPublish; -} - -/** - * If there is a pending publish with the given name or outpoint, remove it. - * A channel name may also be provided along with name. - */ -function removePendingPublishIfNeeded({ name, channelName, outpoint }) { - function pubMatches(pub) { - return ( - pub.outpoint === outpoint || - (pub.name === name && (!channelName || pub.channel_name === channelName)) - ); - } - - setLocal('pendingPublishes', Lbry.getPendingPublishes().filter(pub => !pubMatches(pub))); -} - -/** - * Gets the current list of pending publish attempts. Filters out any that have timed out and - * removes them from the list. - */ -Lbry.getPendingPublishes = () => { - const pendingPublishes = getLocal('pendingPublishes') || []; - const newPendingPublishes = pendingPublishes.filter( - pub => Date.now() - pub.time <= Lbry.pendingPublishTimeout - ); - setLocal('pendingPublishes', newPendingPublishes); - return newPendingPublishes; -}; - -/** - * Gets a pending publish attempt by its name or (fake) outpoint. A channel name can also be - * provided along withe the name. If no pending publish is found, returns null. - */ -function getPendingPublish({ name, channelName, outpoint }) { - const pendingPublishes = Lbry.getPendingPublishes(); - return ( - pendingPublishes.find( - pub => - pub.outpoint === outpoint || - (pub.name === name && (!channelName || pub.channel_name === channelName)) - ) || null - ); -} - -function pendingPublishToDummyClaim({ channelName, name, outpoint, claimId, txid, nout }) { - return { name, outpoint, claimId, txid, nout, channelName }; -} - -function pendingPublishToDummyFileInfo({ name, outpoint, claimId }) { - return { name, outpoint, claimId, metadata: null }; + // localStorage.setItem(key, JSON.stringify(value)); } // core +Lbry.status = () => + new Promise((resolve, reject) => { + apiCall( + 'status', + {}, + status => { + resolve(status); + }, + reject + ); + }); + +Lbry.file_delete = (params = {}) => + new Promise((resolve, reject) => { + apiCall('file_delete', params, resolve, reject); + }); + +Lbry.file_set_status = (params = {}) => + new Promise((resolve, reject) => { + apiCall('file_set_status', params, resolve, reject); + }); + Lbry.connectPromise = null; Lbry.connect = () => { if (Lbry.connectPromise === null) { Lbry.connectPromise = new Promise((resolve, reject) => { let tryNum = 0; - // Check every half second to see if the daemon is accepting connections function checkDaemonStarted() { tryNum += 1; - lbryProxy - .status() + Lbry.status() .then(resolve) .catch(() => { if (tryNum <= CHECK_DAEMON_STARTED_TRY_NUMBER) { @@ -135,42 +108,6 @@ Lbry.connect = () => { return Lbry.connectPromise; }; -/** - * Publishes a file. The optional fileListedCallback is called when the file becomes available in - * lbry.file_list() during the publish process. - * - * This currently includes a work-around to cache the file in local storage so that the pending - * publish can appear in the UI immediately. - */ -Lbry.publishDeprecated = (params, fileListedCallback, publishedCallback, errorCallback) => { - // Give a short grace period in case publish() returns right away or (more likely) gives an error - const returnPendingTimeout = setTimeout( - () => { - const { name, channel_name: channelName } = params; - if (publishedCallback || fileListedCallback) { - savePendingPublish({ - name, - channelName, - }); - publishedCallback(true); - } - }, - 2000, - { once: true } - ); - - lbryProxy.publish(params).then( - result => { - if (returnPendingTimeout) clearTimeout(returnPendingTimeout); - publishedCallback(result); - }, - err => { - if (returnPendingTimeout) clearTimeout(returnPendingTimeout); - errorCallback(err); - } - ); -}; - Lbry.getMediaType = (contentType, fileName) => { if (contentType) { return /^[^/]+/.exec(contentType)[0]; @@ -204,35 +141,13 @@ Lbry.getMediaType = (contentType, fileName) => { */ Lbry.file_list = (params = {}) => new Promise((resolve, reject) => { - const { name, channel_name: channelName, outpoint } = params; - - /** - * If we're searching by outpoint, check first to see if there's a matching pending publish. - * Pending publishes use their own faux outpoints that are always unique, so we don't need - * to check if there's a real file. - */ - if (outpoint) { - const pendingPublish = getPendingPublish({ outpoint }); - if (pendingPublish) { - resolve([pendingPublishToDummyFileInfo(pendingPublish)]); - return; - } - } + const { claim_name: claimName, channel_name: channelName, outpoint } = params; apiCall( 'file_list', params, fileInfos => { - removePendingPublishIfNeeded({ name, channelName, outpoint }); - - // if a naked file_list call, append the pending file infos - if (!name && !channelName && !outpoint) { - const dummyFileInfos = Lbry.getPendingPublishes().map(pendingPublishToDummyFileInfo); - - resolve([...fileInfos, ...dummyFileInfos]); - } else { - resolve(fileInfos); - } + resolve(fileInfos); }, reject ); @@ -244,16 +159,19 @@ Lbry.claim_list_mine = (params = {}) => 'claim_list_mine', params, claims => { - claims.forEach(({ name, channel_name: channelName, txid, nout }) => { - removePendingPublishIfNeeded({ - name, - channelName, - outpoint: `${txid}:${nout}`, - }); - }); + resolve(claims); + }, + reject + ); + }); - const dummyClaims = Lbry.getPendingPublishes().map(pendingPublishToDummyClaim); - resolve([...claims, ...dummyClaims]); +Lbry.get = (params = {}) => + new Promise((resolve, reject) => { + apiCall( + 'get', + params, + streamInfo => { + resolve(streamInfo); }, reject ); @@ -276,4 +194,17 @@ Lbry.resolve = (params = {}) => ); }); +const lbryProxy = new Proxy(Lbry, { + get(target, name) { + if (name in target) { + return target[name]; + } + + return (params = {}) => + new Promise((resolve, reject) => { + apiCall(name, params, resolve, reject); + }); + }, +}); + export default lbryProxy; diff --git a/src/lbryURI.js b/src/lbryURI.js new file mode 100644 index 0000000..9fd136b --- /dev/null +++ b/src/lbryURI.js @@ -0,0 +1,230 @@ +const channelNameMinLength = 1; +const claimIdMaxLength = 40; + +export const regexInvalidURI = /[^A-Za-z0-9-]/g; +export const regexAddress = /^b(?=[^0OIl]{32,33})[0-9A-Za-z]{32,33}$/; + +/** + * Parses a LBRY name into its component parts. Throws errors with user-friendly + * messages for invalid names. + * + * N.B. that "name" indicates the value in the name position of the URI. For + * claims for channel content, this will actually be the channel name, and + * the content name is in the path (e.g. lbry://@channel/content) + * + * In most situations, you'll want to use the contentName and channelName keys + * and ignore the name key. + * + * Returns a dictionary with keys: + * - name (string): The value in the "name" position in the URI. Note that this + * could be either content name or channel name; see above. + * - path (string, if persent) + * - claimSequence (int, if present) + * - bidPosition (int, if present) + * - claimId (string, if present) + * - isChannel (boolean) + * - contentName (string): For anon claims, the name; for channel claims, the path + * - channelName (string, if present): Channel name without @ + */ +export function parseURI(URI, requireProto = false) { + // Break into components. Empty sub-matches are converted to null + const componentsRegex = new RegExp( + '^((?:lbry://)?)' + // protocol + '([^:$#/]*)' + // claim name (stops at the first separator or end) + '([:$#]?)([^/]*)' + // modifier separator, modifier (stops at the first path separator or end) + '(/?)(.*)' // path separator, path + ); + const [proto, claimName, modSep, modVal, pathSep, path] = componentsRegex + .exec(URI) + .slice(1) + .map(match => match || null); + + let contentName; + + // Validate protocol + if (requireProto && !proto) { + throw new Error(__('LBRY URIs must include a protocol prefix (lbry://).')); + } + + // Validate and process name + if (!claimName) { + throw new Error(__('URI does not include name.')); + } + + const isChannel = claimName.startsWith('@'); + const channelName = isChannel ? claimName.slice(1) : claimName; + + if (isChannel) { + if (!channelName) { + throw new Error(__('No channel name after @.')); + } + + if (channelName.length < channelNameMinLength) { + throw new Error(__(`Channel names must be at least %s characters.`, channelNameMinLength)); + } + + contentName = path; + } + + const nameBadChars = (channelName || claimName).match(regexInvalidURI); + if (nameBadChars) { + throw new Error( + __( + `Invalid character %s in name: %s.`, + nameBadChars.length === 1 ? '' : 's', + nameBadChars.join(', ') + ) + ); + } + + // Validate and process modifier (claim ID, bid position or claim sequence) + let claimId; + let claimSequence; + let bidPosition; + if (modSep) { + if (!modVal) { + throw new Error(__(`No modifier provided after separator %s.`, modSep)); + } + + if (modSep === '#') { + claimId = modVal; + } else if (modSep === ':') { + claimSequence = modVal; + } else if (modSep === '$') { + bidPosition = modVal; + } + } + + if ( + claimId && + (claimId.length > claimIdMaxLength || !claimId.match(/^[0-9a-f]+$/)) && + !claimId.match(/^pending/) // ought to be dropped when savePendingPublish drops hack + ) { + throw new Error(__(`Invalid claim ID %s.`, claimId)); + } + + if (claimSequence && !claimSequence.match(/^-?[1-9][0-9]*$/)) { + throw new Error(__('Claim sequence must be a number.')); + } + + if (bidPosition && !bidPosition.match(/^-?[1-9][0-9]*$/)) { + throw new Error(__('Bid position must be a number.')); + } + + // Validate and process path + if (path) { + if (!isChannel) { + throw new Error(__('Only channel URIs may have a path.')); + } + + const pathBadChars = path.match(regexInvalidURI); + if (pathBadChars) { + throw new Error(__(`Invalid character in path: %s`, pathBadChars.join(', '))); + } + + contentName = path; + } else if (pathSep) { + throw new Error(__('No path provided after /')); + } + + return { + claimName, + path, + isChannel, + ...(contentName ? { contentName } : {}), + ...(channelName ? { channelName } : {}), + ...(claimSequence ? { claimSequence: parseInt(claimSequence, 10) } : {}), + ...(bidPosition ? { bidPosition: parseInt(bidPosition, 10) } : {}), + ...(claimId ? { claimId } : {}), + ...(path ? { path } : {}), + }; +} + +/** + * Takes an object in the same format returned by parse() and builds a URI. + * + * The channelName key will accept names with or without the @ prefix. + */ +export function buildURI(URIObj, includeProto = true) { + const { claimId, claimSequence, bidPosition, contentName, channelName } = URIObj; + + let { claimName, path } = URIObj; + + if (channelName) { + const channelNameFormatted = channelName.startsWith('@') ? channelName : `@${channelName}`; + if (!claimName) { + claimName = channelNameFormatted; + } else if (claimName !== channelNameFormatted) { + throw new Error( + __( + 'Received a channel content URI, but claim name and channelName do not match. "name" represents the value in the name position of the URI (lbry://name...), which for channel content will be the channel name. In most cases, to construct a channel URI you should just pass channelName and contentName.' + ) + ); + } + } + + if (contentName) { + if (!claimName) { + claimName = contentName; + } else if (!path) { + path = contentName; + } + if (path && path !== contentName) { + throw new Error( + __( + 'Path and contentName do not match. Only one is required; most likely you wanted contentName.' + ) + ); + } + } + + return ( + (includeProto ? 'lbry://' : '') + + claimName + + (claimId ? `#${claimId}` : '') + + (claimSequence ? `:${claimSequence}` : '') + + (bidPosition ? `${bidPosition}` : '') + + (path ? `/${path}` : '') + ); +} + +/* Takes a parseable LBRY URI and converts it to standard, canonical format */ +export function normalizeURI(URI) { + if (URI.match(/pending_claim/)) return URI; + + const { claimName, path, bidPosition, claimSequence, claimId } = parseURI(URI); + return buildURI({ claimName, path, claimSequence, bidPosition, claimId }); +} + +export function isURIValid(URI) { + let parts; + try { + parts = parseURI(normalizeURI(URI)); + } catch (error) { + return false; + } + return parts && parts.claimName; +} + +export function isNameValid(claimName, checkCase = true) { + const regexp = new RegExp('^[a-z0-9-]+$', checkCase ? '' : 'i'); + return regexp.test(claimName); +} + +export function isURIClaimable(URI) { + let parts; + try { + parts = parseURI(normalizeURI(URI)); + } catch (error) { + return false; + } + return ( + parts && + parts.claimName && + !parts.claimId && + !parts.bidPosition && + !parts.claimSequence && + !parts.isChannel && + !parts.path + ); +} diff --git a/src/lbryapi.js b/src/lbryapi.js index 5cbcf06..630649a 100644 --- a/src/lbryapi.js +++ b/src/lbryapi.js @@ -1,7 +1,7 @@ -import Lbry from 'lbry'; import querystring from 'querystring'; -const LbryApi = { +const Lbryapi = { + enabled: true, exchangePromise: null, exchangeLastFetched: null, }; @@ -12,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 (!Lbryio.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'))); } @@ -82,4 +81,4 @@ LbryApi.call = (resource, action, params = {}, method = 'get') => { return makeRequest(url, options).then(response => response.data); }; -export default LbryApi; +export default Lbryapi; diff --git a/src/redux/actions/claims.js b/src/redux/actions/claims.js new file mode 100644 index 0000000..8fa939b --- /dev/null +++ b/src/redux/actions/claims.js @@ -0,0 +1,188 @@ +import * as ACTIONS from 'constants/action_types'; +import Lbry from 'lbry'; +import Lbryapi from 'lbryapi'; +import { buildURI, normalizeURI } from 'lbryURI'; +import { doNotify } from 'redux/actions/notifications'; +import { selectMyClaimsRaw, selectResolvingUris } from 'redux/selectors/claims'; +import { batchActions } from 'util/batchActions'; + +export function doResolveUris(uris) { + return (dispatch, getState) => { + const normalizedUris = uris.map(normalizeURI); + const state = getState(); + + // Filter out URIs that are already resolving + const resolvingUris = selectResolvingUris(state); + const urisToResolve = normalizedUris.filter(uri => !resolvingUris.includes(uri)); + + if (urisToResolve.length === 0) { + return; + } + + dispatch({ + type: ACTIONS.RESOLVE_URIS_STARTED, + data: { uris: normalizedUris }, + }); + + const resolveInfo = {}; + Lbry.resolve({ uris: urisToResolve }).then(result => { + Object.entries(result).forEach(([uri, uriResolveInfo]) => { + const fallbackResolveInfo = { + claim: null, + claimsInChannel: null, + certificate: null, + }; + + const { claim, certificate, claims_in_channel: claimsInChannel } = + uriResolveInfo && !uriResolveInfo.error ? uriResolveInfo : fallbackResolveInfo; + + resolveInfo[uri] = { claim, certificate, claimsInChannel }; + }); + + dispatch({ + type: ACTIONS.RESOLVE_URIS_COMPLETED, + data: { resolveInfo }, + }); + }); + }; +} + +export function doResolveUri(uri) { + return doResolveUris([uri]); +} + +export function doFetchClaimListMine() { + return dispatch => { + dispatch({ + type: ACTIONS.FETCH_CLAIM_LIST_MINE_STARTED, + }); + + Lbry.claim_list_mine().then(claims => { + dispatch({ + type: ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED, + data: { + claims, + }, + }); + }); + }; +} + +export function doAbandonClaim(txid, nout) { + return (dispatch, getState) => { + const state = getState(); + const myClaims = selectMyClaimsRaw(state); + const { claim_id: claimId, name } = myClaims.find( + claim => claim.txid === txid && claim.nout === nout + ); + + dispatch({ + type: ACTIONS.ABANDON_CLAIM_STARTED, + data: { + claimId, + }, + }); + + const errorCallback = () => { + dispatch( + doNotify({ + title: 'Transaction failed', + message: 'Transaction failed', + type: 'error', + displayType: ['modal', 'toast'], + }) + ); + }; + + const successCallback = results => { + if (results.txid) { + dispatch({ + type: ACTIONS.ABANDON_CLAIM_SUCCEEDED, + data: { + claimId, + }, + }); + dispatch(doResolveUri(buildURI({ name, claimId }))); + dispatch(doFetchClaimListMine()); + } else { + dispatch( + doNotify({ + title: 'Transaction failed', + message: 'Transaction failed', + type: 'error', + displayType: ['modal', 'toast'], + }) + ); + } + }; + + Lbry.claim_abandon({ + txid, + nout, + }).then(successCallback, errorCallback); + }; +} + +export function doFetchFeaturedUris() { + return dispatch => { + dispatch({ + type: ACTIONS.FETCH_FEATURED_CONTENT_STARTED, + }); + + const success = ({ Uris }) => { + let urisToResolve = []; + Object.keys(Uris).forEach(category => { + urisToResolve = [...urisToResolve, ...Uris[category]]; + }); + + const actions = [ + doResolveUris(urisToResolve), + { + type: ACTIONS.FETCH_FEATURED_CONTENT_COMPLETED, + data: { + uris: Uris, + success: true, + }, + }, + ]; + dispatch(batchActions(...actions)); + }; + + const failure = () => { + dispatch({ + type: ACTIONS.FETCH_FEATURED_CONTENT_COMPLETED, + data: { + uris: {}, + }, + }); + }; + + Lbryapi.call('file', 'list_homepage').then(success, failure); + }; +} + +export function doFetchRewardedContent() { + return dispatch => { + const success = nameToClaimId => { + dispatch({ + type: ACTIONS.FETCH_REWARD_CONTENT_COMPLETED, + data: { + claimIds: Object.values(nameToClaimId), + success: true, + }, + }); + }; + + const failure = () => { + dispatch({ + type: ACTIONS.FETCH_REWARD_CONTENT_COMPLETED, + data: { + claimIds: [], + success: false, + }, + }); + }; + + Lbryapi.call('reward', 'list_featured').then(success, failure); + }; +} diff --git a/src/redux/actions/file_info.js b/src/redux/actions/file_info.js new file mode 100644 index 0000000..25089d9 --- /dev/null +++ b/src/redux/actions/file_info.js @@ -0,0 +1,66 @@ +import * as ACTIONS from 'constants/action_types'; +import Lbry from 'lbry'; +import { doFetchClaimListMine } from 'redux/actions/claims'; +import { selectClaimsByUri, selectIsFetchingClaimListMine } from 'redux/selectors/claims'; +import { selectIsFetchingFileList, selectUrisLoading } from 'redux/selectors/file_info'; + +export function doFetchFileInfo(uri) { + return (dispatch, getState) => { + const state = getState(); + const claim = selectClaimsByUri(state)[uri]; + const outpoint = claim ? `${claim.txid}:${claim.nout}` : null; + const alreadyFetching = !!selectUrisLoading(state)[uri]; + + if (!alreadyFetching) { + dispatch({ + type: ACTIONS.FETCH_FILE_INFO_STARTED, + data: { + outpoint, + }, + }); + + Lbry.file_list({ outpoint, full_status: true }).then(fileInfos => { + dispatch({ + type: ACTIONS.FETCH_FILE_INFO_COMPLETED, + data: { + outpoint, + fileInfo: fileInfos && fileInfos.length ? fileInfos[0] : null, + }, + }); + }); + } + }; +} + +export function doFileList() { + return (dispatch, getState) => { + const state = getState(); + const isFetching = selectIsFetchingFileList(state); + + if (!isFetching) { + dispatch({ + type: ACTIONS.FILE_LIST_STARTED, + }); + + Lbry.file_list().then(fileInfos => { + dispatch({ + type: ACTIONS.FILE_LIST_SUCCEEDED, + data: { + fileInfos, + }, + }); + }); + } + }; +} + +export function doFetchFileInfosAndPublishedClaims() { + return (dispatch, getState) => { + const state = getState(); + const isFetchingClaimListMine = selectIsFetchingClaimListMine(state); + const isFetchingFileInfo = selectIsFetchingFileList(state); + + if (!isFetchingClaimListMine) dispatch(doFetchClaimListMine()); + if (!isFetchingFileInfo) dispatch(doFileList()); + }; +} diff --git a/src/redux/actions/notifications.js b/src/redux/actions/notifications.js new file mode 100644 index 0000000..ce5d085 --- /dev/null +++ b/src/redux/actions/notifications.js @@ -0,0 +1,10 @@ +// @flow +import * as ACTIONS from 'constants/action_types'; +import Notification from 'types/Notification'; + +export function doNotify(data: Notification) { + return { + type: ACTIONS.CREATE_NOTIFICATION, + data, + }; +} diff --git a/src/redux/actions/search.js b/src/redux/actions/search.js new file mode 100644 index 0000000..7a2e009 --- /dev/null +++ b/src/redux/actions/search.js @@ -0,0 +1,174 @@ +// @flow +import * as ACTIONS from 'constants/action_types'; +import * as SEARCH_TYPES from 'constants/search'; +import { normalizeURI, buildURI, parseURI } from 'lbryURI'; +import { doResolveUri } from 'redux/actions/claims'; +import { makeSelectSearchUris } from 'redux/selectors/search'; +import { batchActions } from 'util/batchActions'; +import handleFetchResponse from 'util/handle-fetch'; + +export const doSearch = rawQuery => (dispatch, getState) => { + const state = getState(); + const query = rawQuery.replace(/^lbry:\/\//i, ''); + + if (!query) { + dispatch({ + type: ACTIONS.SEARCH_FAIL, + }); + return; + } + + // If we have already searched for something, we don't need to do anything + const urisForQuery = makeSelectSearchUris(query)(state); + if (urisForQuery && !!urisForQuery.length) { + return; + } + + dispatch({ + type: ACTIONS.SEARCH_START, + }); + + // If the user is on the file page with a pre-populated uri and they select + // the search option without typing anything, searchQuery will be empty + // We need to populate it so the input is filled on the search page + if (!state.search.searchQuery) { + dispatch({ + type: ACTIONS.UPDATE_SEARCH_QUERY, + data: { searchQuery: query }, + }); + } + + fetch(`https://lighthouse.lbry.io/search?s=${query}`) + .then(handleFetchResponse) + .then(data => { + const uris = []; + const actions = []; + + data.forEach(result => { + const uri = buildURI({ + claimName: result.name, + claimId: result.claimId, + }); + actions.push(doResolveUri(uri)); + uris.push(uri); + }); + + actions.push({ + type: ACTIONS.SEARCH_SUCCESS, + data: { + query, + uris, + }, + }); + dispatch(batchActions(...actions)); + }) + .catch(() => { + dispatch({ + type: ACTIONS.SEARCH_FAIL, + }); + }); +}; + +export const doUpdateSearchQuery = (query: string, shouldSkipSuggestions: ?boolean) => dispatch => { + dispatch({ + type: ACTIONS.UPDATE_SEARCH_QUERY, + data: { query }, + }); + + // Don't fetch new suggestions if the user just added a space + if (!query.endsWith(' ') || !shouldSkipSuggestions) { + dispatch(getSearchSuggestions(query)); + } +}; + +export const getSearchSuggestions = (value: string) => dispatch => { + const query = value.trim(); + + const isPrefix = () => + query === '@' || query === 'lbry:' || query === 'lbry:/' || query === 'lbry://'; + + if (!query || isPrefix()) { + dispatch({ + type: ACTIONS.UPDATE_SEARCH_SUGGESTIONS, + data: { suggestions: [] }, + }); + return; + } + + let suggestions = []; + try { + // If the user is about to manually add the claim id ignore it until they + // actually add one. This would hardly ever happen, but then the search + // suggestions won't change just from adding a '#' after a uri + let uriQuery = query; + if (uriQuery.endsWith('#')) { + uriQuery = uriQuery.slice(0, -1); + } + + const uri = normalizeURI(uriQuery); + const { claimName, isChannel } = parseURI(uri); + + suggestions.push( + { + value: uri, + shorthand: isChannel ? claimName.slice(1) : claimName, + type: isChannel ? SEARCH_TYPES.CHANNEL : SEARCH_TYPES.FILE, + }, + { + value: claimName, + type: SEARCH_TYPES.SEARCH, + } + ); + + // If it's a valid url, don't fetch any extra search results + return dispatch({ + type: ACTIONS.UPDATE_SEARCH_SUGGESTIONS, + data: { suggestions }, + }); + } catch (e) { + suggestions.push({ + value: query, + type: SEARCH_TYPES.SEARCH, + }); + } + + // Populate the current search query suggestion before fetching results + dispatch({ + type: ACTIONS.UPDATE_SEARCH_SUGGESTIONS, + data: { suggestions }, + }); + + // strip out any basic stuff for more accurate search results + let searchValue = value.replace(/lbry:\/\//g, '').replace(/-/g, ' '); + if (searchValue.includes('#')) { + // This should probably be more robust, but I think it's fine for now + // Remove everything after # to get rid of the claim id + searchValue = searchValue.substring(0, searchValue.indexOf('#')); + } + + return fetch(`https://lighthouse.lbry.io/autocomplete?s=${searchValue}`) + .then(handleFetchResponse) + .then(apiSuggestions => { + const formattedSuggestions = apiSuggestions.slice(0, 6).map(suggestion => { + // This will need to be more robust when the api starts returning lbry uris + const isChannel = suggestion.startsWith('@'); + const suggestionObj = { + value: isChannel ? `lbry://${suggestion}` : suggestion, + shorthand: isChannel ? suggestion.slice(1) : '', + type: isChannel ? 'channel' : 'search', + }; + + return suggestionObj; + }); + + suggestions = suggestions.concat(formattedSuggestions); + dispatch({ + type: ACTIONS.UPDATE_SEARCH_SUGGESTIONS, + data: { suggestions }, + }); + }) + .catch(() => { + // If the fetch fails, do nothing + // Basic search suggestions are already populated at this point + }); +}; diff --git a/src/redux/actions/wallet.js b/src/redux/actions/wallet.js new file mode 100644 index 0000000..728ba2d --- /dev/null +++ b/src/redux/actions/wallet.js @@ -0,0 +1,209 @@ +import * as ACTIONS from 'constants/action_types'; +import Lbry from 'lbry'; +import { doNotify } from 'redux/actions/notifications'; +import { + selectBalance, + selectDraftTransaction, + selectDraftTransactionAmount, +} from 'redux/selectors/wallet'; + +export function doUpdateBalance() { + return (dispatch, getState) => { + const { wallet: { balance: balanceInStore } } = getState(); + Lbry.wallet_balance().then(balance => { + if (balanceInStore !== balance) { + return dispatch({ + type: ACTIONS.UPDATE_BALANCE, + data: { + balance, + }, + }); + } + }); + }; +} + +export function doBalanceSubscribe() { + return dispatch => { + dispatch(doUpdateBalance()); + setInterval(() => dispatch(doUpdateBalance()), 5000); + }; +} + +export function doFetchTransactions() { + return dispatch => { + dispatch({ + type: ACTIONS.FETCH_TRANSACTIONS_STARTED, + }); + + Lbry.transaction_list().then(results => { + dispatch({ + type: ACTIONS.FETCH_TRANSACTIONS_COMPLETED, + data: { + transactions: results, + }, + }); + }); + }; +} + +export function doFetchBlock(height) { + return dispatch => { + Lbry.block_show({ height }).then(block => { + dispatch({ + type: ACTIONS.FETCH_BLOCK_SUCCESS, + data: { block }, + }); + }); + }; +} + +export function doGetNewAddress() { + return dispatch => { + dispatch({ + type: ACTIONS.GET_NEW_ADDRESS_STARTED, + }); + + // Removed localStorage use, since address is expected to be stored in redux store + Lbry.wallet_new_address().then(address => { + dispatch({ + type: ACTIONS.GET_NEW_ADDRESS_COMPLETED, + data: { address }, + }); + }); + }; +} + +export function doCheckAddressIsMine(address) { + return dispatch => { + dispatch({ + type: ACTIONS.CHECK_ADDRESS_IS_MINE_STARTED, + }); + + Lbry.wallet_is_address_mine({ address }).then(isMine => { + if (!isMine) dispatch(doGetNewAddress()); + + dispatch({ + type: ACTIONS.CHECK_ADDRESS_IS_MINE_COMPLETED, + }); + }); + }; +} + +export function doSendDraftTransaction() { + return (dispatch, getState) => { + const state = getState(); + const draftTx = selectDraftTransaction(state); + const balance = selectBalance(state); + const amount = selectDraftTransactionAmount(state); + + if (balance - amount <= 0) { + dispatch( + doNotify({ + title: 'Insufficient credits', + message: 'Insufficient credits', + type: 'error', + displayType: ['modal', 'toast'], + }) + ); + return; + } + + dispatch({ + type: ACTIONS.SEND_TRANSACTION_STARTED, + }); + + const successCallback = results => { + if (results === true) { + dispatch({ + type: ACTIONS.SEND_TRANSACTION_COMPLETED, + }); + dispatch( + doNotify({ + title: 'Credits sent', + message: `You sent ${amount} LBC`, + type: 'error', + displayType: ['snackbar', 'toast'], + linkText: 'History', + linkTarget: '/wallet', + }) + ); + } else { + dispatch({ + type: ACTIONS.SEND_TRANSACTION_FAILED, + data: { error: results }, + }); + dispatch( + doNotify({ + title: 'Transaction failed', + message: 'Transaction failed', + type: 'error', + displayType: ['modal', 'toast'], + }) + ); + } + }; + + const errorCallback = error => { + dispatch({ + type: ACTIONS.SEND_TRANSACTION_FAILED, + data: { error: error.message }, + }); + dispatch( + doNotify({ + title: 'Transaction failed', + message: 'Transaction failed', + type: 'error', + displayType: ['modal', 'toast'], + }) + ); + }; + + Lbry.wallet_send({ + amount: draftTx.amount, + address: draftTx.address, + }).then(successCallback, errorCallback); + }; +} + +export function doSetDraftTransactionAmount(amount) { + return { + type: ACTIONS.SET_DRAFT_TRANSACTION_AMOUNT, + data: { amount }, + }; +} + +export function doSetDraftTransactionAddress(address) { + return { + type: ACTIONS.SET_DRAFT_TRANSACTION_ADDRESS, + data: { address }, + }; +} + +export function doSendSupport(amount, claimId, uri, successCallback, errorCallback) { + return (dispatch, getState) => { + const state = getState(); + const balance = selectBalance(state); + + if (balance - amount <= 0) { + dispatch( + doNotify({ + title: 'Insufficient credits', + message: 'Insufficient credits', + type: 'error', + displayType: ['modal', 'toast'], + }) + ); + return; + } + + dispatch({ + type: ACTIONS.SUPPORT_TRANSACTION_STARTED, + }); + + Lbry.wallet_send({ + claim_id: claimId, + amount, + }).then(successCallback, errorCallback); + }; +} diff --git a/src/redux/reducers/claims.js b/src/redux/reducers/claims.js new file mode 100644 index 0000000..e0df41d --- /dev/null +++ b/src/redux/reducers/claims.js @@ -0,0 +1,246 @@ +import * as ACTIONS from 'constants/action_types'; + +const reducers = {}; + +const defaultState = { + rewardedContentClaimIds: [], + channelClaimCounts: {}, +}; + +reducers[ACTIONS.RESOLVE_URIS_COMPLETED] = (state, action) => { + const { resolveInfo } = action.data; + const byUri = Object.assign({}, state.claimsByUri); + const byId = Object.assign({}, state.byId); + const channelClaimCounts = Object.assign({}, state.channelClaimCounts); + + Object.entries(resolveInfo).forEach(([uri, { certificate, claimsInChannel }]) => { + if (certificate && !Number.isNaN(claimsInChannel)) { + channelClaimCounts[uri] = claimsInChannel; + } + }); + + Object.entries(resolveInfo).forEach(([uri, { certificate, claim }]) => { + if (claim) { + byId[claim.claim_id] = claim; + byUri[uri] = claim.claim_id; + } else if (claim === undefined && certificate !== undefined) { + byId[certificate.claim_id] = certificate; + // Don't point URI at the channel certificate unless it actually is + // a channel URI. This is brittle. + if (!uri.split(certificate.name)[1].match(/\//)) { + byUri[uri] = certificate.claim_id; + } else { + byUri[uri] = null; + } + } else { + byUri[uri] = null; + } + }); + + return Object.assign({}, state, { + byId, + claimsByUri: byUri, + channelClaimCounts, + resolvingUris: (state.resolvingUris || []).filter(uri => !resolveInfo[uri]), + }); +}; + +reducers[ACTIONS.FETCH_CLAIM_LIST_MINE_STARTED] = state => + Object.assign({}, state, { + isFetchingClaimListMine: true, + }); + +reducers[ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED] = (state, action) => { + const { claims } = action.data; + const byId = Object.assign({}, state.byId); + const pendingById = Object.assign({}, state.pendingById); + + claims.filter(claim => claim.category && claim.category.match(/claim/)).forEach(claim => { + byId[claim.claim_id] = claim; + + const pending = Object.values(pendingById).find( + pendingClaim => + pendingClaim.name === claim.name && pendingClaim.channel_name === claim.channel_name + ); + + if (pending) { + delete pendingById[pending.claim_id]; + } + }); + + // Remove old timed out pending publishes + Object.values(pendingById) + .filter(pendingClaim => Date.now() - pendingClaim.time >= 20 * 60 * 1000) + .forEach(pendingClaim => { + delete pendingById[pendingClaim.claim_id]; + }); + + return Object.assign({}, state, { + isFetchingClaimListMine: false, + myClaims: claims, + byId, + pendingById, + }); +}; + +reducers[ACTIONS.FETCH_CHANNEL_LIST_MINE_STARTED] = state => + Object.assign({}, state, { fetchingMyChannels: true }); + +reducers[ACTIONS.FETCH_CHANNEL_LIST_MINE_COMPLETED] = (state, action) => { + const { claims } = action.data; + const myChannelClaims = new Set(state.myChannelClaims); + const byId = Object.assign({}, state.byId); + + claims.forEach(claim => { + myChannelClaims.add(claim.claim_id); + byId[claims.claim_id] = claim; + }); + + return Object.assign({}, state, { + byId, + fetchingMyChannels: false, + myChannelClaims, + }); +}; + +reducers[ACTIONS.FETCH_CHANNEL_CLAIMS_STARTED] = (state, action) => { + const { uri, page } = action.data; + const fetchingChannelClaims = Object.assign({}, state.fetchingChannelClaims); + + fetchingChannelClaims[uri] = page; + + return Object.assign({}, state, { + fetchingChannelClaims, + }); +}; + +reducers[ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED] = (state, action) => { + const { uri, claims, page } = action.data; + + const claimsByChannel = Object.assign({}, state.claimsByChannel); + const byChannel = Object.assign({}, claimsByChannel[uri]); + const allClaimIds = new Set(byChannel.all); + const currentPageClaimIds = []; + const byId = Object.assign({}, state.byId); + const fetchingChannelClaims = Object.assign({}, state.fetchingChannelClaims); + + if (claims !== undefined) { + claims.forEach(claim => { + allClaimIds.add(claim.claim_id); + currentPageClaimIds.push(claim.claim_id); + byId[claim.claim_id] = claim; + }); + } + + byChannel.all = allClaimIds; + byChannel[page] = currentPageClaimIds; + claimsByChannel[uri] = byChannel; + delete fetchingChannelClaims[uri]; + + return Object.assign({}, state, { + claimsByChannel, + byId, + fetchingChannelClaims, + }); +}; + +reducers[ACTIONS.ABANDON_CLAIM_STARTED] = (state, action) => { + const { claimId } = action.data; + const abandoningById = Object.assign({}, state.abandoningById); + + abandoningById[claimId] = true; + + return Object.assign({}, state, { + abandoningById, + }); +}; + +reducers[ACTIONS.ABANDON_CLAIM_SUCCEEDED] = (state, action) => { + const { claimId } = action.data; + const byId = Object.assign({}, state.byId); + const claimsByUri = Object.assign({}, state.claimsByUri); + + Object.keys(claimsByUri).forEach(uri => { + if (claimsByUri[uri] === claimId) { + delete claimsByUri[uri]; + } + }); + + delete byId[claimId]; + + return Object.assign({}, state, { + byId, + claimsByUri, + }); +}; + +reducers[ACTIONS.CREATE_CHANNEL_COMPLETED] = (state, action) => { + const { channelClaim } = action.data; + const byId = Object.assign({}, state.byId); + const myChannelClaims = new Set(state.myChannelClaims); + + byId[channelClaim.claim_id] = channelClaim; + myChannelClaims.add(channelClaim.claim_id); + + return Object.assign({}, state, { + byId, + myChannelClaims, + }); +}; + +reducers[ACTIONS.FETCH_FEATURED_CONTENT_STARTED] = state => + Object.assign({}, state, { + fetchingFeaturedContent: true, + }); + +reducers[ACTIONS.FETCH_FEATURED_CONTENT_COMPLETED] = (state, action) => { + const { uris, success } = action.data; + + return Object.assign({}, state, { + fetchingFeaturedContent: false, + fetchingFeaturedContentFailed: !success, + featuredUris: uris, + }); +}; + +reducers[ACTIONS.FETCH_REWARD_CONTENT_COMPLETED] = (state, action) => { + const { claimIds } = action.data; + + return Object.assign({}, state, { + rewardedContentClaimIds: claimIds, + }); +}; + +reducers[ACTIONS.RESOLVE_URIS_STARTED] = (state, action) => { + const { uris } = action.data; + + const oldResolving = state.resolvingUris || []; + const newResolving = Object.assign([], oldResolving); + + uris.forEach(uri => { + if (!newResolving.includes(uri)) { + newResolving.push(uri); + } + }); + + return Object.assign({}, state, { + resolvingUris: newResolving, + }); +}; + +reducers[ACTIONS.FETCH_CHANNEL_CLAIM_COUNT_COMPLETED] = (state, action) => { + const channelClaimCounts = Object.assign({}, state.channelClaimCounts); + const { uri, totalClaims } = action.data; + + channelClaimCounts[uri] = totalClaims; + + return Object.assign({}, state, { + channelClaimCounts, + }); +}; + +export function claimsReducer(state = defaultState, action) { + const handler = reducers[action.type]; + if (handler) return handler(state, action); + return state; +} diff --git a/src/redux/reducers/cost_info.js b/src/redux/reducers/cost_info.js index 4137bb8..5d738ce 100644 --- a/src/redux/reducers/cost_info.js +++ b/src/redux/reducers/cost_info.js @@ -27,7 +27,7 @@ reducers[ACTIONS.FETCH_COST_INFO_COMPLETED] = (state, action) => { }); }; -export default function reducer(state = defaultState, action) { +export function costInfoReducer(state = defaultState, action) { const handler = reducers[action.type]; if (handler) return handler(state, action); return state; diff --git a/src/redux/reducers/file_info.js b/src/redux/reducers/file_info.js new file mode 100644 index 0000000..c26734c --- /dev/null +++ b/src/redux/reducers/file_info.js @@ -0,0 +1,156 @@ +import * as ACTIONS from 'constants/action_types'; + +const reducers = {}; +const defaultState = {}; + +reducers[ACTIONS.FILE_LIST_STARTED] = state => + Object.assign({}, state, { + isFetchingFileList: true, + }); + +reducers[ACTIONS.FILE_LIST_SUCCEEDED] = (state, action) => { + const { fileInfos } = action.data; + const newByOutpoint = Object.assign({}, state.byOutpoint); + const pendingByOutpoint = Object.assign({}, state.pendingByOutpoint); + + fileInfos.forEach(fileInfo => { + const { outpoint } = fileInfo; + + if (outpoint) newByOutpoint[fileInfo.outpoint] = fileInfo; + }); + + return Object.assign({}, state, { + isFetchingFileList: false, + byOutpoint: newByOutpoint, + pendingByOutpoint, + }); +}; + +reducers[ACTIONS.FETCH_FILE_INFO_STARTED] = (state, action) => { + const { outpoint } = action.data; + const newFetching = Object.assign({}, state.fetching); + + newFetching[outpoint] = true; + + return Object.assign({}, state, { + fetching: newFetching, + }); +}; + +reducers[ACTIONS.FETCH_FILE_INFO_COMPLETED] = (state, action) => { + const { fileInfo, outpoint } = action.data; + + const newByOutpoint = Object.assign({}, state.byOutpoint); + const newFetching = Object.assign({}, state.fetching); + + newByOutpoint[outpoint] = fileInfo; + delete newFetching[outpoint]; + + return Object.assign({}, state, { + byOutpoint: newByOutpoint, + fetching: newFetching, + }); +}; + +reducers[ACTIONS.DOWNLOADING_STARTED] = (state, action) => { + const { uri, outpoint, fileInfo } = action.data; + + const newByOutpoint = Object.assign({}, state.byOutpoint); + const newDownloading = Object.assign({}, state.downloadingByOutpoint); + const newLoading = Object.assign({}, state.urisLoading); + + newDownloading[outpoint] = true; + newByOutpoint[outpoint] = fileInfo; + delete newLoading[uri]; + + return Object.assign({}, state, { + downloadingByOutpoint: newDownloading, + urisLoading: newLoading, + byOutpoint: newByOutpoint, + }); +}; + +reducers[ACTIONS.DOWNLOADING_PROGRESSED] = (state, action) => { + const { outpoint, fileInfo } = action.data; + + const newByOutpoint = Object.assign({}, state.byOutpoint); + const newDownloading = Object.assign({}, state.downloadingByOutpoint); + + newByOutpoint[outpoint] = fileInfo; + newDownloading[outpoint] = true; + + return Object.assign({}, state, { + byOutpoint: newByOutpoint, + downloadingByOutpoint: newDownloading, + }); +}; + +reducers[ACTIONS.DOWNLOADING_COMPLETED] = (state, action) => { + const { outpoint, fileInfo } = action.data; + + const newByOutpoint = Object.assign({}, state.byOutpoint); + const newDownloading = Object.assign({}, state.downloadingByOutpoint); + + newByOutpoint[outpoint] = fileInfo; + delete newDownloading[outpoint]; + + return Object.assign({}, state, { + byOutpoint: newByOutpoint, + downloadingByOutpoint: newDownloading, + }); +}; + +reducers[ACTIONS.FILE_DELETE] = (state, action) => { + const { outpoint } = action.data; + + const newByOutpoint = Object.assign({}, state.byOutpoint); + const downloadingByOutpoint = Object.assign({}, state.downloadingByOutpoint); + + delete newByOutpoint[outpoint]; + delete downloadingByOutpoint[outpoint]; + + return Object.assign({}, state, { + byOutpoint: newByOutpoint, + downloadingByOutpoint, + }); +}; + +reducers[ACTIONS.LOADING_VIDEO_STARTED] = (state, action) => { + const { uri } = action.data; + + const newLoading = Object.assign({}, state.urisLoading); + + newLoading[uri] = true; + + return Object.assign({}, state, { + urisLoading: newLoading, + }); +}; + +reducers[ACTIONS.LOADING_VIDEO_FAILED] = (state, action) => { + const { uri } = action.data; + + const newLoading = Object.assign({}, state.urisLoading); + + delete newLoading[uri]; + + return Object.assign({}, state, { + urisLoading: newLoading, + }); +}; + +reducers[ACTIONS.FETCH_DATE] = (state, action) => { + const { time } = action.data; + if (time) { + return Object.assign({}, state, { + publishedDate: time, + }); + } + return null; +}; + +export function fileInfoReducer(state = defaultState, action) { + const handler = reducers[action.type]; + if (handler) return handler(state, action); + return state; +} diff --git a/src/redux/reducers/notifications.js b/src/redux/reducers/notifications.js new file mode 100644 index 0000000..a066202 --- /dev/null +++ b/src/redux/reducers/notifications.js @@ -0,0 +1,39 @@ +import * as ACTIONS from 'constants/action_types'; + +const reducers = {}; + +const defaultState = { + // First-in, first-out + queue: [], +}; + +reducers[ACTIONS.NOTIFICATION_CREATED] = (state, action) => { + const { title, message, type, errorCode, displayType } = action.data; + const queue = Object.assign([], state.queue); + queue.push({ + title, + message, + type, + errorCode, + displayType, + }); + + return Object.assign({}, state, { + queue, + }); +}; + +reducers[ACTIONS.NOTIFICATION_DISPLAYED] = state => { + const queue = Object.assign([], state.queue); + queue.shift(); + + return Object.assign({}, state, { + queue, + }); +}; + +export function notificationsReducer(state = defaultState, action) { + const handler = reducers[action.type]; + if (handler) return handler(state, action); + return state; +} diff --git a/src/redux/reducers/search.js b/src/redux/reducers/search.js new file mode 100644 index 0000000..908cf28 --- /dev/null +++ b/src/redux/reducers/search.js @@ -0,0 +1,103 @@ +// @flow +import * as ACTIONS from 'constants/action_types'; +import { handleActions } from 'util/redux-utils'; + +type SearchSuccess = { + type: ACTIONS.SEARCH_SUCCESS, + data: { + query: string, + uris: Array, + }, +}; + +type UpdateSearchQuery = { + type: ACTIONS.UPDATE_SEARCH_QUERY, + data: { + query: string, + }, +}; + +type SearchSuggestion = { + value: string, + shorthand: string, + type: string, +}; + +type UpdateSearchSuggestions = { + type: ACTIONS.UPDATE_SEARCH_SUGGESTIONS, + data: { + suggestions: Array, + }, +}; + +type SearchState = { + isActive: boolean, + searchQuery: string, + suggestions: Array, + urisByQuery: {}, +}; + +const defaultState = { + isActive: false, + searchQuery: '', // needs to be an empty string for input focusing + suggestions: [], + urisByQuery: {}, +}; + +export const searchReducer = handleActions( + { + [ACTIONS.SEARCH_START]: (state: SearchState): SearchState => ({ + ...state, + searching: true, + }), + [ACTIONS.SEARCH_SUCCESS]: (state: SearchState, action: SearchSuccess): SearchState => { + const { query, uris } = action.data; + + return { + ...state, + searching: false, + urisByQuery: Object.assign({}, state.urisByQuery, { [query]: uris }), + }; + }, + + [ACTIONS.SEARCH_FAIL]: (state: SearchState): SearchState => ({ + ...state, + searching: false, + }), + + [ACTIONS.UPDATE_SEARCH_QUERY]: ( + state: SearchState, + action: UpdateSearchQuery + ): SearchState => ({ + ...state, + searchQuery: action.data.query, + isActive: true, + }), + + [ACTIONS.UPDATE_SEARCH_SUGGESTIONS]: ( + state: SearchState, + action: UpdateSearchSuggestions + ): SearchState => ({ + ...state, + suggestions: action.data.suggestions, + }), + + // clear the searchQuery on back/forward + // it may be populated by the page title for search/file pages + // if going home, it should be blank + [ACTIONS.HISTORY_NAVIGATE]: (state: SearchState): SearchState => ({ + ...state, + searchQuery: '', + suggestions: [], + isActive: false, + }), + // sets isActive to false so the uri will be populated correctly if the + // user is on a file page. The search query will still be present on any + // other page + [ACTIONS.CLOSE_MODAL]: (state: SearchState): SearchState => ({ + ...state, + isActive: false, + }), + }, + defaultState +); diff --git a/src/redux/reducers/wallet.js b/src/redux/reducers/wallet.js new file mode 100644 index 0000000..c57ecc7 --- /dev/null +++ b/src/redux/reducers/wallet.js @@ -0,0 +1,146 @@ +import * as ACTIONS from 'constants/action_types'; + +const reducers = {}; +const buildDraftTransaction = () => ({ + amount: undefined, + address: undefined, +}); + +const defaultState = { + balance: undefined, + blocks: {}, + transactions: {}, + fetchingTransactions: false, + gettingNewAddress: false, + draftTransaction: buildDraftTransaction(), + sendingSupport: false, +}; + +reducers[ACTIONS.FETCH_TRANSACTIONS_STARTED] = state => + Object.assign({}, state, { + fetchingTransactions: true, + }); + +reducers[ACTIONS.FETCH_TRANSACTIONS_COMPLETED] = (state, action) => { + const byId = Object.assign({}, state.transactions); + + const { transactions } = action.data; + + transactions.forEach(transaction => { + byId[transaction.txid] = transaction; + }); + + return Object.assign({}, state, { + transactions: byId, + fetchingTransactions: false, + }); +}; + +reducers[ACTIONS.GET_NEW_ADDRESS_STARTED] = state => + Object.assign({}, state, { + gettingNewAddress: true, + }); + +reducers[ACTIONS.GET_NEW_ADDRESS_COMPLETED] = (state, action) => { + const { address } = action.data; + + // Say no to localStorage! + return Object.assign({}, state, { + gettingNewAddress: false, + receiveAddress: address, + }); +}; + +reducers[ACTIONS.UPDATE_BALANCE] = (state, action) => + Object.assign({}, state, { + balance: action.data.balance, + }); + +reducers[ACTIONS.CHECK_ADDRESS_IS_MINE_STARTED] = state => + Object.assign({}, state, { + checkingAddressOwnership: true, + }); + +reducers[ACTIONS.CHECK_ADDRESS_IS_MINE_COMPLETED] = state => + Object.assign({}, state, { + checkingAddressOwnership: false, + }); + +reducers[ACTIONS.SET_DRAFT_TRANSACTION_AMOUNT] = (state, action) => { + const oldDraft = state.draftTransaction; + const newDraft = Object.assign({}, oldDraft, { + amount: parseFloat(action.data.amount), + }); + + return Object.assign({}, state, { + draftTransaction: newDraft, + }); +}; + +reducers[ACTIONS.SET_DRAFT_TRANSACTION_ADDRESS] = (state, action) => { + const oldDraft = state.draftTransaction; + const newDraft = Object.assign({}, oldDraft, { + address: action.data.address, + }); + + return Object.assign({}, state, { + draftTransaction: newDraft, + }); +}; + +reducers[ACTIONS.SEND_TRANSACTION_STARTED] = state => { + const newDraftTransaction = Object.assign({}, state.draftTransaction, { + sending: true, + }); + + return Object.assign({}, state, { + draftTransaction: newDraftTransaction, + }); +}; + +reducers[ACTIONS.SEND_TRANSACTION_COMPLETED] = state => + Object.assign({}, state, { + draftTransaction: buildDraftTransaction(), + }); + +reducers[ACTIONS.SEND_TRANSACTION_FAILED] = (state, action) => { + const newDraftTransaction = Object.assign({}, state.draftTransaction, { + sending: false, + error: action.data.error, + }); + + return Object.assign({}, state, { + draftTransaction: newDraftTransaction, + }); +}; + +reducers[ACTIONS.SUPPORT_TRANSACTION_STARTED] = state => + Object.assign({}, state, { + sendingSupport: true, + }); + +reducers[ACTIONS.SUPPORT_TRANSACTION_COMPLETED] = state => + Object.assign({}, state, { + sendingSupport: false, + }); + +reducers[ACTIONS.SUPPORT_TRANSACTION_FAILED] = (state, action) => + Object.assign({}, state, { + error: action.data.error, + sendingSupport: false, + }); + +reducers[ACTIONS.FETCH_BLOCK_SUCCESS] = (state, action) => { + const { block, block: { height } } = action.data; + const blocks = Object.assign({}, state.blocks); + + blocks[height] = block; + + return Object.assign({}, state, { blocks }); +}; + +export function walletReducer(state = defaultState, action) { + const handler = reducers[action.type]; + if (handler) return handler(state, action); + return state; +} diff --git a/src/redux/selectors/claims.js b/src/redux/selectors/claims.js index 5610880..489eabb 100644 --- a/src/redux/selectors/claims.js +++ b/src/redux/selectors/claims.js @@ -1,3 +1,5 @@ +import { normalizeURI } from 'lbryURI'; +import { makeSelectCurrentParam } from 'redux/selectors/navigation'; import { createSelector } from 'reselect'; const selectState = state => state.claims || {}; @@ -22,4 +24,186 @@ export const selectClaimsByUri = createSelector(selectState, selectClaimsById, ( }); return claims; -}); \ No newline at end of file +}); + +export const selectAllClaimsByChannel = createSelector( + selectState, + state => state.claimsByChannel || {} +); + +export const makeSelectClaimForUri = uri => + createSelector(selectClaimsByUri, claims => claims && claims[normalizeURI(uri)]); + +export const selectMyClaimsRaw = createSelector(selectState, state => state.myClaims); + +export const selectAbandoningIds = createSelector(selectState, state => + Object.keys(state.abandoningById || {}) +); + +export const selectMyActiveClaims = createSelector( + selectMyClaimsRaw, + selectAbandoningIds, + (claims, abandoningIds) => + new Set( + claims && + claims + .map(claim => claim.claim_id) + .filter(claimId => Object.keys(abandoningIds).indexOf(claimId) === -1) + ) +); + +export const makeSelectClaimIsMine = rawUri => { + const uri = normalizeURI(rawUri); + return createSelector( + selectClaimsByUri, + selectMyActiveClaims, + (claims, myClaims) => + claims && claims[uri] && claims[uri].claim_id && myClaims.has(claims[uri].claim_id) + ); +}; + +export const selectAllFetchingChannelClaims = createSelector( + selectState, + state => state.fetchingChannelClaims || {} +); + +export const makeSelectFetchingChannelClaims = uri => + createSelector(selectAllFetchingChannelClaims, fetching => fetching && fetching[uri]); + +export const makeSelectClaimsInChannelForCurrentPage = uri => { + const pageSelector = makeSelectCurrentParam('page'); + + return createSelector( + selectClaimsById, + selectAllClaimsByChannel, + pageSelector, + (byId, allClaims, page) => { + const byChannel = allClaims[uri] || {}; + const claimIds = byChannel[page || 1]; + + if (!claimIds) return claimIds; + + return claimIds.map(claimId => byId[claimId]); + } + ); +}; + +export const makeSelectMetadataForUri = uri => + createSelector(makeSelectClaimForUri(uri), claim => { + const metadata = claim && claim.value && claim.value.stream && claim.value.stream.metadata; + + return metadata || (claim === undefined ? undefined : null); + }); + +export const makeSelectTitleForUri = uri => + createSelector(makeSelectMetadataForUri(uri), metadata => metadata && metadata.title); + +export const makeSelectContentTypeForUri = uri => + createSelector(makeSelectClaimForUri(uri), claim => { + const source = claim && claim.value && claim.value.stream && claim.value.stream.source; + return source ? source.contentType : undefined; + }); + +export const selectIsFetchingClaimListMine = createSelector( + selectState, + state => state.isFetchingClaimListMine +); + +export const selectPendingClaims = createSelector(selectState, state => + Object.values(state.pendingById || {}) +); + +export const selectMyClaims = createSelector( + selectMyActiveClaims, + selectClaimsById, + selectAbandoningIds, + selectPendingClaims, + (myClaimIds, byId, abandoningIds, pendingClaims) => { + const claims = []; + + myClaimIds.forEach(id => { + const claim = byId[id]; + + if (claim && abandoningIds.indexOf(id) === -1) claims.push(claim); + }); + + return [...claims, ...pendingClaims]; + } +); + +export const selectMyClaimsWithoutChannels = createSelector(selectMyClaims, myClaims => + myClaims.filter(claim => !claim.name.match(/^@/)) +); + +export const selectAllMyClaimsByOutpoint = createSelector( + selectMyClaimsRaw, + claims => + new Set(claims && claims.length ? claims.map(claim => `${claim.txid}:${claim.nout}`) : null) +); + +export const selectMyClaimsOutpoints = createSelector(selectMyClaims, myClaims => { + const outpoints = []; + + myClaims.forEach(claim => outpoints.push(`${claim.txid}:${claim.nout}`)); + + return outpoints; +}); + +export const selectFetchingMyChannels = createSelector( + selectState, + state => state.fetchingMyChannels +); + +export const selectMyChannelClaims = createSelector( + selectState, + selectClaimsById, + (state, byId) => { + const ids = state.myChannelClaims || []; + const claims = []; + + ids.forEach(id => { + if (byId[id]) { + // I'm not sure why this check is necessary, but it ought to be a quick fix for https://github.com/lbryio/lbry-app/issues/544 + claims.push(byId[id]); + } + }); + + return claims; + } +); + +export const selectResolvingUris = createSelector(selectState, state => state.resolvingUris || []); + +export const makeSelectIsUriResolving = uri => + createSelector( + selectResolvingUris, + resolvingUris => resolvingUris && resolvingUris.indexOf(uri) !== -1 + ); + +export const selectFeaturedUris = createSelector(selectState, state => state.featuredUris); + +export const selectFetchingFeaturedUris = createSelector( + selectState, + state => state.fetchingFeaturedContent +); + +export const selectPlayingUri = createSelector(selectState, state => state.playingUri); + +export const selectChannelClaimCounts = createSelector( + selectState, + state => state.channelClaimCounts || {} +); + +export const makeSelectTotalItemsForChannel = uri => + createSelector(selectChannelClaimCounts, byUri => byUri && byUri[uri]); + +export const makeSelectTotalPagesForChannel = uri => + createSelector( + selectChannelClaimCounts, + byUri => byUri && byUri[uri] && Math.ceil(byUri[uri] / 10) + ); + +export const selectRewardContentClaimIds = createSelector( + selectState, + state => state.rewardedContentClaimIds +); diff --git a/src/redux/selectors/cost_info.js b/src/redux/selectors/cost_info.js index bcfb5a6..04d5b09 100644 --- a/src/redux/selectors/cost_info.js +++ b/src/redux/selectors/cost_info.js @@ -1,5 +1,5 @@ import { createSelector } from 'reselect'; -//import { selectCurrentParams } from 'redux/selectors/navigation'; +import { selectCurrentParams } from 'redux/selectors/navigation'; export const selectState = state => state.costInfo || {}; @@ -10,7 +10,7 @@ export const makeSelectCostInfoForUri = uri => export const selectCostForCurrentPageUri = createSelector( selectAllCostInfoByUri, - {}/*selectCurrentParams*/, + selectCurrentParams, (costInfo, params) => (params.uri && costInfo[params.uri] ? costInfo[params.uri].cost : undefined) ); diff --git a/src/redux/selectors/file_info.js b/src/redux/selectors/file_info.js new file mode 100644 index 0000000..b971328 --- /dev/null +++ b/src/redux/selectors/file_info.js @@ -0,0 +1,197 @@ +import { + selectClaimsByUri, + selectIsFetchingClaimListMine, + selectMyClaims, + selectClaimsById, +} from 'redux/selectors/claims'; +import { createSelector } from 'reselect'; +import { buildURI } from 'lbryURI'; + +export const selectState = state => state.fileInfo || {}; + +export const selectFileInfosByOutpoint = createSelector( + selectState, + state => state.byOutpoint || {} +); + +export const selectIsFetchingFileList = createSelector( + selectState, + state => state.isFetchingFileList +); + +export const selectIsFetchingFileListDownloadedOrPublished = createSelector( + selectIsFetchingFileList, + selectIsFetchingClaimListMine, + (isFetchingFileList, isFetchingClaimListMine) => isFetchingFileList || isFetchingClaimListMine +); + +export const makeSelectFileInfoForUri = uri => + createSelector(selectClaimsByUri, selectFileInfosByOutpoint, (claims, byOutpoint) => { + const claim = claims[uri]; + const outpoint = claim ? `${claim.txid}:${claim.nout}` : undefined; + return outpoint ? byOutpoint[outpoint] : undefined; + }); + +export const selectDownloadingByOutpoint = createSelector( + selectState, + state => state.downloadingByOutpoint || {} +); + +export const makeSelectDownloadingForUri = uri => + createSelector( + selectDownloadingByOutpoint, + makeSelectFileInfoForUri(uri), + (byOutpoint, fileInfo) => { + if (!fileInfo) return false; + return byOutpoint[fileInfo.outpoint]; + } + ); + +export const selectUrisLoading = createSelector(selectState, state => state.urisLoading || {}); + +export const makeSelectLoadingForUri = uri => + createSelector(selectUrisLoading, byUri => byUri && byUri[uri]); + +export const selectFileInfosDownloaded = createSelector( + selectFileInfosByOutpoint, + selectMyClaims, + (byOutpoint, myClaims) => + Object.values(byOutpoint).filter(fileInfo => { + const myClaimIds = myClaims.map(claim => claim.claim_id); + + return ( + fileInfo && + myClaimIds.indexOf(fileInfo.claim_id) === -1 && + (fileInfo.completed || fileInfo.written_bytes) + ); + }) +); + +// export const selectFileInfoForUri = (state, props) => { +// const claims = selectClaimsByUri(state), +// claim = claims[props.uri], +// fileInfos = selectAllFileInfos(state), +// outpoint = claim ? `${claim.txid}:${claim.nout}` : undefined; + +// return outpoint && fileInfos ? fileInfos[outpoint] : undefined; +// }; + +export const selectDownloadingFileInfos = createSelector( + selectDownloadingByOutpoint, + selectFileInfosByOutpoint, + (downloadingByOutpoint, fileInfosByOutpoint) => { + const outpoints = Object.keys(downloadingByOutpoint); + const fileInfos = []; + + outpoints.forEach(outpoint => { + const fileInfo = fileInfosByOutpoint[outpoint]; + + if (fileInfo) fileInfos.push(fileInfo); + }); + + return fileInfos; + } +); + +export const selectTotalDownloadProgress = createSelector(selectDownloadingFileInfos, fileInfos => { + const progress = []; + + fileInfos.forEach(fileInfo => { + progress.push(fileInfo.written_bytes / fileInfo.total_bytes * 100); + }); + + const totalProgress = progress.reduce((a, b) => a + b, 0); + + if (fileInfos.length > 0) return totalProgress / fileInfos.length / 100.0; + return -1; +}); + +export const selectSearchDownloadUris = query => + createSelector(selectFileInfosDownloaded, selectClaimsById, (fileInfos, claimsById) => { + if (!query || !fileInfos.length) { + return null; + } + + const queryParts = query.toLowerCase().split(' '); + const searchQueryDictionary = {}; + queryParts.forEach(subQuery => { + searchQueryDictionary[subQuery] = subQuery; + }); + + const arrayContainsQueryPart = array => { + for (let i = 0; i < array.length; i += 1) { + const subQuery = array[i]; + if (searchQueryDictionary[subQuery]) { + return true; + } + } + return false; + }; + + const downloadResultsFromQuery = []; + fileInfos.forEach(fileInfo => { + const { channel_name: channelName, claim_name: claimName, metadata } = fileInfo; + const { author, description, title } = metadata; + + if (channelName) { + const lowerCaseChannel = channelName.toLowerCase(); + const strippedOutChannelName = lowerCaseChannel.slice(1); // trim off the @ + if (searchQueryDictionary[channelName] || searchQueryDictionary[strippedOutChannelName]) { + downloadResultsFromQuery.push(fileInfo); + return; + } + } + + const nameParts = claimName.toLowerCase().split('-'); + if (arrayContainsQueryPart(nameParts)) { + downloadResultsFromQuery.push(fileInfo); + return; + } + + const titleParts = title.toLowerCase().split(' '); + if (arrayContainsQueryPart(titleParts)) { + downloadResultsFromQuery.push(fileInfo); + return; + } + + if (author) { + const authorParts = author.toLowerCase().split(' '); + if (arrayContainsQueryPart(authorParts)) { + downloadResultsFromQuery.push(fileInfo); + return; + } + } + + if (description) { + const descriptionParts = description.toLowerCase().split(' '); + if (arrayContainsQueryPart(descriptionParts)) { + downloadResultsFromQuery.push(fileInfo); + } + } + }); + + return downloadResultsFromQuery.length + ? downloadResultsFromQuery.map(fileInfo => { + const { channel_name: channelName, claim_id: claimId, claim_name: claimName } = fileInfo; + + const uriParams = {}; + + if (channelName) { + const claim = claimsById[claimId]; + if (claim.value) { + uriParams.claimId = claim.value.publisherSignature.certificateId; + } else { + uriParams.claimId = claimId; + } + uriParams.channelName = channelName; + uriParams.contentName = claimName; + } else { + uriParams.claimId = claimId; + uriParams.claimName = claimName; + } + + const uri = buildURI(uriParams); + return uri; + }) + : null; + }); diff --git a/src/redux/selectors/navigation.js b/src/redux/selectors/navigation.js new file mode 100644 index 0000000..f4acc30 --- /dev/null +++ b/src/redux/selectors/navigation.js @@ -0,0 +1,202 @@ +import { createSelector } from 'reselect'; +import { parseQueryParams } from 'util/query_params'; + +export const selectState = state => state.navigation || {}; + +export const selectCurrentPath = createSelector(selectState, state => state.currentPath); + +export const computePageFromPath = path => path.replace(/^\//, '').split('?')[0]; + +export const selectCurrentPage = createSelector(selectCurrentPath, path => + computePageFromPath(path) +); + +export const selectCurrentParams = createSelector(selectCurrentPath, path => { + if (path === undefined) return {}; + if (!path.match(/\?/)) return {}; + + return parseQueryParams(path.split('?')[1]); +}); + +export const makeSelectCurrentParam = param => + createSelector(selectCurrentParams, params => (params ? params[param] : undefined)); + +export const selectPathAfterAuth = createSelector(selectState, state => state.pathAfterAuth); + +export const selectIsBackDisabled = createSelector(selectState, state => state.index === 0); + +export const selectIsForwardDisabled = createSelector( + selectState, + state => state.index === state.stack.length - 1 +); + +export const selectIsHome = createSelector(selectCurrentPage, page => page === 'discover'); + +export const selectHistoryIndex = createSelector(selectState, state => state.index); + +export const selectHistoryStack = createSelector(selectState, state => state.stack); + +// returns current page attributes (scrollY, path) +export const selectActiveHistoryEntry = createSelector( + selectState, + state => state.stack[state.index] +); + +export const selectPageTitle = createSelector(selectCurrentPage, page => { + switch (page) { + default: + return ''; + } +}); + +export const selectNavLinks = createSelector( + selectCurrentPage, + selectHistoryStack, + (currentPage, historyStack) => { + const isWalletPage = page => + page === 'wallet' || + page === 'send' || + page === 'getcredits' || + page === 'rewards' || + page === 'history' || + page === 'invite'; + + const isMyLbryPage = page => + page === 'downloaded' || page === 'published' || page === 'settings'; + + const previousStack = historyStack.slice().reverse(); + + const getPreviousSubLinkPath = checkIfValidPage => { + for (let i = 0; i < previousStack.length; i += 1) { + const currentStackItem = previousStack[i]; + + // Trim off the "/" from the path + const pageInStack = currentStackItem.path.slice(1); + if (checkIfValidPage(pageInStack)) { + return currentStackItem.path; + } + } + + return undefined; + }; + + // Gets the last active sublink in a section + const getActiveSublink = category => { + if (category === 'wallet') { + const previousPath = getPreviousSubLinkPath(isWalletPage); + return previousPath || '/wallet'; + } else if (category === 'myLbry') { + const previousPath = getPreviousSubLinkPath(isMyLbryPage); + return previousPath || '/downloaded'; + } + + return undefined; + }; + + const isCurrentlyWalletPage = isWalletPage(currentPage); + const isCurrentlyMyLbryPage = isMyLbryPage(currentPage); + + const walletSubLinks = [ + { + label: 'Overview', + path: '/wallet', + active: currentPage === 'wallet', + }, + { + label: 'Send & Recieve', + path: '/send', + active: currentPage === 'send', + }, + { + label: 'Get Credits', + path: '/getcredits', + active: currentPage === 'getcredits', + }, + { + label: 'Rewards', + path: '/rewards', + active: currentPage === 'rewards', + }, + { + label: 'Invites', + path: '/invite', + active: currentPage === 'invite', + }, + { + label: 'Transactions', + path: '/history', + active: currentPage === 'history', + }, + ]; + + const myLbrySubLinks = [ + { + label: 'Downloads', + path: '/downloaded', + active: currentPage === 'downloaded', + }, + { + label: 'Publishes', + path: '/published', + active: currentPage === 'published', + }, + { + label: 'Settings', + path: '/settings', + active: currentPage === 'settings', + }, + { + label: 'Backup', + path: '/backup', + active: currentPage === 'backup', + }, + ]; + + const navLinks = { + primary: [ + { + label: 'Explore', + path: '/discover', + active: currentPage === 'discover', + icon: 'Compass', + }, + { + label: 'Subscriptions', + path: '/subscriptions', + active: currentPage === 'subscriptions', + icon: 'AtSign', + }, + ], + secondary: [ + { + label: 'Wallet', + icon: 'CreditCard', + subLinks: walletSubLinks, + path: isCurrentlyWalletPage ? '/wallet' : getActiveSublink('wallet'), + active: isWalletPage(currentPage), + }, + { + label: 'My LBRY', + icon: 'Settings', + subLinks: myLbrySubLinks, + path: isCurrentlyMyLbryPage ? '/downloaded' : getActiveSublink('myLbry'), + active: isMyLbryPage(currentPage), + }, + { + label: 'Publish', + icon: 'UploadCloud', + path: '/publish', + active: currentPage === 'publish', + }, + { + label: 'Help', + path: '/help', + active: currentPage === 'help', + icon: 'HelpCircle', + }, + ], + }; + + return navLinks; + } +); diff --git a/src/redux/selectors/notifications.js b/src/redux/selectors/notifications.js new file mode 100644 index 0000000..0b41428 --- /dev/null +++ b/src/redux/selectors/notifications.js @@ -0,0 +1,8 @@ +import { createSelector } from 'reselect'; + +export const selectState = state => state.notifications || {}; + +export const selectNotification = createSelector( + selectState, + state => (state.queue.length > 0 ? state.queue[0] : {}) +); diff --git a/src/redux/selectors/search.js b/src/redux/selectors/search.js new file mode 100644 index 0000000..20367c0 --- /dev/null +++ b/src/redux/selectors/search.js @@ -0,0 +1,37 @@ +import { selectCurrentPage, selectCurrentParams } from 'redux/selectors/navigation'; +import { createSelector } from 'reselect'; + +export const selectState = state => state.search || {}; + +export const selectSearchValue = createSelector(selectState, state => state.searchQuery); + +export const selectSearchQuery = createSelector( + selectCurrentPage, + selectCurrentParams, + (page, params) => (page === 'search' ? params && params.query : null) +); + +export const selectIsSearching = createSelector(selectState, state => state.searching); + +export const selectSearchUrisByQuery = createSelector(selectState, state => state.urisByQuery); + +export const makeSelectSearchUris = query => + // replace statement below is kind of ugly, and repeated in doSearch action + createSelector( + selectSearchUrisByQuery, + byQuery => byQuery[query ? query.replace(/^lbry:\/\//i, '') : query] + ); + +export const selectWunderBarAddress = createSelector( + selectCurrentPage, + selectSearchQuery, + selectCurrentParams, + (page, query, params) => { + // only populate the wunderbar address if we are on the file/channel pages + // or show the search query + if (page === 'show') { + return params.uri; + } + return query; + } +); diff --git a/src/redux/selectors/wallet.js b/src/redux/selectors/wallet.js new file mode 100644 index 0000000..bddedb8 --- /dev/null +++ b/src/redux/selectors/wallet.js @@ -0,0 +1,125 @@ +import { createSelector } from 'reselect'; + +export const selectState = state => state.wallet || {}; + +export const selectBalance = createSelector(selectState, state => state.balance); + +export const selectTransactionsById = createSelector(selectState, state => state.transactions); + +export const selectTransactionItems = createSelector(selectTransactionsById, byId => { + const items = []; + + Object.keys(byId).forEach(txid => { + const tx = byId[txid]; + + // ignore dust/fees + // it is fee only txn if all infos are also empty + if ( + Math.abs(tx.value) === Math.abs(tx.fee) && + tx.claim_info.length === 0 && + tx.support_info.length === 0 && + tx.update_info.length === 0 + ) { + return; + } + + const append = []; + + append.push( + ...tx.claim_info.map(item => + Object.assign({}, tx, item, { + type: item.claim_name[0] === '@' ? 'channel' : 'publish', + }) + ) + ); + append.push( + ...tx.support_info.map(item => + Object.assign({}, tx, item, { + type: !item.is_tip ? 'support' : 'tip', + }) + ) + ); + append.push(...tx.update_info.map(item => Object.assign({}, tx, item, { type: 'update' }))); + + if (!append.length) { + append.push( + Object.assign({}, tx, { + type: tx.value < 0 ? 'spend' : 'receive', + }) + ); + } + + items.push( + ...append.map(item => { + // value on transaction, amount on outpoint + // amount is always positive, but should match sign of value + const amount = parseFloat(item.balance_delta ? item.balance_delta : item.value); + + return { + txid, + date: tx.timestamp ? new Date(Number(tx.timestamp) * 1000) : null, + amount, + fee: amount < 0 ? -1 * tx.fee / append.length : 0, + claim_id: item.claim_id, + claim_name: item.claim_name, + type: item.type || 'send', + nout: item.nout, + }; + }) + ); + }); + return items.reverse(); +}); + +export const selectRecentTransactions = createSelector(selectTransactionItems, transactions => { + const threshold = new Date(); + threshold.setDate(threshold.getDate() - 7); + return transactions.filter(transaction => transaction.date > threshold); +}); + +export const selectHasTransactions = createSelector( + selectTransactionItems, + transactions => transactions && transactions.length > 0 +); + +export const selectIsFetchingTransactions = createSelector( + selectState, + state => state.fetchingTransactions +); + +export const selectIsSendingSupport = createSelector(selectState, state => state.sendingSupport); + +export const selectReceiveAddress = createSelector(selectState, state => state.receiveAddress); + +export const selectGettingNewAddress = createSelector( + selectState, + state => state.gettingNewAddress +); + +export const selectDraftTransaction = createSelector( + selectState, + state => state.draftTransaction || {} +); + +export const selectDraftTransactionAmount = createSelector( + selectDraftTransaction, + draft => draft.amount +); + +export const selectDraftTransactionAddress = createSelector( + selectDraftTransaction, + draft => draft.address +); + +export const selectDraftTransactionError = createSelector( + selectDraftTransaction, + draft => draft.error +); + +export const selectBlocks = createSelector(selectState, state => state.blocks); + +export const makeSelectBlockDate = block => + createSelector( + selectBlocks, + blocks => (blocks && blocks[block] ? new Date(blocks[block].time * 1000) : undefined) + ); diff --git a/src/types/Notification.js b/src/types/Notification.js new file mode 100644 index 0000000..735591c --- /dev/null +++ b/src/types/Notification.js @@ -0,0 +1,12 @@ +// @flow +export type Notification = { + title: ?string, + message: string, + type: string, + errorCode: ?number, + displayType: mixed, + + // additional properties for SnackBar + linkText: ?string, + linkTarget: ?string, +}; diff --git a/src/util/batchActions.js b/src/util/batchActions.js new file mode 100644 index 0000000..0af1c42 --- /dev/null +++ b/src/util/batchActions.js @@ -0,0 +1,7 @@ +// https://github.com/reactjs/redux/issues/911 +export function batchActions(...actions) { + return { + type: 'BATCH_ACTIONS', + actions, + }; +} diff --git a/src/util/formatCredits.js b/src/util/formatCredits.js new file mode 100644 index 0000000..98383c0 --- /dev/null +++ b/src/util/formatCredits.js @@ -0,0 +1,21 @@ +export function formatCredits(amount, precision) { + return amount.toFixed(precision || 1).replace(/\.?0+$/, ''); +} + +export function formatFullPrice(amount, precision = 1) { + let formated = ''; + + const quantity = amount.toString().split('.'); + const fraction = quantity[1]; + + if (fraction) { + const decimals = fraction.split(''); + const first = decimals.filter(number => number !== '0')[0]; + const index = decimals.indexOf(first); + + // Set format fraction + formated = `.${fraction.substring(0, index + precision)}`; + } + + return parseFloat(quantity[0] + formated); +} diff --git a/src/util/handle-fetch.js b/src/util/handle-fetch.js new file mode 100644 index 0000000..96ce44a --- /dev/null +++ b/src/util/handle-fetch.js @@ -0,0 +1,5 @@ +export default function handleFetchResponse(response) { + return response.status === 200 + ? Promise.resolve(response.json()) + : Promise.reject(new Error(response.statusText)); +} diff --git a/src/util/query_params.js b/src/util/query_params.js new file mode 100644 index 0000000..e7f04d1 --- /dev/null +++ b/src/util/query_params.js @@ -0,0 +1,28 @@ +export function parseQueryParams(queryString) { + if (queryString === '') return {}; + const parts = queryString + .split('?') + .pop() + .split('&') + .map(p => p.split('=')); + + const params = {}; + parts.forEach(array => { + const [first, second] = array; + params[first] = second; + }); + return params; +} + +export function toQueryString(params) { + if (!params) return ''; + + const parts = []; + Object.keys(params).forEach(key => { + if (Object.prototype.hasOwnProperty.call(params, key) && params[key]) { + parts.push(`${key}=${params[key]}`); + } + }); + + return parts.join('&'); +} diff --git a/src/util/redux-utils.js b/src/util/redux-utils.js new file mode 100644 index 0000000..bf9c171 --- /dev/null +++ b/src/util/redux-utils.js @@ -0,0 +1,17 @@ +// 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 +export const handleActions = (actionMap, defaultState) => (state = defaultState, action) => { + const handler = actionMap[action.type]; + + 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 + return state; +}; diff --git a/webpack.config.js b/webpack.config.js index 3c8c34b..1bb41cf 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -4,7 +4,7 @@ module.exports = { output: { path: path.resolve(__dirname, 'build'), filename: 'index.js', - libraryTarget: 'commonjs2' + libraryTarget: 'umd' }, module: { rules: [