Skip to content

Commit

Permalink
dev done
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravv70 committed Jan 1, 2022
1 parent ce84da8 commit c55b5ca
Show file tree
Hide file tree
Showing 23 changed files with 31,610 additions and 17,162 deletions.
47,780 changes: 30,715 additions & 17,065 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.12.3",
"@material-ui/lab": "^4.0.0-alpha.60",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
"axios": "^0.24.0",
"chart.js": "^3.5.1",
"react": "^17.0.2",
"react-alice-carousel": "^2.5.1",
"react-chartjs-2": "^3.0.4",
"react-dom": "^17.0.2",
"react-scripts": "5.0.0",
"web-vitals": "^2.1.2"
"react-html-parser": "^2.0.2",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "react-scripts start",
Expand Down
Binary file added public/banner2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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>
<title>Crypto Hunter</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
43 changes: 9 additions & 34 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,13 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;800&display=swap");

.App-link {
color: #61dafb;
* {
margin: 0;
padding: 0;
box-sizing: border-box;
scroll-behavior: smooth;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
a {
text-decoration: none;
color: gold;
}
41 changes: 23 additions & 18 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import logo from './logo.svg';
import './App.css';
import { makeStyles } from "@material-ui/core";
import Homepage from "./Pages/HomePage";
import "./App.css";
import { BrowserRouter, Route } from "react-router-dom";
import CoinPage from "./Pages/CoinPage";
import Header from "./components/Header";

const useStyles = makeStyles(() => ({
App: {
backgroundColor: "#14161a",
color: "white",
minHeight: "100vh",
},
}));

function App() {
const classes = useStyles();

return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
<BrowserRouter>
<div className={classes.App}>
<Header />
<Route path="/" component={Homepage} exact />
<Route path="/coins/:id" component={CoinPage} exact />
</div>
</BrowserRouter>
);
}

Expand Down
8 changes: 0 additions & 8 deletions src/App.test.js

This file was deleted.

25 changes: 25 additions & 0 deletions src/CryptoContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { createContext, useContext, useEffect, useState } from "react";

const Crypto = createContext();

const CryptoContext = ({ children }) => {
const [currency, setCurrency] = useState("INR");
const [symbol, setSymbol] = useState("₹");

useEffect(() => {
if (currency === "INR") setSymbol("₹");
else if (currency === "USD") setSymbol("$");
}, [currency]);

return (
<Crypto.Provider value={{ currency, setCurrency, symbol }}>
{children}
</Crypto.Provider>
);
};

export default CryptoContext;

export const CryptoState = () => {
return useContext(Crypto);
};
158 changes: 158 additions & 0 deletions src/Pages/CoinPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import { LinearProgress, makeStyles, Typography } from "@material-ui/core";
import axios from "axios";
import { useEffect, useState } from "react";
import { useParams } from "react-router-dom";
import ReactHtmlParser from "react-html-parser";
import CoinInfo from "../components/CoinInfo";
import { SingleCoin } from "../config/api";
import { numberWithCommas } from "../components/CoinsTable";
import { CryptoState } from "../CryptoContext";

const CoinPage = () => {
const { id } = useParams();
const [coin, setCoin] = useState();

const { currency, symbol } = CryptoState();

const fetchCoin = async () => {
const { data } = await axios.get(SingleCoin(id));

setCoin(data);
};

useEffect(() => {
fetchCoin();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const useStyles = makeStyles((theme) => ({
container: {
display: "flex",
[theme.breakpoints.down("md")]: {
flexDirection: "column",
alignItems: "center",
},
},
sidebar: {
width: "30%",
[theme.breakpoints.down("md")]: {
width: "100%",
},
display: "flex",
flexDirection: "column",
alignItems: "center",
marginTop: 25,
borderRight: "2px solid grey",
},
heading: {
fontWeight: "bold",
marginBottom: 20,
fontFamily: "Montserrat",
},
description: {
width: "100%",
fontFamily: "Montserrat",
padding: 25,
paddingBottom: 15,
paddingTop: 0,
textAlign: "justify",
},
marketData: {
alignSelf: "start",
padding: 25,
paddingTop: 10,
width: "100%",
[theme.breakpoints.down("md")]: {
display: "flex",
justifyContent: "space-around",
},
[theme.breakpoints.down("sm")]: {
flexDirection: "column",
alignItems: "center",
},
[theme.breakpoints.down("xs")]: {
alignItems: "start",
},
},
}));

const classes = useStyles();

if (!coin) return <LinearProgress style={{ backgroundColor: "gold" }} />;

return (
<div className={classes.container}>
<div className={classes.sidebar}>
<img
src={coin?.image.large}
alt={coin?.name}
height="200"
style={{ marginBottom: 20 }}
/>
<Typography variant="h3" className={classes.heading}>
{coin?.name}
</Typography>
<Typography variant="subtitle1" className={classes.description}>
{ReactHtmlParser(coin?.description.en.split(". ")[0])}.
</Typography>
<div className={classes.marketData}>
<span style={{ display: "flex" }}>
<Typography variant="h5" className={classes.heading}>
Rank:
</Typography>
&nbsp; &nbsp;
<Typography
variant="h5"
style={{
fontFamily: "Montserrat",
}}
>
{numberWithCommas(coin?.market_cap_rank)}
</Typography>
</span>

<span style={{ display: "flex" }}>
<Typography variant="h5" className={classes.heading}>
Current Price:
</Typography>
&nbsp; &nbsp;
<Typography
variant="h5"
style={{
fontFamily: "Montserrat",
}}
>
{symbol}{" "}
{numberWithCommas(
coin?.market_data.current_price[currency.toLowerCase()]
)}
</Typography>
</span>
<span style={{ display: "flex" }}>
<Typography variant="h5" className={classes.heading}>
Market Cap:
</Typography>
&nbsp; &nbsp;
<Typography
variant="h5"
style={{
fontFamily: "Montserrat",
}}
>
{symbol}{" "}
{numberWithCommas(
coin?.market_data.market_cap[currency.toLowerCase()]
.toString()
.slice(0, -6)
)}
M
</Typography>
</span>
</div>
</div>
<CoinInfo coin={coin} />
</div>
);
};

export default CoinPage;
14 changes: 14 additions & 0 deletions src/Pages/HomePage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";
import Banner from "../components/Banner/Banner";
import CoinsTable from "../components/CoinsTable";

const Homepage = () => {
return (
<>
<Banner />
<CoinsTable />
</>
);
};

export default Homepage;
Loading

0 comments on commit c55b5ca

Please sign in to comment.