Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shows crypto currency values #236

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28,701 changes: 28,701 additions & 0 deletions crypto currency info/package-lock.json

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions crypto currency info/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^0.27.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.4.0",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4",
"workbox-background-sync": "^6.5.3",
"workbox-broadcast-update": "^6.5.3",
"workbox-cacheable-response": "^6.5.3",
"workbox-core": "^6.5.3",
"workbox-expiration": "^6.5.3",
"workbox-google-analytics": "^6.5.3",
"workbox-navigation-preload": "^6.5.3",
"workbox-precaching": "^6.5.3",
"workbox-range-requests": "^6.5.3",
"workbox-routing": "^6.5.3",
"workbox-strategies": "^6.5.3",
"workbox-streams": "^6.5.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file added crypto currency info/public/favicon.ico
Binary file not shown.
40 changes: 40 additions & 0 deletions crypto currency info/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Binary file added crypto currency info/public/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added crypto currency info/public/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions crypto currency info/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions crypto currency info/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
36 changes: 36 additions & 0 deletions crypto currency info/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { useEffect, useState } from 'react';
import {Routes,Route} from "react-router-dom"
import Navbar from './components/Navbar';
import Coins from './components/Coins';
import { getAPI } from './config/GetApi';
import Coin from './Pages/Coin';

function App() {
const [coins,setCoins]=useState([])

useEffect(()=>{

getAPI("https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=10&page=1&sparkline=false").then((res)=>{
console.log(res.data);
setCoins(res.data)
}).catch((error) => {
console.log(error)
})
},[])


return (
<div className="App">
<Navbar/>
<Routes>
<Route path="/" element={<Coins coins={coins}/>}/>
<Route path="/coin" element={<Coins coins={coins}/>}/>
<Route path='/coin/:coinId' element={<Coin/>}/>


</Routes>
</div>
);
}

export default App;
109 changes: 109 additions & 0 deletions crypto currency info/src/Pages/Coin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
.coin-container .content {
max-width: 740px;
margin: 1rem auto;
padding: .7rem 1rem;
display: flex;
flex-direction: column;

box-shadow: 0px 0px 12px #18191b;
border-radius: 8px;
}

.rank {
margin: .5 0;
}

.rank-btn {
border: 1px solid #6900ff;
box-shadow: 0px 0px 8px #6900ff;
background-color: #c8acee;
border-radius: 8px;
padding: .2rem;
}

.info {
display: grid;
grid-template-columns: repeat(2, 1fr);
}

.info .coin-heading {
display: flex;
align-items: center;
margin: 1rem 0;
}

.info .coin-price {
display: flex;
align-items: center;
justify-content: center;
}

.info p {
padding-right: 1rem;
}

table {
margin: .5rem 0;
}

td, th {
padding: 8px;
text-align: center;
}



.stats {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-gap: 2rem;
width: 100%;
}

.stats .row {
display: flex;
justify-content: space-between;
border-bottom: 1px solid #808080;
margin: .6rem 0;
padding-bottom: .5rem;
}

.stats .row p:first-child {
color: #d3d3d3;
}

.about h3 {
margin: 1rem 0;
}

@media screen and (max-width: 700px) {
.coin-container .content {
max-width: 100%;
margin: .5rem;
padding: 0 .5rem;
}

.stats {
grid-template-columns: 1fr;
}

td,th {
padding: 3px;
}

.rank {
margin: .5rem;
}

.rank-btn {
margin: .5rem 0;
}
}








104 changes: 104 additions & 0 deletions crypto currency info/src/Pages/Coin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import React, { useEffect, useState } from 'react'
import { useParams } from 'react-router-dom'
import { getAPI } from '../config/GetApi'
import "./Coin.css"
const Coin = (props) => {
const {coinId}=useParams()
const [coin,setCoin]=useState({})
useEffect(()=>{
getAPI(`https://api.coingecko.com/api/v3/coins/${coinId}`).then((res)=>{
console.log(res.data)
setCoin(res.data)
}).catch((error) => {
console.log(error)
})
},[])
return (
<div>
<div className='coin-container'>
<div className='content'>
<h1>{coin.name}</h1>
</div>
<div className='content'>
<div className='rank'>
<span className='rank-btn'>Rank # {coin.market_cap_rank}</span>
</div>
<div className='info'>
<div className='coin-heading'>
{coin.image ? <img src={coin.image.small} alt='' /> : null}
<p>{coin.name}</p>
{coin.symbol ? <p>{coin.symbol.toUpperCase()}/USD</p> : null}

</div>
<div className='coin-price'>
{coin.market_data?.current_price ? <h1>${coin.market_data.current_price.usd.toLocaleString()}</h1> : null}
</div>
</div>
</div>

<div className='content'>
<table>
<thead>
<tr>
<th>1h</th>
<th>24h</th>
<th>7d</th>
<th>14d</th>
<th>30d</th>
<th>1yr</th>
</tr>
</thead>
<tbody>
<tr>
<td>{coin.market_data?.price_change_percentage_1h_in_currency ? <p>{coin.market_data.price_change_percentage_1h_in_currency.usd.toFixed(1)}%</p> : null}</td>
<td>{coin.market_data?.price_change_percentage_24h_in_currency ? <p>{coin.market_data.price_change_percentage_24h_in_currency.usd.toFixed(1)}%</p> : null}</td>
<td>{coin.market_data?.price_change_percentage_24h_in_currency ? <p>{coin.market_data.price_change_percentage_7d_in_currency.usd.toFixed(1)}%</p> : null}</td>
<td>{coin.market_data?.price_change_percentage_24h_in_currency ? <p>{coin.market_data.price_change_percentage_14d_in_currency.usd.toFixed(1)}%</p> : null}</td>
<td>{coin.market_data?.price_change_percentage_24h_in_currency ? <p>{coin.market_data.price_change_percentage_30d_in_currency.usd.toFixed(1)}%</p> : null}</td>
<td>{coin.market_data?.price_change_percentage_24h_in_currency ? <p>{coin.market_data.price_change_percentage_1y_in_currency.usd.toFixed(1)}%</p> : null}</td>

</tr>
</tbody>
</table>
</div>
<div className='content'>
<div className='stats'>
<div className='left'>
<div className='row'>
<h4>24 Hour Low</h4>
{coin.market_data?.low_24h ? <p>${coin.market_data.low_24h.usd.toLocaleString()}</p> : null}
</div>
<div className='row'>
<h4>24 Hour High</h4>
{coin.market_data?.high_24h ? <p>${coin.market_data.high_24h.usd.toLocaleString()}</p> : null} </div>

</div>
<div className='right'>
<div className='row'>
<h4>Market Cap</h4>
{coin.market_data?.market_cap ? <p>${coin.market_data.market_cap.usd.toLocaleString()}</p> : null}
</div>
<div className='row'>
<h4>Circulating Supply</h4>
{coin.market_data ? <p>{coin.market_data.circulating_supply}</p> : null}
</div>

</div>
</div>
</div>

<div className='content'>
<div className='about'>
<h3>About</h3>
<p>
{coin.description ? coin.description.en : ''}
</p>

</div>
</div>

</div>
</div>
)
}
export default Coin
19 changes: 19 additions & 0 deletions crypto currency info/src/components/CoinItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react";
import "./Coins.css";
const CoinItem = (props) => {
return (
<div className='coin-row'>
<p>{props.coins.market_cap_rank}</p>
<div className='img-symbol'>
<img src={props.coins.image} alt='' />
<p>{props.coins.symbol.toUpperCase()}</p>
</div>
<p>${props.coins.current_price.toLocaleString()}</p>
<p>{props.coins.price_change_percentage_24h.toFixed(2)}%</p>
<p className='hide-mobile'>${props.coins.total_volume.toLocaleString()}</p>
<p className='hide-mobile'>${props.coins.market_cap.toLocaleString()}</p>
</div>
);
};

export default CoinItem;
Loading