Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 6th, 2020 277 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useState, useEffect } from 'react';
  2. import { fetchLoginStatus } from './services';
  3. import Nav from './Nav';
  4. import Login from './Login';
  5. import SendMessage from './SendMessage';
  6. import RefreshUsers from './RefreshUsers';
  7. import RefreshMessages from './RefreshMessages';
  8. import './app.css';
  9.  
  10. const App = () => {
  11.   const [userState, setUserState] = useState({ isLoggedIn: false });
  12.   //const [currentMessages, setCurrentMessages] = useState({ currentMessages: [] });
  13.  
  14.   // Runs when first rendered
  15.   // AND whenever any vars in the passed array change
  16.   // (None in this case)
  17.   useEffect(() => {
  18.     fetchLoginStatus()
  19.       .then(userInfo => {
  20.         setUserState({
  21.           isLoggedIn: true,
  22.           username: userInfo.username
  23.         });
  24.       });
  25.   }, []);
  26.  
  27.   const login = (username) => {
  28.     setUserState({
  29.       isLoggedIn: true,
  30.       username
  31.     });
  32.   };
  33.  
  34.   const logout = () => {
  35.     setUserState({
  36.       isLoggedIn: false
  37.     });
  38.   };
  39.  
  40.   const processUserState = (loggedInState, messages) => {
  41.     console.log("before Process User state: send message");
  42.     console.log(messages);
  43.     console.log("length");
  44.     console.log(messages.length);
  45.     setUserState({
  46.       username: userState.username,
  47.       isLoggedIn: loggedInState,
  48.       currentMessages: [],
  49.       currentMessages: messages
  50.     });
  51.  
  52.  
  53.     console.log("Process User state: send message");
  54.     console.log(messages);
  55.     console.log("length");
  56.     console.log(messages.length);
  57.     /*
  58.     setCurrentMessages(
  59.       {
  60.         currentMessages: messages,
  61.       }
  62.     );*/
  63.  
  64.     console.log('Current messages are');
  65.     console.log(userState);
  66.   };
  67.  
  68.   let content;
  69.  
  70.   if (userState.isLoggedIn) {
  71.     content = <>< SendMessage onMessage={processUserState} />
  72.       < RefreshMessages user={userState} />
  73.     </>;
  74.   } else {
  75.     content = <Login onLogin={login} />;
  76.   }
  77.  
  78.   return (
  79.     <div className="app">
  80.       <Nav user={userState} onLogout={logout} />
  81.       {content}
  82.     </div>
  83.   );
  84. };
  85.  
  86. export default App;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top