Skip to content

Commit ce162cc

Browse files
authored
Merge pull request #7 from CodeDead/feature/egld-price-calculator
feature/egld-price-calculator
2 parents e8fbe22 + 353f9ce commit ce162cc

8 files changed

Lines changed: 540 additions & 203 deletions

File tree

package.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,29 @@
1717
"@material-ui/core": "^4.11.3",
1818
"@material-ui/icons": "^4.11.2",
1919
"@material-ui/lab": "^4.0.0-alpha.57",
20-
"gatsby": "^3.0.4",
21-
"gatsby-plugin-catch-links": "^3.0.0",
22-
"gatsby-plugin-google-gtag": "^3.0.0",
23-
"gatsby-plugin-image": "^1.0.1",
20+
"axios": "^0.21.1",
21+
"gatsby": "^3.1.1",
22+
"gatsby-plugin-catch-links": "^3.1.0",
23+
"gatsby-plugin-google-gtag": "^3.1.0",
24+
"gatsby-plugin-image": "^1.1.1",
2425
"gatsby-plugin-robots-txt": "^1.5.5",
25-
"gatsby-plugin-sharp": "^3.0.1",
26-
"gatsby-plugin-sitemap": "^3.0.0",
27-
"gatsby-remark-images": "^4.0.0",
28-
"gatsby-source-filesystem": "^3.0.0",
26+
"gatsby-plugin-sharp": "^3.1.1",
27+
"gatsby-plugin-sitemap": "^3.1.0",
28+
"gatsby-remark-images": "^4.1.0",
29+
"gatsby-source-filesystem": "^3.1.0",
2930
"gatsby-theme-material-ui": "^1.0.13",
30-
"gatsby-transformer-remark": "^3.0.0",
31-
"gatsby-transformer-sharp": "^3.0.0",
32-
"react": "^17.0.1",
33-
"react-dom": "^17.0.1",
31+
"gatsby-transformer-remark": "^3.1.0",
32+
"gatsby-transformer-sharp": "^3.1.0",
33+
"react": "^17.0.2",
34+
"react-dom": "^17.0.2",
3435
"react-helmet": "^6.1.0"
3536
},
3637
"devDependencies": {
3738
"eslint": "^7.22.0",
3839
"eslint-config-airbnb": "^18.2.1",
3940
"eslint-plugin-import": "^2.22.1",
4041
"eslint-plugin-jsx-a11y": "^6.4.1",
41-
"eslint-plugin-react": "^7.22.0",
42+
"eslint-plugin-react": "^7.23.0",
4243
"eslint-plugin-react-hooks": "^4.2.0"
4344
},
4445
"repository": {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import CircularProgress from '@material-ui/core/CircularProgress';
3+
4+
const LoadingBar = () => (
5+
<div style={{
6+
display: 'flex',
7+
justifyContent: 'center',
8+
}}
9+
>
10+
<CircularProgress />
11+
</div>
12+
);
13+
14+
export default LoadingBar;

src/images/Elrond/egld.png

127 KB
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
path: "/blog/2021/03/23/egld-price-calculator"
3+
title: "Elrond (EGLD) Price Calculator"
4+
author: "CodeDead"
5+
date: "2021-03-23"
6+
abstract: "We've added a new tool to our website. This time, a cryptocurrency price calculator, specifically made for Elrond (EGLD)..."
7+
categories: "JavaScript, News, Cryptocurrency"
8+
---
9+
## Information
10+
11+
We've added a new tool to our website. This time, a cryptocurrency price calculator, specifically made for [Elrond (EGLD)](https://elrond.com).
12+
With this tool, you can retrieve the current simple price for the EGLD currency, using data retrieved from [CoinGecko](https://coingecko.com).
13+
14+
## EGLD Price Calculator
15+
16+
You can find the Elrond (EGLD) price calculator here:
17+
[EGLD Price Calculator](/software/egld-price-calculator)
18+
19+
## Other
20+
21+
Feel free to [contact us](/contact) if you have any questions or if you need help.

src/pages/privacy/index.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ const Privacy = () => {
7575
</ul>
7676

7777
<Typography gutterBottom>
78-
Take a look at google’s privacy policy to find out more. We don’t export this data to
79-
any hard drives or sell it or anything. This information is quite useful for our
80-
applications in the following sense:
78+
<a href="https://policies.google.com/" rel="noopener noreferrer" target="_blank">Take a look at google’s privacy policy to find out more.</a>
79+
We don’t export this data to any hard drives or sell it or anything. This information
80+
is quite useful for our applications in the following sense:
8181
</Typography>
8282
<ul>
8383
<li>
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
import React, { useContext, useEffect, useState } from 'react';
2+
import {
3+
Card,
4+
Container, FormControl, InputLabel, MenuItem, Select, TextField,
5+
} from '@material-ui/core';
6+
import axios from 'axios';
7+
import Grid from '@material-ui/core/Grid';
8+
import CardContent from '@material-ui/core/CardContent';
9+
import MuiAlert from '@material-ui/lab/Alert';
10+
import Snackbar from '@material-ui/core/Snackbar';
11+
import { setPageIndex } from '../../../reducers/MainReducer/Actions';
12+
import PageHeader from '../../../components/PageHeader';
13+
import Layout from '../../../components/Layout';
14+
import { MainContext } from '../../../contexts/MainContextProvider';
15+
import LoadingBar from '../../../components/LoadingBar';
16+
17+
const EgldPriceCalculator = () => {
18+
const [, dispatch] = useContext(MainContext);
19+
20+
const [pricePerEgld, setPricePerEgld] = useState(null);
21+
const [currency, setCurrency] = useState('usd');
22+
const [supportedCurrencies, setSupportedCurrencies] = useState(null);
23+
24+
const [egld, setEgld] = useState(1);
25+
const [currencyAmount, setCurrencyAmount] = useState(0);
26+
27+
const [loading, setLoading] = useState(false);
28+
const [error, setError] = useState(null);
29+
30+
/**
31+
* Close the snackbar
32+
*/
33+
const closeSnackbar = () => {
34+
setError(null);
35+
};
36+
37+
/**
38+
* Get a list of supported currencies
39+
* @param override True if the loading indicator should be ignored, otherwise false
40+
*/
41+
const getSupportedCurrencies = (override) => {
42+
if (loading && !override) return;
43+
44+
setLoading(true);
45+
setError(null);
46+
setSupportedCurrencies(null);
47+
48+
axios.get('https://api.coingecko.com/api/v3/simple/supported_vs_currencies')
49+
.then((res) => {
50+
setSupportedCurrencies(res.data);
51+
})
52+
.catch((err) => {
53+
setError(err);
54+
})
55+
.finally(() => {
56+
setLoading(false);
57+
});
58+
};
59+
60+
/**
61+
* Get the price for EGLD
62+
* @param override True if the loading indicator should be ignored, otherwise false
63+
* @param changeEgld Change the EGLD amount or not
64+
* @param newCurrency The currency for which the price should be retrieved
65+
*/
66+
const getEgldPrice = (override, changeEgld, newCurrency) => {
67+
if (loading && !override) return;
68+
69+
setLoading(true);
70+
setError(null);
71+
setPricePerEgld(null);
72+
73+
axios.get(`https://api.coingecko.com/api/v3/simple/price?ids=elrond-erd-2&vs_currencies=${newCurrency}`)
74+
.then((res) => {
75+
const values = Object.values(res.data['elrond-erd-2']);
76+
const ppegld = parseFloat(values[0]);
77+
78+
setPricePerEgld(ppegld);
79+
if (changeEgld) {
80+
setEgld((1 / ppegld) * currencyAmount);
81+
} else {
82+
setCurrencyAmount(egld * ppegld);
83+
}
84+
})
85+
.catch((err) => {
86+
setError(err);
87+
})
88+
.finally(() => {
89+
setLoading(false);
90+
});
91+
};
92+
93+
/**
94+
* Change the EGLD amount
95+
* @param e
96+
*/
97+
const changeEgldAmount = (e) => {
98+
if (e.target.value < 0) return;
99+
100+
setEgld(e.target.value);
101+
setCurrencyAmount(e.target.value * pricePerEgld);
102+
};
103+
104+
/**
105+
* Change the amount of the selected currency
106+
* @param e The event argument
107+
*/
108+
const changeCurrencyAmount = (e) => {
109+
if (e.target.value < 0) return;
110+
111+
setEgld((1 / pricePerEgld) * e.target.value);
112+
setCurrencyAmount(e.target.value);
113+
};
114+
115+
/**
116+
* Change the currency
117+
* @param e The event argument
118+
*/
119+
const changeCurrency = (e) => {
120+
if (!e.target.value) return;
121+
122+
setCurrency(e.target.value);
123+
getEgldPrice(false, false, e.target.value);
124+
};
125+
126+
useEffect(() => {
127+
dispatch(setPageIndex(-1));
128+
getSupportedCurrencies(false);
129+
getEgldPrice(true, false, currency);
130+
}, []);
131+
132+
return (
133+
<Layout>
134+
<PageHeader title="Elrond (EGLD) Price Calculator" subTitle="Simple Elrond (EGLD) price calculator" />
135+
<Container maxWidth="md" style={{ marginTop: 10 }}>
136+
<Card>
137+
<CardContent>
138+
{loading ? <LoadingBar /> : (
139+
<Grid container spacing={2}>
140+
<Grid item xs={12} md={12} lg={12}>
141+
<Grid container>
142+
<Grid item xs={12} md={10} lg={10}>
143+
<TextField
144+
variant="outlined"
145+
label="Amount"
146+
value={egld}
147+
type="number"
148+
fullWidth
149+
onChange={changeEgldAmount}
150+
/>
151+
</Grid>
152+
<Grid item xs={12} md={2} lg={2}>
153+
<FormControl
154+
variant="outlined"
155+
fullWidth
156+
>
157+
<InputLabel>Currency</InputLabel>
158+
<Select
159+
value="egld"
160+
label="Currency"
161+
fullWidth
162+
>
163+
<MenuItem value="egld">
164+
<em>EGLD</em>
165+
</MenuItem>
166+
</Select>
167+
</FormControl>
168+
</Grid>
169+
</Grid>
170+
</Grid>
171+
<Grid item xs={12} md={12} lg={12}>
172+
<Grid container>
173+
<Grid item xs={12} md={10} lg={10}>
174+
<TextField
175+
variant="outlined"
176+
label="Amount"
177+
value={currencyAmount}
178+
type="number"
179+
fullWidth
180+
onChange={changeCurrencyAmount}
181+
/>
182+
</Grid>
183+
<Grid item xs={12} md={2} lg={2}>
184+
<FormControl
185+
variant="outlined"
186+
fullWidth
187+
>
188+
<InputLabel>Currency</InputLabel>
189+
<Select
190+
value={currency}
191+
label="Currency"
192+
fullWidth
193+
onChange={changeCurrency}
194+
>
195+
<MenuItem value="">
196+
Select a currency
197+
</MenuItem>
198+
{supportedCurrencies && supportedCurrencies.length > 0
199+
? supportedCurrencies.map((item) => (
200+
<MenuItem
201+
key={item}
202+
value={item}
203+
>
204+
{item.toUpperCase()}
205+
</MenuItem>
206+
)) : null}
207+
</Select>
208+
</FormControl>
209+
</Grid>
210+
</Grid>
211+
</Grid>
212+
</Grid>
213+
)}
214+
</CardContent>
215+
</Card>
216+
</Container>
217+
<Snackbar open={!!error} autoHideDuration={6000} onClose={closeSnackbar}>
218+
{error
219+
? (
220+
<MuiAlert elevation={6} variant="filled" severity="error" onClose={closeSnackbar}>
221+
{error.message}
222+
</MuiAlert>
223+
)
224+
: null}
225+
</Snackbar>
226+
</Layout>
227+
);
228+
};
229+
230+
export default EgldPriceCalculator;

src/pages/software/index.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ const Software = () => {
6060
childImageSharp {
6161
gatsbyImageData(layout: CONSTRAINED, height: 160)
6262
}
63+
},
64+
egld: file(relativePath: { eq: "Elrond/egld.png" }) {
65+
childImageSharp {
66+
gatsbyImageData(layout: CONSTRAINED, height: 160)
67+
}
6368
}
6469
}`);
6570

@@ -111,6 +116,12 @@ const Software = () => {
111116
description: 'AniView is a free and open source GIF image viewer. You can watch GIF images your way, thanks to all the options that are available in AniView.',
112117
tags: ['AniView', 'images', 'GIF', 'viewer'],
113118
image: imageData.aniview.childImageSharp.gatsbyImageData,
119+
}, {
120+
name: 'EGLD Price Calculator',
121+
url: '/software/egld-price-calculator',
122+
description: 'A simple and easy to use price calculator for Elrond (EGLD).',
123+
tags: ['egld', 'elrond', 'currency', 'Crypto'],
124+
image: imageData.egld.childImageSharp.gatsbyImageData,
114125
}];
115126

116127
useEffect(() => {
@@ -312,6 +323,14 @@ const Software = () => {
312323
image={applications.filter((item) => item.name === 'AniView')[0].image}
313324
/>
314325
</Grid>
326+
<Grid item xs={12} md={3} lg={4}>
327+
<Application
328+
name={applications.filter((item) => item.name === 'EGLD Price Calculator')[0].name}
329+
description={applications.filter((item) => item.name === 'EGLD Price Calculator')[0].description}
330+
url={applications.filter((item) => item.name === 'EGLD Price Calculator')[0].url}
331+
image={applications.filter((item) => item.name === 'EGLD Price Calculator')[0].image}
332+
/>
333+
</Grid>
315334
</Grid>
316335
</>
317336
)}

0 commit comments

Comments
 (0)