1
0
mirror of https://github.com/kremalicious/blowfish.git synced 2024-12-28 15:47:52 +01:00

number formatting tweaks

This commit is contained in:
Matthias Kretschmann 2019-06-04 20:35:37 +02:00
parent 1c59257417
commit 0a1feafa74
Signed by: m
GPG Key ID: 606EEEF3C479A91F
6 changed files with 68 additions and 49 deletions

View File

@ -17,8 +17,8 @@ if (
isDev = true isDev = true
} }
const width = 620 const width = 640
const height = 440 const height = 450
const createWindow = async () => { const createWindow = async () => {
const isDarkMode = systemPreferences.isDarkMode() const isDarkMode = systemPreferences.isDarkMode()

View File

@ -1,24 +1,25 @@
.ticker { .ticker {
justify-content: center; margin-top: 3rem;
margin-top: 2rem; margin-bottom: 4rem;
margin-bottom: 2rem; width: 100%;
} }
.ticker .number-unit { .ticker .number-unit {
flex: initial; margin-top: 0;
margin-top: 1rem;
} }
.ticker button { .ticker button {
background: none; background: none;
border: 1px solid #e2e2e2; border: 1px solid #e2e2e2;
box-shadow: none; box-shadow: none;
margin: 0; margin: 0 auto;
outline: 0; outline: 0;
font-size: .8rem; font-size: .75rem;
border-radius: .3rem; border-radius: .3rem;
padding: .2rem .4rem; padding: .3rem .4rem;
display: block; display: block;
width: 100%;
max-width: 12rem;
transition: border .2s ease-out; transition: border .2s ease-out;
color: #41474e; color: #41474e;
} }
@ -33,12 +34,11 @@
} }
.label--price { .label--price {
display: inline-block;
font-size: .95rem; font-size: .95rem;
} }
.change { .change {
font-size: .7rem; font-size: .65rem;
display: inline-block; display: inline-block;
margin-left: .25rem; margin-left: .25rem;
} }

View File

@ -11,12 +11,12 @@ const Item = posed.div(fadeIn)
const Change = ({ currency }) => ( const Change = ({ currency }) => (
<AppContext.Consumer> <AppContext.Consumer>
{({ priceChanges }) => { {({ priceChanges }) => {
let classes = JSON.stringify(priceChanges[currency]).startsWith('+') const isNegative = JSON.stringify(priceChanges[currency]).startsWith('-')
? 'change--positive' let classes = isNegative ? 'change--negative' : 'change--positive'
: 'change--negative'
return ( return (
<span className={`change ${classes}`}> <span className={`change ${classes}`} title="24hr change">
{!isNegative && '+'}
{Number(priceChanges[currency]).toFixed(1)}% {Number(priceChanges[currency]).toFixed(1)}%
</span> </span>
) )
@ -31,29 +31,14 @@ Change.propTypes = {
export default class Ticker extends PureComponent { export default class Ticker extends PureComponent {
static contextType = AppContext static contextType = AppContext
items = activeStyle => items = () => {
// convert Map to array first, cause for...of or forEach returns undefined, const {
// so it cannot be mapped to a collection of elements prices,
[...this.context.prices.entries()].map(([key, value]) => ( needsConfig,
<Item key={key} className="number-unit"> currency,
<button toggleCurrencies,
className="label label--price" accentColor
onClick={() => this.context.toggleCurrencies(key)} } = this.context
disabled={this.context.needsConfig}
style={
key === this.context.currency && !this.context.needsConfig
? activeStyle
: {}
}
>
{cryptoFormatter(value, key)}
{key !== 'ocean' && <Change currency={key} />}
</button>
</Item>
))
render() {
const { accentColor } = this.context
const activeStyle = { const activeStyle = {
backgroundColor: accentColor, backgroundColor: accentColor,
@ -61,9 +46,29 @@ export default class Ticker extends PureComponent {
borderColor: accentColor borderColor: accentColor
} }
// convert Map to array first, cause for...of or forEach returns undefined,
// so it cannot be mapped to a collection of elements
return [...prices.entries()].map(([key, value]) => (
<Item key={key} className="number-unit">
<button
className="label label--price"
onClick={() => toggleCurrencies(key)}
disabled={needsConfig}
style={key === currency && !needsConfig ? activeStyle : {}}
>
{cryptoFormatter(value, key)}
{key !== 'ocean' && <Change currency={key} />}
</button>
</Item>
))
}
render() {
return ( return (
<footer className="number-unit-wrap ticker" {...this.props}> <footer className="ticker" {...this.props}>
<PoseGroup animateOnMount>{this.items(activeStyle)}</PoseGroup> <div className="number-unit-wrap">
<PoseGroup animateOnMount>{this.items()}</PoseGroup>
</div>
</footer> </footer>
) )
} }

View File

@ -26,19 +26,16 @@
} }
.number-unit-wrap { .number-unit-wrap {
display: flex; display: grid;
grid-gap: .5rem;
grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
justify-items: start;
width: 100%; width: 100%;
flex-wrap: wrap;
justify-content: space-around;
position: relative;
} }
.number-unit { .number-unit {
text-align: center; text-align: center;
flex: 1 1 20%; width: 100%;
margin-top: 5%;
padding-left: 2%;
padding-right: 2%;
} }
.label { .label {
@ -52,6 +49,7 @@
.number-unit-wrap--accounts { .number-unit-wrap--accounts {
min-height: 55px; min-height: 55px;
padding-top: 2rem;
} }
.number-unit--main { .number-unit--main {

View File

@ -3,6 +3,7 @@
width: 100%; width: 100%;
position: relative; position: relative;
margin-top: 7vh; margin-top: 7vh;
padding-bottom: 4rem;
} }
.preferences__title { .preferences__title {

View File

@ -1,6 +1,8 @@
const { app, shell } = require('electron') const { app, shell } = require('electron')
const { formatCurrency } = require('@coingecko/cryptoformat') const { formatCurrency } = require('@coingecko/cryptoformat')
const isFiat = currency => currency === 'eur' || currency === 'usd'
const openUrl = url => { const openUrl = url => {
shell.openExternal(url) shell.openExternal(url)
} }
@ -35,9 +37,22 @@ const formatOcean = value => {
return numberformatted.replace(/EUR/, 'Ọ').replace(/€/, 'Ọ') return numberformatted.replace(/EUR/, 'Ọ').replace(/€/, 'Ọ')
} }
const formatFiat = (value, currency) => {
const numberformatted = new Intl.NumberFormat(locale, {
minimumFractionDigits: 0,
maximumFractionDigits: 4,
style: 'currency',
currency: currency.toUpperCase()
}).format(value)
return numberformatted
}
const cryptoFormatter = (value, currency) => { const cryptoFormatter = (value, currency) => {
if (currency === 'ocean') { if (currency === 'ocean') {
return formatOcean(value) return formatOcean(value)
} else if (isFiat(currency)) {
return formatFiat(value, currency)
} else { } else {
return formatCurrency(value, currency.toUpperCase(), locale) return formatCurrency(value, currency.toUpperCase(), locale)
.replace(/BTC/, 'Ƀ') .replace(/BTC/, 'Ƀ')