diff --git a/src/components/CoinData.jsx b/src/components/CoinData.jsx new file mode 100644 index 0000000..841a837 --- /dev/null +++ b/src/components/CoinData.jsx @@ -0,0 +1,67 @@ +import React from 'react'; + +const CoinData = ({ data }) => { + console.log(data); // Ensure data is received and logged properly + + if (!data || Object.keys(data).length === 0) { + return
Not valid data
; + } + + const coin = data[0]; + console.log(coin); + + return ( +
+
+ {coin.name} +
+

+ {coin.name} ({coin.symbol ? coin.symbol.toUpperCase() : ''}) +

+
+
+

Current Price:

+

${coin.current_price.toFixed(2)}

+
+
+

Market Cap:

+

${coin.market_cap.toLocaleString()}

+
+
+

Total Volume:

+

${coin.total_volume.toLocaleString()}

+
+
+

Circulating Supply:

+

{coin.circulating_supply.toLocaleString()} {coin.symbol ? coin.symbol.toUpperCase() : ''}

+
+
+

High 24h:

+

${coin.high_24h.toFixed(2)}

+
+
+

Low 24h:

+

${coin.low_24h.toFixed(2)}

+
+
+

Price Change (24h):

+

${coin.price_change_24h.toFixed(2)} ({coin.price_change_percentage_24h.toFixed(2)}%)

+
+
+

All-time High:

+

${coin.ath.toFixed(2)} ({new Date(coin.ath_date).toLocaleDateString()})

+
+
+

All-time Low:

+

${coin.atl.toFixed(2)} ({new Date(coin.atl_date).toLocaleDateString()})

+
+
+

Last Updated:

+

{new Date(coin.last_updated).toLocaleString()}

+
+
+
+ ); +}; + +export default CoinData; diff --git a/src/components/CointTable.jsx b/src/components/CointTable.jsx index cce27de..536fc46 100644 --- a/src/components/CointTable.jsx +++ b/src/components/CointTable.jsx @@ -2,15 +2,21 @@ import React, { useContext } from 'react'; import { CoinContext } from '../context/CoinContext'; const CoinTable = () => { - const { coins, currency } = useContext(CoinContext); + + const {currency,coins } = useContext(CoinContext); + + - // Handle case where coins are still loading or not yet fetched if (!coins || coins.length === 0) { - return
Loading...
; // You can replace with a loading indicator component + return ( +
+
+
+ ); } // Display only the first 10 coins - const displayCoins = coins.slice(0, 10); + const displayCoins = coins.slice(0, 100); return (
@@ -36,21 +42,21 @@ const CoinTable = () => { {displayCoins.map((coin, index) => ( - +
{coin.name} - {coin.name} ({coin.symbol.toUpperCase()}) + {coin.name} ({coin.symbol.toUpperCase()})
- + {currency.symbol} {coin.current_price.toLocaleString()} {/* Hide Market Cap on smaller screens */} - + {currency.symbol} {coin.market_cap.toLocaleString()} {/* Hide 24h Change on smaller screens */} - = 0 ? 'text-green-500' : 'text-red-500'}`}> + = 0 ? 'text-green-500' : 'text-red-500'}`}> {coin.price_change_percentage_24h.toFixed(2)}% diff --git a/src/components/Footer.jsx b/src/components/Footer.jsx new file mode 100644 index 0000000..1e44f1a --- /dev/null +++ b/src/components/Footer.jsx @@ -0,0 +1,37 @@ +// src/components/Footer.jsx +import React from 'react'; + +const Footer = () => { + return ( + + ); +}; + +export default Footer; diff --git a/src/context/CoinContext.jsx b/src/context/CoinContext.jsx index a7d72f1..3739e71 100644 --- a/src/context/CoinContext.jsx +++ b/src/context/CoinContext.jsx @@ -12,7 +12,7 @@ const CoinContextProvider = (props) => { method: 'GET', headers: { accept: 'application/json', 'x-cg-demo-api-key': 'CG-kAqoQqNM9q4z9V4w4Uadedtj' } }; - + fetch(`https://api.coingecko.com/api/v3/coins/markets?vs_currency=${currency.name}`, options) .then(response => response.json()) .then(response => setCoins(response)) diff --git a/src/main.jsx b/src/main.jsx index f01e1fc..62257d8 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -7,6 +7,7 @@ import Home from './pages/Home/Home.jsx' import News from './pages/News/News.jsx'; import Market from './pages/Market/Market.jsx'; import CoinContextProvider from './context/CoinContext.jsx'; +import Footer from './components/Footer.jsx'; ReactDOM.createRoot(document.getElementById('root')).render( @@ -19,6 +20,7 @@ ReactDOM.createRoot(document.getElementById('root')).render( } /> } /> +
diff --git a/src/pages/Home/Home.jsx b/src/pages/Home/Home.jsx index 365382f..d7d3f95 100644 --- a/src/pages/Home/Home.jsx +++ b/src/pages/Home/Home.jsx @@ -1,25 +1,15 @@ -import React, { useContext } from 'react' -import { CoinContext } from '../../context/CoinContext' +import React, { useContext, useState,useEffect } from 'react' import CoinTable from '../../components/CointTable'; -const Home = () => { - const {coins,currency}=useContext(CoinContext); - +const Home = () => { + return (
-

Welcome to CryptoMania

-

Your one stop solution for crypto

-
-
- - -
- - -
- +

Welcome to CryptoMania

+

Your one stop solution for crypto

+ +
) diff --git a/src/pages/Market/Market.jsx b/src/pages/Market/Market.jsx index b1a26ed..0f94b35 100644 --- a/src/pages/Market/Market.jsx +++ b/src/pages/Market/Market.jsx @@ -1,31 +1,75 @@ -import React, { useContext } from 'react' -import { CoinContext } from '../../context/CoinContext'; +import React, { useContext, useState } from 'react'; +import { CoinContext } from '../../context/CoinContext'; +import CoinData from '../../components/CoinData'; const Market = () => { + const [searchQuery, setSearchQuery] = useState(''); + const { coins } = useContext(CoinContext); + const [filteredCoins, setFilteredCoins] = useState([]); + const [val, setVal] = useState(''); - const {val,setval}=useContext(CoinContext); - - - function update(){ - setval((old)=>old+1+old); - console.log(val); - } + const handleInputChange = (e) => { + const { value } = e.target; + setSearchQuery(value); + //console.log("hande",value); - return ( -
-

Welcome to Market Section

-

Your one stop solution for crypto

-

The value is {val}

- -
- -
+ // Filter coins based on input value + const filtered = coins.filter((coin) => + coin.name.toLowerCase().includes(value.toLowerCase()) + ); + + // Take only the first three valid matches + const firstThreeMatches = filtered.slice(0, 3); -
+ setFilteredCoins(firstThreeMatches); + }; + + const handleSubmit = (e) => { + e.preventDefault(); + const filtered = coins.filter((coin) => + coin.name.toLowerCase().includes(searchQuery.toLowerCase()) + ); + + setVal(filtered); + setSearchQuery(""); + }; + + return ( + <> +
+

Welcome to Market Section

+

Your one stop solution for crypto

+ +
+ +
+ + + {filteredCoins.map((coin, index) => ( + + ))} + + +
+ + +
+ {/* Pass data as a prop */} +
+ + ) } -export default Market +export default Market;