1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-11-26 11:49:04 +01:00

codesplitting web3 components, web3 fixes

This commit is contained in:
Matthias Kretschmann 2019-10-23 13:09:26 +02:00
parent 48fc75ec78
commit a6294e523f
Signed by: m
GPG Key ID: 606EEEF3C479A91F
5 changed files with 45 additions and 33 deletions

View File

@ -81,7 +81,7 @@
"remark-react": "^6.0.0", "remark-react": "^6.0.0",
"slugify": "^1.3.4", "slugify": "^1.3.4",
"use-dark-mode": "^2.3.1", "use-dark-mode": "^2.3.1",
"web3": "^1.2.1" "web3": "^1.2.2"
}, },
"devDependencies": { "devDependencies": {
"@babel/node": "^7.6.3", "@babel/node": "^7.6.3",
@ -133,9 +133,6 @@
"typescript": "^3.6.4", "typescript": "^3.6.4",
"why-did-you-update": "^1.0.6" "why-did-you-update": "^1.0.6"
}, },
"engines": {
"node": ">=10.0.0"
},
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/kremalicious/blog.git" "url": "https://github.com/kremalicious/blog.git"

View File

@ -1,5 +1,5 @@
import React, { PureComponent } from 'react' import React, { PureComponent } from 'react'
import { getFiat } from './utils' import { getFiat, Logger } from './utils'
import styles from './Conversion.module.scss' import styles from './Conversion.module.scss'
export default class Conversion extends PureComponent< export default class Conversion extends PureComponent<
@ -24,20 +24,21 @@ export default class Conversion extends PureComponent<
} }
async getFiatResponse() { async getFiatResponse() {
const { dollar, euro } = await getFiat(this.props.amount) try {
this.setState({ const { dollar, euro } = await getFiat(this.props.amount)
euro: euro, this.setState({ euro, dollar })
dollar: dollar } catch (error) {
}) Logger.error(error.message)
}
} }
render() { render() {
const { dollar, euro } = this.state
return ( return (
<div className={styles.conversion}> <div className={styles.conversion}>
<span> <span>{dollar !== '0.00' && `= $ ${dollar}`}</span>
{this.state.dollar !== '0.00' && `= $ ${this.state.dollar}`} <span>{euro !== '0.00' && `= € ${euro}`}</span>
</span>
<span>{this.state.euro !== '0.00' && `= € ${this.state.euro}`}</span>
</div> </div>
) )
} }

View File

@ -25,6 +25,10 @@
border-bottom-left-radius: 0; border-bottom-left-radius: 0;
border-left: 0; border-left: 0;
} }
:global(.dark) & {
border-color: #000;
}
} }
} }
@ -55,6 +59,11 @@
&::-webkit-inner-spin-button { &::-webkit-inner-spin-button {
margin-left: -($spacer / 2); margin-left: -($spacer / 2);
} }
:global(.dark) & {
border-color: #000;
color: $brand-grey-dimmed;
}
} }
} }
@ -72,6 +81,11 @@
border-bottom-left-radius: $border-radius; border-bottom-left-radius: $border-radius;
display: flex; display: flex;
align-items: center; align-items: center;
:global(.dark) & {
background: $body-background-color--dark;
border-right-color: #000;
}
} }
.infoline { .infoline {

View File

@ -100,19 +100,14 @@ export const getNetwork = async (web3: Web3) => {
export const getFiat = async (amount: number) => { export const getFiat = async (amount: number) => {
const url = 'https://api.coinmarketcap.com/v1/ticker/ethereum/?convert=EUR' const url = 'https://api.coinmarketcap.com/v1/ticker/ethereum/?convert=EUR'
const response = await fetch(url)
if (!response.ok) Logger.error(response.statusText)
const data = await response.json()
/* eslint-disable @typescript-eslint/camelcase */
const { price_usd, price_eur } = data[0]
const dollar = (amount * price_usd).toFixed(2)
const euro = (amount * price_eur).toFixed(2)
/* eslint-enable @typescript-eslint/camelcase */
try { return { dollar, euro }
const response = await fetch(url)
if (!response.ok) Logger.error(response.statusText)
const data = await response.json()
/* eslint-disable @typescript-eslint/camelcase */
const { price_usd, price_eur } = data[0]
const dollar = (amount * price_usd).toFixed(2)
const euro = (amount * price_eur).toFixed(2)
/* eslint-enable @typescript-eslint/camelcase */
return { dollar, euro }
} catch (error) {
Logger.error(error)
}
} }

View File

@ -1,11 +1,12 @@
import React from 'react' import React, { lazy, Suspense } from 'react'
import { useSiteMetadata } from '../../hooks/use-site-metadata' import { useSiteMetadata } from '../../hooks/use-site-metadata'
import Web3Donation from '../Web3Donation'
import Qr from '../atoms/Qr'
import Modal from '../atoms/Modal' import Modal from '../atoms/Modal'
import styles from './ModalThanks.module.scss' import styles from './ModalThanks.module.scss'
const Web3Donation = lazy(() => import('../Web3Donation'))
const Qr = lazy(() => import('../atoms/Qr'))
export default function ModalThanks(props: any) { export default function ModalThanks(props: any) {
const { author } = useSiteMetadata() const { author } = useSiteMetadata()
@ -16,7 +17,9 @@ export default function ModalThanks(props: any) {
title="Say thanks" title="Say thanks"
> >
<div className={styles.modalThanks}> <div className={styles.modalThanks}>
<Web3Donation address={author.ether} /> <Suspense fallback={<div>Loading...</div>}>
<Web3Donation address={author.ether} />
</Suspense>
<header> <header>
<h4>Any other wallets</h4> <h4>Any other wallets</h4>
@ -27,7 +30,9 @@ export default function ModalThanks(props: any) {
.filter(key => key === 'bitcoin' || key === 'ether') .filter(key => key === 'bitcoin' || key === 'ether')
.map((address: string, i: number) => ( .map((address: string, i: number) => (
<div key={i} className={styles.coin}> <div key={i} className={styles.coin}>
<Qr title={address} address={(author as any)[address]} /> <Suspense fallback={<div>Loading...</div>}>
<Qr title={address} address={(author as any)[address]} />
</Suspense>
</div> </div>
))} ))}
</div> </div>