Skip to content

Commit 7cafa8f

Browse files
Andres BedoyaAndres Bedoya
Andres Bedoya
authored and
Andres Bedoya
committed
API change
1 parent f42e56d commit 7cafa8f

13 files changed

+104
-93
lines changed

.gitignore

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
# See https://help.github.com/ignore-files/ for more about ignoring files.
2-
31
# dependencies
42
/node_modules
53

64
# testing
75
/coverage
86

97
# production
10-
/build
8+
/dist
119

1210
# misc
1311
.DS_Store
1412
.env.local
1513
.env.development.local
1614
.env.test.local
1715
.env.production.local
16+
.cache
1817

1918
npm-debug.log*
2019
yarn-debug.log*

dist/src.7ed060e2.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/src.7ed060e2.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/src.7ed060e2.js

+21-25
Large diffs are not rendered by default.

dist/src.7ed060e2.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+30-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.js

-36
This file was deleted.
File renamed without changes.

src/components/App/App.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from "react";
2+
import Particles from "react-particles-js";
3+
import useResources from "../../hooks/useResources";
4+
import Card from "../Card/Card";
5+
import { formatNum, getCoinColor } from "../../libs/utils";
6+
import particlesConfig from "../../libs/particlesconfig";
7+
8+
import "./App.css";
9+
10+
const App = () => {
11+
const { resources, isLoading, isError } = useResources(9);
12+
13+
const mapCoins = resources.map(coin => ({
14+
name: coin.name,
15+
symbol: coin.symbol,
16+
rank: coin.rank,
17+
price: formatNum(coin.price),
18+
change24hr: coin.change,
19+
img: coin.iconUrl,
20+
color: getCoinColor(coin.symbol)
21+
}));
22+
23+
return (
24+
<div className="app">
25+
<Particles className="particles" params={particlesConfig} />
26+
<div className="container">
27+
<div className="coins">
28+
{mapCoins.map((coin, i) => (
29+
<Card coin={coin} key={i} />
30+
))}
31+
</div>
32+
</div>
33+
</div>
34+
);
35+
};
36+
37+
export default App;

src/components/Card/Card.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
}
88

99
.coin {
10+
background-color: #fff;
1011
border: 1px solid #eee;
1112
flex: 1 0 30%;
1213
margin: 9px;
@@ -25,7 +26,6 @@
2526
}
2627

2728
.card-body {
28-
background-color: #fff;
2929
padding: 10px;
3030
}
3131

src/components/Card/Card.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import React from 'react';
2-
import { getColorClass, determineSign, timeConverter } from '../../libs/utils';
3-
import './Card.css';
1+
import React from "react";
2+
import { getColorClass, determineSign } from "../../libs/utils";
3+
import "./Card.css";
44

55
const Card = ({ coin }) => {
66
const cardColorClass = getColorClass(coin.color);
77
const signCoin = determineSign(coin.change24hr);
8-
const lastUpdate = timeConverter(coin.lastUpdate);
98

109
return (
1110
<div className="coin">
@@ -19,12 +18,9 @@ const Card = ({ coin }) => {
1918
<p className="coin-value">${coin.price}</p>
2019
<span className={`coin-change ${signCoin}`}>{coin.change24hr}%</span>
2120
</div>
22-
<div>
23-
<p className="coin-last-update">Last update: {lastUpdate}</p>
24-
</div>
2521
</div>
2622
</div>
2723
);
28-
}
24+
};
2925

30-
export default Card;
26+
export default Card;

src/hooks/useResources.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ const useResources = num => {
99
try {
1010
setIsLoading(true);
1111
const response = await fetch(
12-
`https://api.coinmarketcap.com/v1/ticker/?limit=${num}`
12+
`https://api.coinranking.com/v1/public/coins?base=USD&timePeriod=24h&limit=${num}`
1313
);
1414
const jsonData = await response.json();
15-
setResources(jsonData);
15+
setResources(jsonData.data.coins);
1616
} catch (e) {
1717
setIsError(e);
1818
} finally {
@@ -39,4 +39,4 @@ const useResources = num => {
3939
};
4040
};
4141

42-
export default useResources;
42+
export default useResources;

src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import ReactDOM from "react-dom";
3-
import App from "./App";
3+
import App from "./components/App/App";
44

55
import "./style.css";
66

7-
ReactDOM.render(<App />, document.getElementById("root"));
7+
ReactDOM.render(<App />, document.getElementById("root"));

0 commit comments

Comments
 (0)