diff --git a/README.md b/README.md
index 7b3b1d4b..4966021d 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,6 @@
@@ -176,15 +187,16 @@ export default class Web3Donation extends PureComponent {
Send Ether with MetaMask, Brave, or Mist.
- {this.state.web3Connected && (
+ {web3Connected && (
- {this.state.loading ? (
+ {loading ? (
'Hang on...'
) : (
@@ -195,10 +207,10 @@ export default class Web3Donation extends PureComponent {
)
diff --git a/src/components/Web3Donation/utils.js b/src/components/Web3Donation/utils.js
index 92ccdd51..3e870dc1 100644
--- a/src/components/Web3Donation/utils.js
+++ b/src/components/Web3Donation/utils.js
@@ -23,3 +23,41 @@ export const getNetworkName = async netId => {
return networkName
}
+
+export const getFiat = async amount => {
+ const url = 'https://api.coinmarketcap.com/v1/ticker/ethereum/?convert=EUR'
+
+ try {
+ const response = await fetch(url)
+ if (!response.ok) {
+ throw Error(response.statusText)
+ }
+ const data = await response.json()
+ const { price_usd, price_eur } = data[0]
+ const dollar = (amount * price_usd).toFixed(2)
+ const euro = (amount * price_eur).toFixed(2)
+
+ return { dollar, euro }
+ } catch (error) {
+ Logger.error(error)
+ }
+}
+
+export class Logger {
+ static dispatch(verb, ...args) {
+ // eslint-disable-next-line no-console
+ console[verb](...args)
+ }
+
+ static log(...args) {
+ Logger.dispatch('log', ...args)
+ }
+
+ static debug(...args) {
+ Logger.dispatch('debug', ...args)
+ }
+
+ static error(...args) {
+ Logger.dispatch('error', ...args)
+ }
+}