Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #34 from derogab/dev
Browse files Browse the repository at this point in the history
Fix API
  • Loading branch information
derogab authored Aug 30, 2020
2 parents a906f6d + 4104dc0 commit ccd7b14
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 143 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
yarn.lock
daemon
assets
Dockerfile
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
COPY package.json ./
COPY yarn.lock ./
RUN yarn

# Copy app
Expand Down
1 change: 0 additions & 1 deletion daemon/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
yarn.lock
data
db.json
Dockerfile
Expand Down
3 changes: 2 additions & 1 deletion daemon/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ WORKDIR /usr/src/app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
COPY package.json ./
COPY yarn.lock ./
RUN yarn

# Copy app
Expand Down
2 changes: 1 addition & 1 deletion daemon/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var argv = require('minimist')(process.argv.slice(2));
*
*/
const config = {
url: 'https://api.coinmarketcap.com/v1/ticker/',
url: 'https://api.coingecko.com/api/v3/coins/',
timeout: argv.timeout || process.env.TIMEOUT || 180,
db: argv.db || process.env.DATABASE || 'db.json',
cryptocurrencies: (argv.crypto || process.env.CRYPTOCURRENCIES).split(',')
Expand Down
4 changes: 3 additions & 1 deletion daemon/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "coingraph-daemon",
"version": "1.1.2",
"version": "1.1.3",
"author": "derogab",
"description": "A daemon for coingraph",
"license": "MIT",
"main": "app.js",
"dependencies": {
"axios": "^0.19.0",
Expand Down
26 changes: 13 additions & 13 deletions daemon/routes/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = function(db, io, app, config) {
})
.then(function (response) {

var data = response.data[0];
var data = response.data;

// save on db
var handler = db.get('cryptocurrencies').find({'id': crypto});
Expand All @@ -29,11 +29,11 @@ module.exports = function(db, io, app, config) {
handler.assign({name: data.name}).write();
handler.assign({symbol: data.symbol}).write();
handler.value().data.push({
"price_usd": parseFloat(data.price_usd),
"percent_change_1h": parseFloat(data.percent_change_1h),
"percent_change_24h": parseFloat(data.percent_change_24h),
"percent_change_7d": parseFloat(data.percent_change_7d),
"last_updated": parseInt(data.last_updated)
"price_usd": parseFloat(data.market_data.current_price.usd),
"percent_change_1h": parseFloat(data.market_data.price_change_percentage_1h_in_currency.usd),
"percent_change_24h": parseFloat(data.market_data.price_change_percentage_24h),
"percent_change_7d": parseFloat(data.market_data.price_change_percentage_7d),
"last_updated": new Date(data.market_data.last_updated).getTime()
});
db.write();

Expand All @@ -42,15 +42,15 @@ module.exports = function(db, io, app, config) {
'id': data.id,
'name': data.name,
'symbol': data.symbol,
'price_usd': parseFloat(data.price_usd),
'percent_change_1h': parseFloat(data.percent_change_1h),
'percent_change_24h': parseFloat(data.percent_change_24h),
'percent_change_7d': parseFloat(data.percent_change_7d),
'last_updated': parseInt(data.last_updated),
'price_usd': parseFloat(data.market_data.current_price.usd),
'percent_change_1h': parseFloat(data.market_data.price_change_percentage_1h_in_currency.usd),
'percent_change_24h': parseFloat(data.market_data.price_change_percentage_24h),
'percent_change_7d': parseFloat(data.market_data.price_change_percentage_7d),
'last_updated': parseInt(data.market_data.last_updated),
'graph': { // new data
'name': '',
'price': parseFloat(data.price_usd),
'time': parseInt(data.last_updated)
'price': parseFloat(data.market_data.current_price.usd),
'time': new Date(data.market_data.last_updated).getTime()
}
};
io.emit('realtime-data', realtime_data);
Expand Down
6 changes: 3 additions & 3 deletions daemon/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ [email protected]:
integrity sha1-o32U7ZzaLVmGXJ92/llu4fM4dB4=

lodash@4:
version "4.17.19"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b"
integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==
version "4.17.20"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52"
integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==

lowdb@^1.0.0:
version "1.0.0"
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "coingraph",
"version": "1.1.2",
"version": "1.1.3",
"author": "derogab",
"description": "A real-time graph for cryptocurrencies",
"license": "MIT",
"private": true,
"dependencies": {
"axios": "^0.19.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Coin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const CustomTooltip = ({ active, payload, label }) => {
if (active) {
var price = payload[0].value;
var time = label;
var ts = new Date(time * 1000);
var ts = new Date(time);

return (
<div className="custom-tooltip">
Expand Down
3 changes: 1 addition & 2 deletions src/containers/Coins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export default class CoinsContainer extends Component {
}

onNewData = (value) => {

const now = new Date(Date.now());
const one_week_ago = new Date(Date.now());
one_week_ago.setDate(one_week_ago.getDate() - 7);
Expand All @@ -44,7 +43,7 @@ export default class CoinsContainer extends Component {
const newData = {
graph: (get(coinsData, [value.id, 'graph'], []).concat(value.graph)).filter((element) => {
// only one week data show
var ttd = new Date(element.time * 1000); // time of this data
var ttd = new Date(element.time); // time of this data
if(ttd >= one_week_ago && ttd <= now) {
return true;
}
Expand Down
Loading

0 comments on commit ccd7b14

Please sign in to comment.