Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 6th, 2020 206 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useState } from 'react';
  2. import { sendMessage } from './services';
  3. import errorMessages from './errorMessages';
  4. import spinner from './spinner.svg';
  5.  
  6. const SendMessage = ({ onMessage }) => {
  7.     // This state is all local to the component
  8.     const [message, setMessage] = useState('');
  9.     const [isLoading, setIsLoading] = useState(false);
  10.     const [error, setError] = useState('');
  11.  
  12.     const processMessage = () => {
  13.         if (!message || message.length === 0) {
  14.             setError(errorMessages.EMPTY_MESSAAGE);
  15.             return;
  16.         }
  17.         // set output for while we wait
  18.         setError('');
  19.         setIsLoading(true);
  20.         // start service call
  21.         sendMessage(message)
  22.             .then((messages) => {
  23.                 setIsLoading(false);
  24.                 onMessage(true, messages);
  25.             })
  26.             .catch((err) => {
  27.                 setError(errorMessages[err.code || 'DEFAULT']);
  28.                 setIsLoading(false);
  29.                 if (err.code === errorMessages.USER_NOTFOUND || err.code === errorMessages.USER_UNAUTHORIZED) {
  30.                     onMessage(false, []);
  31.                 }
  32.             });
  33.     };
  34.  
  35.     return (
  36.         <div className="sendMessages">
  37.             <p className="error">{error}</p>
  38.             <input onChange={(e) => setMessage(e.target.value)} required />
  39.             {isLoading ?
  40.                 <img alt="spinner" src={spinner} /> :
  41.                 <button onClick={processMessage}>Send</button>
  42.             }
  43.         </div>
  44.     );
  45. };
  46.  
  47. export default SendMessage;
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