import { receivedAccount } from './account';
import { fetchHomeTimeline, receivedHomeTimeline } from './timeline';
import { onError } from './error-handler';
import { TwitterAction } from '../middlewares/twitterClient';

export function setUp(credential) {
  return new TwitterAction({
    credential,
    invoke: twitterClient => dispatch => {
      twitterClient
        .fetchUser()
        .then(user => {
          dispatch(receivedAccount(user, credential, true));
          dispatch(fetchHomeTimeline(credential));
          dispatch(subscribeStream(twitterClient, user.id_str));
        })
        .catch(error => dispatch(onError(error)));
    }
  });
}

export function subscribeStream(twitterClient, userId) {
  return dispatch => {
    twitterClient.subscribeUserStream(userId)
      .on('tweet', (data) => {
        dispatch(receivedHomeTimeline([data]));
      });
  };
}

@@ -2,24 +2,21 @@
 mport %7B 
-received
+fetch
 Account 
@@ -109,51 +109,8 @@
 e';%0A
-import %7B onError %7D from './error-handler';%0A
 impo
@@ -168,16 +168,88 @@
 ient';%0A%0A
+/**%0A *%0A * @param %7BCredential%7D credential%0A * @return %7BTwitterAction%7D%0A */%0A
 export f
@@ -368,77 +368,8 @@
 %3E %7B%0A
-      twitterClient%0A        .fetchUser()%0A        .then(user =%3E %7B%0A    
     
@@ -383,24 +383,21 @@
 tch(
-received
+fetch
 Account(
 user
@@ -396,14 +396,8 @@
 unt(
-user, 
 cred
@@ -410,36 +410,32 @@
 , true));%0A      
-    
 dispatch(fetchHo
@@ -461,28 +461,24 @@
 al));%0A      
-  
-  
 dispatch(sub
@@ -509,81 +509,25 @@
 nt, 
-user.id_str));%0A        %7D)%0A        .catch(error =%3E dispatch(onError(error)
+credential.userId
 ));%0A

Use fetchAccount instead of receivedAccount