├── .env
├── .firebase
└── hosting.YnVpbGQ.cache
├── .firebaserc
├── .gitignore
├── README.md
├── firebase.json
├── package.json
├── postcss.config.js
├── public
├── favicon.ico
├── index.html
├── logo192.png
├── logo512.png
├── manifest.json
└── robots.txt
├── src
├── App.js
├── components
│ ├── CoinItem.jsx
│ ├── CoinSearch.jsx
│ ├── Footer.jsx
│ ├── Navbar.jsx
│ ├── SavedCoin.jsx
│ ├── ThemeToggle.jsx
│ └── Trending.jsx
├── context
│ ├── AuthContext.jsx
│ └── ThemeContext.jsx
├── firebase.js
├── index.css
├── index.js
└── routes
│ ├── Account.jsx
│ ├── CoinPage.jsx
│ ├── Home.jsx
│ ├── Signin.jsx
│ └── Signup.jsx
├── tailwind.config.js
└── yarn.lock
/.env:
--------------------------------------------------------------------------------
1 | REACT_APP_FIREBASE_API_KEY=YOUR REACT KEY
2 | REACT_APP_FIREBASE_AUTH_DOMAIN=YOUR FIREBASE AUTH DOMAIN
3 | REACT_APP_FIREBASE_PROJECT_ID=YOUR PROJECT ID
4 | REACT_APP_FIREBASE_STORAGE_BUCKET=YOUR STORAGE BUCKET
5 | REACT_APP_FIREBASE_MESSAGING_SENDER=YOUR MESSAGING SENDER
6 | REACT_APP_FIREBASE_APP_ID=YOUR APP ID
--------------------------------------------------------------------------------
/.firebase/hosting.YnVpbGQ.cache:
--------------------------------------------------------------------------------
1 | asset-manifest.json,1654105834037,0ae684695f747d511f6d8cb611055a02b5090179fd90814b21eea876b266aba0
2 | index.html,1654105834036,f6a1f7afbeb8205ab7215e78227f83ff83ee60c3aeb6226e9dcc3c4b2aa20566
3 | favicon.ico,1654105814136,b72f7455f00e4e58792d2bca892abb068e2213838c0316d6b7a0d6d16acd1955
4 | logo192.png,1654105814137,caff018b7f1e8fd481eb1c50d75b0ef236bcd5078b1d15c8bb348453fee30293
5 | manifest.json,1654105814139,341d52628782f8ac9290bbfc43298afccb47b7cbfcee146ae30cf0f46bc30900
6 | robots.txt,1654105814140,391d14b3c2f8c9143a27a28c7399585142228d4d1bdbe2c87ac946de411fa9a2
7 | logo512.png,1654105814138,191fc21360b4ccfb1cda11a1efb97f489ed22672ca83f4064316802bbfdd750e
8 | static/css/main.1097ef92.css.map,1654105834057,4fb0f8ad942077cfe4322509684553fbbc93aabcdfc462a514e1947463239692
9 | static/css/main.1097ef92.css,1654105834057,04b20f9201c4224b77e31c43beffcd7b8631d4e0c0b9253b1a43c745ce45348a
10 | static/js/main.99b0cee0.js.LICENSE.txt,1654105834057,140fa5acd8ff7f2e15b05bcfc2c58e2b22355ba6f131e2f6d996e98711776ffb
11 | static/js/main.99b0cee0.js,1654105834057,0e83bbfe9b2b5880d8d2e51830d88b07feefeccff70ece8164fce30ba84cb790
12 | static/js/main.99b0cee0.js.map,1654105834058,b3fd5fbeafb1caf981d86aac79d6c7d1bf27fe6b44599b648c53839483475124
13 |
--------------------------------------------------------------------------------
/.firebaserc:
--------------------------------------------------------------------------------
1 | {
2 | "projects": {
3 | "default": "cryptobase-7b9b5"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Getting Started with Create React App
2 |
3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4 |
5 | ## Available Scripts
6 |
7 | In the project directory, you can run:
8 |
9 | ### `yarn start`
10 |
11 | Runs the app in the development mode.\
12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
13 |
14 | The page will reload when you make changes.\
15 | You may also see any lint errors in the console.
16 |
17 | ### `yarn test`
18 |
19 | Launches the test runner in the interactive watch mode.\
20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21 |
22 | ### `yarn build`
23 |
24 | Builds the app for production to the `build` folder.\
25 | It correctly bundles React in production mode and optimizes the build for the best performance.
26 |
27 | The build is minified and the filenames include the hashes.\
28 | Your app is ready to be deployed!
29 |
30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31 |
32 | ### `yarn eject`
33 |
34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!**
35 |
36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37 |
38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
39 |
40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
41 |
42 | ## Learn More
43 |
44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45 |
46 | To learn React, check out the [React documentation](https://reactjs.org/).
47 |
48 | ### Code Splitting
49 |
50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51 |
52 | ### Analyzing the Bundle Size
53 |
54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55 |
56 | ### Making a Progressive Web App
57 |
58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59 |
60 | ### Advanced Configuration
61 |
62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63 |
64 | ### Deployment
65 |
66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67 |
68 | ### `yarn build` fails to minify
69 |
70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
71 |
--------------------------------------------------------------------------------
/firebase.json:
--------------------------------------------------------------------------------
1 | {
2 | "hosting": {
3 | "public": "build",
4 | "ignore": [
5 | "firebase.json",
6 | "**/.*",
7 | "**/node_modules/**"
8 | ],
9 | "rewrites": [
10 | {
11 | "source": "**",
12 | "destination": "/index.html"
13 | }
14 | ]
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "crypto-project",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^5.14.1",
7 | "@testing-library/react": "^13.0.0",
8 | "@testing-library/user-event": "^13.2.1",
9 | "axios": "^0.27.2",
10 | "dompurify": "^2.3.8",
11 | "firebase": "^9.8.2",
12 | "react": "^18.1.0",
13 | "react-dom": "^18.1.0",
14 | "react-icons": "^4.3.1",
15 | "react-router-dom": "^6.3.0",
16 | "react-scripts": "5.0.1",
17 | "react-sparklines": "^1.7.0",
18 | "web-vitals": "^2.1.0"
19 | },
20 | "scripts": {
21 | "start": "react-scripts start",
22 | "build": "react-scripts build",
23 | "test": "react-scripts test",
24 | "eject": "react-scripts eject"
25 | },
26 | "eslintConfig": {
27 | "extends": [
28 | "react-app",
29 | "react-app/jest"
30 | ]
31 | },
32 | "browserslist": {
33 | "production": [
34 | ">0.2%",
35 | "not dead",
36 | "not op_mini all"
37 | ],
38 | "development": [
39 | "last 1 chrome version",
40 | "last 1 firefox version",
41 | "last 1 safari version"
42 | ]
43 | },
44 | "devDependencies": {
45 | "autoprefixer": "^10.4.7",
46 | "postcss": "^8.4.14",
47 | "tailwindcss": "^3.0.24"
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/postcss.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | plugins: {
3 | tailwindcss: {},
4 | autoprefixer: {},
5 | },
6 | }
7 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fireclint/crypto-react-firebase/a60602687a2578477fca75a8dc9d606e152210a2/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | React App
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fireclint/crypto-react-firebase/a60602687a2578477fca75a8dc9d606e152210a2/public/logo192.png
--------------------------------------------------------------------------------
/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fireclint/crypto-react-firebase/a60602687a2578477fca75a8dc9d606e152210a2/public/logo512.png
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from 'react';
2 | import { Route, Routes } from 'react-router-dom';
3 | import Navbar from './components/Navbar';
4 | import { ThemeProvider } from './context/ThemeContext';
5 | import Home from './routes/Home';
6 | import Signin from './routes/Signin';
7 | import Signup from './routes/Signup';
8 | import Account from './routes/Account';
9 | import axios from 'axios';
10 | import CoinPage from './routes/CoinPage';
11 | import Footer from './components/Footer';
12 | import { AuthContextProvider } from './context/AuthContext';
13 |
14 | function App() {
15 | const [coins, setCoins] = useState([]);
16 |
17 | const url =
18 | 'https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=10&page=1&sparkline=true';
19 |
20 | useEffect(() => {
21 | axios.get(url).then((response) => {
22 | setCoins(response.data);
23 | // console.log(response.data)
24 | });
25 | }, [url]);
26 |
27 | return (
28 |
29 |
30 |
31 |
32 | } />
33 | } />
34 | } />
35 | } />
36 | }>
37 |
38 |
39 |
40 |
41 |
42 |
43 | );
44 | }
45 |
46 | export default App;
47 |
--------------------------------------------------------------------------------
/src/components/CoinItem.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import { AiFillStar, AiOutlineStar } from 'react-icons/ai';
3 | import { Link } from 'react-router-dom';
4 | import { Sparklines, SparklinesLine } from 'react-sparklines';
5 | import { UserAuth } from '../context/AuthContext';
6 | import { db } from '../firebase';
7 | import { arrayUnion, doc, updateDoc } from 'firebase/firestore';
8 |
9 | const CoinItem = ({ coin }) => {
10 | const [savedCoin, setSavedCoin] = useState(false);
11 | const { user } = UserAuth();
12 |
13 | const coinPath = doc(db, 'users', `${user?.email}`);
14 | const saveCoin = async () => {
15 | if (user?.email) {
16 | setSavedCoin(true);
17 | await updateDoc(coinPath, {
18 | watchList: arrayUnion({
19 | id: coin.id,
20 | name: coin.name,
21 | image: coin.image,
22 | rank: coin.market_cap_rank,
23 | symbol: coin.symbol,
24 | }),
25 | });
26 | } else {
27 | alert('Please sign in to save a coin to your watch list');
28 | }
29 | };
30 |
31 | return (
32 |
33 |
34 | {savedCoin ? : }
35 | |
36 | {coin.market_cap_rank} |
37 |
38 |
39 |
40 | 
45 | {coin.name}
46 |
47 |
48 | |
49 | {coin.symbol.toUpperCase()} |
50 | ${coin.current_price.toLocaleString()} |
51 |
52 | {coin.price_change_percentage_24h > 0 ? (
53 |
54 | {coin.price_change_percentage_24h.toFixed(2)}%
55 |
56 | ) : (
57 |
58 | {coin.price_change_percentage_24h.toFixed(2)}%
59 |
60 | )}
61 | |
62 |
63 | ${coin.total_volume.toLocaleString()}
64 | |
65 |
66 | ${coin.market_cap.toLocaleString()}
67 | |
68 |
69 |
70 |
71 |
72 | |
73 |
74 | );
75 | };
76 |
77 | export default CoinItem;
78 |
--------------------------------------------------------------------------------
/src/components/CoinSearch.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import CoinItem from './CoinItem';
3 |
4 | const CoinSearch = ({ coins }) => {
5 | const [searchText, setSearchText] = useState('');
6 | console.log(coins)
7 | return (
8 |
9 |
10 |
Search Crypto
11 |
19 |
20 |
21 |
22 |
23 |
24 | |
25 | # |
26 | Coin |
27 | |
28 | Price |
29 | 24h |
30 | 24h Volume |
31 | Mkt |
32 | Last 7 Days |
33 |
34 |
35 |
36 | {coins
37 | .filter((value) => {
38 | if (searchText === '') {
39 | return value;
40 | } else if (
41 | value.name.toLowerCase().includes(searchText.toLowerCase())
42 | ) {
43 | return value;
44 | }
45 | })
46 | .map((coin) => (
47 |
48 | ))}
49 |
50 |
51 |
52 | );
53 | };
54 |
55 | export default CoinSearch;
56 |
--------------------------------------------------------------------------------
/src/components/Footer.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { AiOutlineInstagram } from 'react-icons/ai';
3 | import {
4 | FaFacebookF,
5 | FaGit,
6 | FaGithub,
7 | FaTiktok,
8 | FaTwitter,
9 | } from 'react-icons/fa';
10 | import ThemeToggle from './ThemeToggle';
11 |
12 | const Footer = () => {
13 | return (
14 |
15 |
16 |
17 |
18 |
Support
19 |
20 | - Help Center
21 | - Contact Us
22 | - API Status
23 | - Documentation
24 |
25 |
26 |
27 |
Info
28 |
29 | - About Us
30 | - Careers
31 | - Invest
32 | - Legal
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
Sign up for crypto news
43 |
44 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
Powered by Coin Gecko
61 |
62 | );
63 | };
64 |
65 | export default Footer;
66 |
--------------------------------------------------------------------------------
/src/components/Navbar.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import { Link, useNavigate } from 'react-router-dom';
3 | import ThemeToggle from './ThemeToggle';
4 | import { AiOutlineClose, AiOutlineMenu } from 'react-icons/ai';
5 | import { UserAuth } from '../context/AuthContext';
6 |
7 | const Navbar = () => {
8 | const [nav, setNav] = useState(false);
9 | const { user, logout } = UserAuth();
10 | const navigate = useNavigate();
11 |
12 | const handleNav = () => {
13 | setNav(!nav);
14 | };
15 |
16 | const handleSignOut = async () => {
17 | try {
18 | await logout();
19 | navigate('/');
20 | } catch (e) {
21 | console.log(e.message);
22 | }
23 | };
24 |
25 | return (
26 |
27 |
28 |
Cryptobase
29 |
30 |
31 |
32 |
33 |
34 | {user?.email ? (
35 |
36 |
37 | Account
38 |
39 |
40 |
41 | ) : (
42 |
43 |
44 | Sign In
45 |
46 |
50 | Sign Up
51 |
52 |
53 | )}
54 |
55 | {/* Menu Icon */}
56 |
59 |
60 | {/* Mobile Menu */}
61 |
68 |
69 | -
70 | Home
71 |
72 | -
73 | Account
74 |
75 | -
76 |
77 |
78 |
79 |
80 |
81 |
87 |
88 |
89 |
92 |
93 |
94 |
95 |
96 | );
97 | };
98 |
99 | export default Navbar;
100 |
--------------------------------------------------------------------------------
/src/components/SavedCoin.jsx:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from 'react';
2 | import { AiOutlineClose } from 'react-icons/ai';
3 | import { Link } from 'react-router-dom';
4 | import { doc, onSnapshot, updateDoc } from 'firebase/firestore';
5 | import { db } from '../firebase';
6 | import { UserAuth } from '../context/AuthContext';
7 |
8 | const SavedCoin = () => {
9 | const [coins, setCoins] = useState([]);
10 | const { user } = UserAuth();
11 |
12 | useEffect(() => {
13 | onSnapshot(doc(db, 'users', `${user?.email}`), (doc) => {
14 | setCoins(doc.data()?.watchList);
15 | });
16 | }, [user?.email]);
17 |
18 | const coinPath = doc(db, 'users', `${user?.email}`);
19 | const deleteCoin = async (passedid) => {
20 | try {
21 | const result = coins.filter((item) => item.id !== passedid);
22 | await updateDoc(coinPath, {
23 | watchList: result,
24 | });
25 | } catch (e) {
26 | console.log(e.message);
27 | }
28 | };
29 |
30 | return (
31 |
32 | {coins?.length === 0 ? (
33 |
34 | You don't have any coins saved. Please save a coin to add it to your
35 | watch list. Click here to search coins.
36 |
37 | ) : (
38 |
39 |
40 |
41 | Rank # |
42 | Coin |
43 | Remove |
44 |
45 |
46 |
47 | {coins?.map((coin) => (
48 |
49 | {coin?.rank} |
50 |
51 |
52 |
53 | 
54 |
55 | {coin?.name}
56 |
57 | {coin?.symbol.toUpperCase()}
58 |
59 |
60 |
61 |
62 | |
63 |
64 | deleteCoin(coin.id)}
66 | className='cursor-pointer'
67 | />
68 | |
69 |
70 | ))}
71 |
72 |
73 | )}
74 |
75 | );
76 | };
77 |
78 | export default SavedCoin;
79 |
--------------------------------------------------------------------------------
/src/components/ThemeToggle.jsx:
--------------------------------------------------------------------------------
1 | import React, { useContext } from 'react';
2 | import { HiSun, HiMoon } from 'react-icons/hi';
3 | import { ThemeContext } from '../context/ThemeContext';
4 |
5 | const ThemeToggle = () => {
6 | const { theme, setTheme } = useContext(ThemeContext);
7 |
8 | return (
9 |
10 | {theme === 'dark' ? (
11 |
setTheme(theme === 'dark' ? 'light' : 'dark')}>
12 | Light Mode
13 |
14 | ) : (
15 |
setTheme(theme === 'dark' ? 'light' : 'dark')}>
16 | Dark Mode
17 |
18 | )}
19 |
20 | );
21 | };
22 |
23 | export default ThemeToggle;
24 |
--------------------------------------------------------------------------------
/src/components/Trending.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect } from 'react';
2 | import axios from 'axios';
3 |
4 | const Trending = () => {
5 | const [trending, setTrending] = useState([]);
6 |
7 | const url = 'https://api.coingecko.com/api/v3/search/trending';
8 |
9 | useEffect(() => {
10 | axios.get(url).then((response) => {
11 | setTrending(response.data.coins);
12 | // console.log(response.data.coins)
13 | });
14 | }, []);
15 |
16 | return (
17 |
18 |
Trending Coins
19 |
20 | {trending.map((coin, idx) => (
21 |
22 |
23 |
24 |

29 |
30 |
{coin.item.name}
31 |
{coin.item.symbol}
32 |
33 |
34 |
35 |

40 |
{coin.item.price_btc.toFixed(7)}
41 |
42 |
43 |
44 | ))}
45 |
46 |
47 | );
48 | };
49 |
50 | export default Trending;
51 |
--------------------------------------------------------------------------------
/src/context/AuthContext.jsx:
--------------------------------------------------------------------------------
1 | import { createContext, useContext, useState, useEffect } from 'react';
2 | import { auth, db } from '../firebase';
3 | import {
4 | createUserWithEmailAndPassword,
5 | signInWithEmailAndPassword,
6 | signOut,
7 | onAuthStateChanged,
8 | } from 'firebase/auth';
9 |
10 | import { doc, setDoc } from 'firebase/firestore';
11 |
12 | const UserContext = createContext();
13 |
14 | export const AuthContextProvider = ({ children }) => {
15 | const [user, setUser] = useState({});
16 |
17 | const signUp = (email, password) => {
18 | createUserWithEmailAndPassword(auth, email, password);
19 | return setDoc(doc(db, 'users', email), {
20 | watchList: [],
21 | });
22 | };
23 | const signIn = (email, password) => {
24 | return signInWithEmailAndPassword(auth, email, password);
25 | };
26 |
27 | const logout = () => {
28 | return signOut(auth);
29 | };
30 |
31 | useEffect(() => {
32 | const unsubscribe = onAuthStateChanged(auth, (currentUser) => {
33 | setUser(currentUser);
34 | });
35 | return () => {
36 | unsubscribe();
37 | };
38 | }, []);
39 |
40 | return (
41 |
42 | {children}
43 |
44 | );
45 | };
46 |
47 | export const UserAuth = () => {
48 | return useContext(UserContext);
49 | };
50 |
--------------------------------------------------------------------------------
/src/context/ThemeContext.jsx:
--------------------------------------------------------------------------------
1 | import React, {useState, useEffect, createContext} from 'react'
2 |
3 | const getInitialTheme = () => {
4 | if (typeof window !== 'undefined' && window.localStorage) {
5 | const storedPrefs = window.localStorage.getItem('color-theme')
6 | if (typeof storedPrefs === 'string') {
7 | return storedPrefs
8 | }
9 |
10 | const userMedia = window.matchMedia('(prefers-color-scheme: dark)')
11 | if (userMedia.matches) {
12 | return 'dark'
13 | }
14 | }
15 | return 'light'
16 | }
17 |
18 | export const ThemeContext = createContext()
19 |
20 | export const ThemeProvider = ({initialTheme, children}) => {
21 | const [theme, setTheme] = useState(getInitialTheme)
22 |
23 | const rawSetTheme = (theme) => {
24 | const root = window.document.documentElement;
25 | const isDark = theme === 'dark'
26 |
27 | root.classList.remove(isDark ? 'light' : 'dark')
28 | root.classList.add(theme)
29 |
30 | localStorage.setItem('color-theme', theme)
31 | }
32 |
33 | if (initialTheme) {
34 | rawSetTheme(initialTheme)
35 | }
36 |
37 | useEffect(()=> {
38 | rawSetTheme(theme)
39 | },[theme])
40 |
41 | return (
42 |
43 | {children}
44 |
45 | )
46 | }
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/src/firebase.js:
--------------------------------------------------------------------------------
1 | // Import the functions you need from the SDKs you need
2 | import { initializeApp } from 'firebase/app';
3 | import { getAuth } from 'firebase/auth';
4 | import { getFirestore } from 'firebase/firestore';
5 | // TODO: Add SDKs for Firebase products that you want to use
6 | // https://firebase.google.com/docs/web/setup#available-libraries
7 |
8 | // Your web app's Firebase configuration
9 | const firebaseConfig = {
10 | apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
11 | authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
12 | projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
13 | storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
14 | messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER,
15 | appId: process.env.REACT_APP_FIREBASE_APP_ID,
16 | };
17 |
18 | // Initialize Firebase
19 | const app = initializeApp(firebaseConfig);
20 | export const auth = getAuth(app);
21 | export const db = getFirestore(app);
22 |
23 | export default app;
24 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | @tailwind base;
2 | @tailwind components;
3 | @tailwind utilities;
4 |
5 | :root {
6 | @apply bg-primary text-primary
7 | }
8 |
9 | .rounded-div {
10 | @apply border border-secondary rounded-2xl shadow-xl bg-primary px-2 max-w-[1140px] w-full mx-auto
11 | }
12 |
13 | .dark {
14 | --color-bg-primary: #2d3748;
15 | --color-bg-primary: #2d3748;
16 | --color-bg-secondary: #283141;
17 | --color-text-primary: #dbdbdb;
18 | --color-text-secondary: #e2e8f0;
19 | --color-text-accent: #81e6d9;
20 | --color-bg-input: #4a5361;
21 | --color-bg-button: #81e6d9;
22 | }
23 |
24 | .light {
25 | --color-bg-primary: #ffffff;
26 | --color-bg-secondary: #edf2f7;
27 | --color-text-primary: #2d3748;
28 | --color-text-secondary: #4a5568;
29 | --color-text-accent: #2b6cb0;
30 | --color-bg-input: #edf2f7;
31 | --color-bg-button: #2b6cb0;
32 | }
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom/client';
3 | import './index.css';
4 | import App from './App';
5 | import { BrowserRouter } from 'react-router-dom';
6 |
7 | const root = ReactDOM.createRoot(document.getElementById('root'));
8 | root.render(
9 |
10 |
11 |
12 | );
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/routes/Account.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import SavedCoin from '../components/SavedCoin';
3 | import { UserAuth } from '../context/AuthContext';
4 | import { Navigate, useNavigate } from 'react-router-dom';
5 |
6 | const Account = () => {
7 | const { user, logout } = UserAuth();
8 | const navigate = useNavigate();
9 |
10 | const handleSignOut = async () => {
11 | try {
12 | await logout();
13 | navigate('/');
14 | } catch (e) {
15 | console.log(e.message);
16 | }
17 | };
18 |
19 | if (user) {
20 | return (
21 |
22 |
23 |
24 |
Account
25 |
26 |
Welcome, {user?.email}
27 |
28 |
29 |
30 |
36 |
37 |
38 |
39 |
40 |
Watch List
41 |
42 |
43 |
44 |
45 | );
46 | } else {
47 | return ;
48 | }
49 | };
50 |
51 | export default Account;
52 |
--------------------------------------------------------------------------------
/src/routes/CoinPage.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect } from 'react';
2 | import axios from 'axios';
3 | import { Sparklines, SparklinesLine } from 'react-sparklines';
4 | import { FaTwitter, FaFacebook, FaReddit, FaGithub } from 'react-icons/fa';
5 | import DOMPurify from 'dompurify'
6 | import { useParams } from 'react-router-dom';
7 |
8 | const CoinPage = () => {
9 | const [coin, setCoin] = useState({});
10 | const params = useParams()
11 |
12 | const url =
13 | `https://api.coingecko.com/api/v3/coins/${params.coinId}?localization=false&sparkline=true`;
14 |
15 | useEffect(() => {
16 | axios.get(url).then((response) => {
17 | setCoin(response.data);
18 | console.log(response.data);
19 | });
20 | }, [url]);
21 |
22 | return (
23 |
24 |
25 |

26 |
27 |
{coin?.name} price
28 |
({coin.symbol?.toUpperCase()} / USD)
29 |
30 |
31 |
32 |
33 |
34 |
35 | {coin.market_data?.current_price ? (
36 |
${coin.market_data.current_price.usd.toLocaleString()}
37 | ) : null}
38 |
7 Day
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
Market Cap
48 | {coin.market_data?.market_cap ? (
49 |
${coin.market_data.market_cap.usd.toLocaleString()}
50 | ) : null}
51 |
52 |
53 |
Volume (24h)
54 | {coin.market_data?.market_cap ? (
55 |
${coin.market_data.total_volume.usd.toLocaleString()}
56 | ) : null}
57 |
58 |
59 |
60 |
61 |
62 |
24h High
63 | {coin.market_data?.high_24h ? (
64 |
${coin.market_data.high_24h.usd.toLocaleString()}
65 | ) : null}
66 |
67 |
68 |
24h Low
69 | {coin.market_data?.low_24h ? (
70 |
${coin.market_data.low_24h.usd.toLocaleString()}
71 | ) : null}
72 |
73 |
74 |
75 |
76 |
77 |
Market Stats
78 |
79 |
80 |
Market Rank
81 | {coin.market_cap_rank}
82 |
83 |
84 |
Hashing Algorithm
85 | {coin.hashing_algorithm ?
{coin.hashing_algorithm}
: null}
86 |
87 |
88 |
Trust Score
89 | {coin.tickers ?
{coin.liquidity_score.toFixed(2)}
: null}
90 |
91 |
92 |
93 |
94 |
95 |
Price Change (24h)
96 | {coin.market_data ? (
97 |
98 | {coin.market_data.price_change_percentage_24h.toFixed(2)}%
99 |
100 | ) : null}
101 |
102 |
103 |
Price Change (7d)
104 | {coin.market_data ? (
105 |
{coin.market_data.price_change_percentage_7d.toFixed(2)}%
106 | ) : null}
107 |
108 |
109 |
Price Change (14d)
110 | {coin.market_data ? (
111 |
112 | {coin.market_data.price_change_percentage_14d.toFixed(2)}%
113 |
114 | ) : null}
115 |
116 |
117 |
118 |
119 |
Price Change (30d)
120 | {coin.market_data ? (
121 |
122 | {coin.market_data.price_change_percentage_30d.toFixed(2)}%
123 |
124 | ) : null}
125 |
126 |
127 |
Price Change (60d)
128 | {coin.market_data ? (
129 |
130 | {coin.market_data.price_change_percentage_60d.toFixed(2)}%
131 |
132 | ) : null}
133 |
134 |
135 |
Price Change (1y)
136 | {coin.market_data ? (
137 |
{coin.market_data.price_change_percentage_1y.toFixed(2)}%
138 | ) : null}
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 | {/* Description */}
151 |
152 |
About {coin.name}
153 |
154 |
155 |
156 | );
157 | };
158 |
159 | export default CoinPage;
160 |
--------------------------------------------------------------------------------
/src/routes/Home.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import CoinSearch from '../components/CoinSearch'
3 | import Trending from '../components/Trending'
4 |
5 | const Home = ({coins}) => {
6 | return (
7 |
8 |
9 |
10 |
11 | )
12 | }
13 |
14 | export default Home
--------------------------------------------------------------------------------
/src/routes/Signin.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import { AiFillLock, AiOutlineMail } from 'react-icons/ai';
3 | import { Link, useNavigate } from 'react-router-dom';
4 | import { signIn, UserAuth } from '../context/AuthContext';
5 |
6 | const Signin = () => {
7 | const [email, setEmail] = useState('');
8 | const [password, setPassword] = useState('');
9 | const [error, setError] = useState('');
10 | const navigate = useNavigate();
11 | const { signIn } = UserAuth();
12 |
13 | const handleSubmit = async (e) => {
14 | e.preventDefault();
15 | setError('');
16 | try {
17 | await signIn(email, password);
18 | navigate('/account')
19 | } catch (e) {
20 | setError(e.message);
21 | console.log(e.message);
22 | }
23 | };
24 |
25 | return (
26 |
27 |
28 |
Sign In
29 |
56 |
57 | Don't have an account?{' '}
58 |
59 | Sign up
60 |
61 |
62 |
63 |
64 | );
65 | };
66 |
67 | export default Signin;
68 |
--------------------------------------------------------------------------------
/src/routes/Signup.jsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import { AiFillLock, AiOutlineMail } from 'react-icons/ai';
3 | import { Link, useNavigate } from 'react-router-dom';
4 | import { UserAuth } from '../context/AuthContext';
5 |
6 | const Signup = () => {
7 | const [email, setEmail] = useState('');
8 | const [password, setPassword] = useState('');
9 | const [error, setError] = useState('');
10 | const navigate = useNavigate();
11 | const { signUp } = UserAuth();
12 |
13 | const handleSubmit = async (e) => {
14 | e.preventDefault()
15 | setError('')
16 | try {
17 | await signUp(email,password)
18 | navigate('/account')
19 | } catch (e) {
20 | setError(e.message)
21 | console.log(e.message)
22 | }
23 | }
24 |
25 | return (
26 |
27 |
28 |
Sign Up
29 | {error ?
{error}
: null}
30 |
57 |
58 | Already have an account?{' '}
59 |
60 | Sign in
61 |
62 |
63 |
64 |
65 | );
66 | };
67 |
68 | export default Signup;
69 |
--------------------------------------------------------------------------------
/tailwind.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | content: ['./src/**/*.{js,jsx,ts,tsx}'],
3 | darkMode: 'class',
4 | theme: {
5 | extend: {
6 | backgroundColor: {
7 | primary: 'var(--color-bg-primary)',
8 | secondary: 'var(--color-bg-secondary)',
9 | button: 'var(--color-bg-button)',
10 | },
11 | textColor: {
12 | accent: 'var(--color-text-accent)',
13 | primary: 'var(--color-text-primary)',
14 | secondary: 'var(--color-text-secondary)',
15 | btnText: 'var(--color-bg-secondary)',
16 | },
17 | borderColor: {
18 | primary: 'var(--color-bg-primary)',
19 | secondary: 'var(--color-bg-secondary)',
20 | input: 'var(--color-bg-input)',
21 | accent: 'var(--color-text-accent)',
22 | },
23 | },
24 | },
25 | plugins: [],
26 | };
27 |
--------------------------------------------------------------------------------