From a166485a788989a37e1bf5e7e14be454eae4c6e8 Mon Sep 17 00:00:00 2001
From: seanyesmunt <sean.yesmunt@gmail.com>
Date: Tue, 21 Aug 2018 23:59:06 -0400
Subject: [PATCH] move channel_list call to happen after fetching subscriptions
 from db

---
 src/renderer/page/subscriptions/index.js    |  3 --
 src/renderer/page/subscriptions/view.jsx    | 38 ---------------------
 src/renderer/redux/actions/subscriptions.js |  4 ++-
 yarn.lock                                   |  4 +--
 4 files changed, 5 insertions(+), 44 deletions(-)

diff --git a/src/renderer/page/subscriptions/index.js b/src/renderer/page/subscriptions/index.js
index 9963b26e0..d5de2d066 100644
--- a/src/renderer/page/subscriptions/index.js
+++ b/src/renderer/page/subscriptions/index.js
@@ -6,7 +6,6 @@ import {
   selectIsFetchingSubscriptions,
   selectNotifications,
 } from 'redux/selectors/subscriptions';
-import { doFetchClaimsByChannel } from 'redux/actions/content';
 import { setSubscriptionNotifications, doFetchMySubscriptions } from 'redux/actions/subscriptions';
 import SubscriptionsPage from './view';
 
@@ -14,7 +13,6 @@ const select = state => ({
   loading:
     selectIsFetchingSubscriptions(state) ||
     Boolean(Object.keys(selectSubscriptionsBeingFetched(state)).length),
-  subscriptionsBeingFetched: selectSubscriptionsBeingFetched(state),
   subscriptions: selectSubscriptions(state),
   subscriptionClaims: selectSubscriptionClaims(state),
   notifications: selectNotifications(state),
@@ -23,7 +21,6 @@ const select = state => ({
 export default connect(
   select,
   {
-    doFetchClaimsByChannel,
     setSubscriptionNotifications,
     doFetchMySubscriptions,
   }
diff --git a/src/renderer/page/subscriptions/view.jsx b/src/renderer/page/subscriptions/view.jsx
index 60c57cf93..a38556644 100644
--- a/src/renderer/page/subscriptions/view.jsx
+++ b/src/renderer/page/subscriptions/view.jsx
@@ -6,16 +6,13 @@ import * as NOTIFICATION_TYPES from 'constants/notification_types';
 import Button from 'component/button';
 import FileList from 'component/fileList';
 import type { Claim } from 'types/claim';
-import isDev from 'electron-is-dev';
 import HiddenNsfwClaims from 'component/hiddenNsfwClaims';
 
 type Props = {
-  doFetchClaimsByChannel: (string, number) => void,
   doFetchMySubscriptions: () => void,
   setSubscriptionNotifications: ({}) => void,
   subscriptions: Array<Subscription>,
   subscriptionClaims: Array<{ uri: string, claims: Array<Claim> }>,
-  subscriptionsBeingFetched: {},
   notifications: {},
   loading: boolean,
 };
@@ -37,41 +34,6 @@ export default class extends React.PureComponent<Props> {
     setSubscriptionNotifications(newNotifications);
   }
 
-  componentDidUpdate() {
-    const {
-      subscriptions,
-      subscriptionClaims,
-      doFetchClaimsByChannel,
-      subscriptionsBeingFetched,
-    } = this.props;
-
-    const subscriptionClaimMap = {};
-    subscriptionClaims.forEach(claim => {
-      /*
-      This check added 6/20/18 to fix function receiving empty claims unexpectedly.
-      The better fix is ensuring channels aren't added to byId if there are no associated claims
-      We are adding this now with the redesign release to ensure users see the correct subscriptions
-      */
-      if (claim.claims.length) {
-        subscriptionClaimMap[claim.uri] = 1;
-      } else if (isDev) {
-        // eslint-disable no-console
-        console.error(
-          `Claim for ${
-            claim.uri
-          } was added to byId in redux but there are no loaded fetched claims. This shouldn't happen because a subscription should have claims attached to it.`
-        );
-        // eslint-enable no-console
-      }
-    });
-
-    subscriptions.forEach(sub => {
-      if (!subscriptionClaimMap[sub.uri] && !subscriptionsBeingFetched[sub.uri]) {
-        doFetchClaimsByChannel(sub.uri, 1);
-      }
-    });
-  }
-
   render() {
     const { subscriptions, subscriptionClaims, loading } = this.props;
 
diff --git a/src/renderer/redux/actions/subscriptions.js b/src/renderer/redux/actions/subscriptions.js
index 2af4d5844..d677d51a6 100644
--- a/src/renderer/redux/actions/subscriptions.js
+++ b/src/renderer/redux/actions/subscriptions.js
@@ -8,7 +8,7 @@ import type { Subscription } from 'types/subscription';
 import { selectSubscriptions } from 'redux/selectors/subscriptions';
 import { makeSelectClientSetting } from 'redux/selectors/settings';
 import { Lbry, buildURI, parseURI } from 'lbry-redux';
-import { doPurchaseUri } from 'redux/actions/content';
+import { doPurchaseUri, doFetchClaimsByChannel } from 'redux/actions/content';
 import { doClaimRewardType } from 'redux/actions/rewards';
 import Promise from 'bluebird';
 import Lbryio from 'lbryio';
@@ -91,6 +91,8 @@ export const doFetchMySubscriptions = () => (dispatch: Dispatch, getState: () =>
         type: ACTIONS.FETCH_SUBSCRIPTIONS_SUCCESS,
         data: subscriptions,
       });
+
+      subscriptions.forEach(({ uri }) => dispatch(doFetchClaimsByChannel(uri)));
     })
     .catch(() => {
       dispatch({
diff --git a/yarn.lock b/yarn.lock
index 8684ec3eb..d52cf43b2 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -5651,9 +5651,9 @@ lazy-val@^1.0.3:
   version "1.0.3"
   resolved "https://registry.yarnpkg.com/lazy-val/-/lazy-val-1.0.3.tgz#bb97b200ef00801d94c317e29dc6ed39e31c5edc"
 
-lbry-redux@lbryio/lbry-redux#ada4880c5d0758c7973aff9d443a87874d98b320:
+lbry-redux@lbryio/lbry-redux#31f7afa8a37f5741dac01fc1ecdf153f3bed95dc:
   version "0.0.1"
-  resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/ada4880c5d0758c7973aff9d443a87874d98b320"
+  resolved "https://codeload.github.com/lbryio/lbry-redux/tar.gz/31f7afa8a37f5741dac01fc1ecdf153f3bed95dc"
   dependencies:
     proxy-polyfill "0.1.6"
     reselect "^3.0.0"
-- 
2.45.3