@@ -5,6 +5,7 @@ import DatePicker from 'react-datepicker';
55import 'react-datepicker/dist/react-datepicker.css' ;
66import './App.css' ; // Import the CSS
77import NewsTicker from './components/News' ; // Import the News components
8+ import CryptoNewsAnalyzer from './components/CryptoNewsAnalyzer' ; // Import the CryptoNewsAnalyzer components
89
910function CoinDetails ( { coin, history } ) {
1011 // Prepare the data for the line chart
@@ -15,7 +16,7 @@ function CoinDetails({ coin, history }) {
1516 < div className = "coin-details" >
1617 < h2 > { coin . name } ({ coin . symbol . toUpperCase ( ) } )</ h2 >
1718 < div style = { { display : 'flex' , flexDirection : 'column' , alignItems : 'flex-start' , width : '100%' } } >
18- < span style = { { color : priceChangeColor , fontSize : '0.8em' } } >
19+ < span style = { { color : priceChangeColor , fontSize : '0.8em' , top : 2 , right : 1200 , } } >
1920 { coin . price_change_24h > 0 && '+' } { coin . price_change_24h ?. toFixed ( 2 ) } %
2021 </ span >
2122 < p style = { { fontSize : '2em' , margin : 0 } } >
@@ -43,17 +44,32 @@ const holdingsData = [
4344
4445function App ( ) {
4546 const [ coins , setCoins ] = useState ( [ ] ) ;
47+ const [ allCoins , setAllCoins ] = useState ( [ ] ) ;
4648 const [ selectedCoin , setSelectedCoin ] = useState ( null ) ;
4749 const [ history , setHistory ] = useState ( [ ] ) ;
4850 const [ loading , setLoading ] = useState ( true ) ;
4951 const [ startDate , setStartDate ] = useState ( new Date ( ) ) ;
5052 const [ endDate , setEndDate ] = useState ( new Date ( ) ) ;
51- const api_key = 'YOUR_API_KEY' ; // replace this with your own API key
53+ const api_key = process . env . REACT_APP_COIN_GECKP_API_KEY ;
5254
5355 const holdings = useMemo ( ( ) => holdingsData , [ ] ) ;
5456
5557 const COLORS = [ '#0088FE' , '#00C49F' , '#FFBB28' , '#FF8042' ] ; // add more colors if you have more coins
5658
59+ useEffect ( ( ) => {
60+ axios . get ( `https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd` , {
61+ headers : {
62+ 'X-CoinAPI-Key' : api_key
63+ }
64+ } )
65+ . then ( response => {
66+ setAllCoins ( response . data ) ;
67+ } )
68+ . catch ( error => {
69+ console . error ( 'Error fetching all coins' , error ) ;
70+ } ) ;
71+ } , [ ] ) ;
72+
5773 useEffect ( ( ) => {
5874 axios . get ( `https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=${ holdings . map ( holding => holding . id ) . join ( ',' ) } ` , {
5975 headers : {
@@ -81,7 +97,7 @@ function App() {
8197
8298 const handleCoinSelect = ( id ) => {
8399 setLoading ( true ) ;
84- const selected = coins . find ( coin => coin . id === id ) ;
100+ const selected = allCoins . find ( coin => coin . id === id ) ;
85101 setSelectedCoin ( selected ) ;
86102
87103 // Fetch historical data for the selected date range
@@ -90,7 +106,7 @@ function App() {
90106 while ( date <= endDate ) {
91107 const formattedDate = `${ date . getDate ( ) } -${ date . getMonth ( ) + 1 } -${ date . getFullYear ( ) } ` ;
92108
93- const promise = axios . get ( `http ://localhost:3001 /api/v3/coins/${ id } /history?date=${ formattedDate } ` , {
109+ const promise = axios . get ( `https ://api.coingecko.com /api/v3/coins/${ id } /history?date=${ formattedDate } ` , {
94110 headers : {
95111 'X-CoinAPI-Key' : api_key
96112 }
@@ -133,7 +149,7 @@ function App() {
133149 ) : (
134150 < div style = { { display : 'flex' , flexDirection : 'column' , alignItems : 'center' , justifyContent : 'center' , width : '100%' , height : '100vh' } } >
135151 < div style = { { display : 'flex' , flexDirection : 'row' , justifyContent : 'space-between' , width : '100%' , height : '100%' } } >
136- < div style = { { flex : 1 , border : '1px solid black ' , margin : '10px' , padding : '20px' , borderRadius : '10px' , boxSizing : 'border-box' } } >
152+ < div style = { { flex : 1 , border : '1px solid #333 ' , margin : '10px' , padding : '20px' , borderRadius : '10px' , boxSizing : 'border-box' , backgroundColor : '#1F1F1F' , color : '#A9A9A9 ' } } >
137153 < h2 > Portfolio Tracker</ h2 >
138154 < ResponsiveContainer width = "100%" height = { 400 } >
139155 < PieChart >
@@ -180,16 +196,19 @@ function App() {
180196 < h3 > ROI: { roi . toFixed ( 2 ) } %</ h3 >
181197 < h3 > P& L : ${pnl . toFixed ( 2 ) } </ h3 >
182198 </ div >
183- < div style = { { flex : 1 , border : '1px solid black ' , margin : '10px' , padding : '20px' , borderRadius : '10px' , boxSizing : 'border-box' } } >
199+ < div style = { { flex : 1 , border : '1px solid #333 ' , margin : '10px' , padding : '20px' , borderRadius : '10px' , boxSizing : 'border-box' , backgroundColor : '#1F1F1F' , color : '#A9A9A9 ' } } >
184200 < h2 > Trends</ h2 >
185201 < select value = { selectedCoin ? selectedCoin . id : '' } onChange = { e => handleCoinSelect ( e . target . value ) } >
186- { coins . map ( coin => (
202+ { allCoins . map ( coin => (
187203 < option key = { coin . id } value = { coin . id } > { coin . name } ({ coin . symbol . toUpperCase ( ) } )</ option >
188204 ) ) }
189205 </ select >
190206 < DatePicker selected = { startDate } onChange = { date => setStartDate ( date ) } />
191207 < DatePicker selected = { endDate } onChange = { date => setEndDate ( date ) } />
192208 { selectedCoin && < CoinDetails coin = { selectedCoin } history = { history } /> }
209+ </ div >
210+ < div style = { { flex : 1 , border : '1px solid #333' , margin : '10px' , padding : '20px' , borderRadius : '10px' , boxSizing : 'border-box' , backgroundColor : '#1F1F1F' , color : '#A9A9A9' } } >
211+ < CryptoNewsAnalyzer coins = { allCoins } />
193212 </ div >
194213 </ div >
195214 </ div >
0 commit comments