mirror of
https://github.com/kremalicious/blowfish.git
synced 2024-12-29 16:17:52 +01:00
more reusable balance component
This commit is contained in:
parent
33053e11e2
commit
532e8ce7cb
@ -19,6 +19,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@oceanprotocol/typographies": "^0.1.0",
|
"@oceanprotocol/typographies": "^0.1.0",
|
||||||
|
"crypto-symbols": "^1.0.0",
|
||||||
"ms": "^2.1.1",
|
"ms": "^2.1.1",
|
||||||
"react": "^16.8.6",
|
"react": "^16.8.6",
|
||||||
"react-dom": "^16.8.6"
|
"react-dom": "^16.8.6"
|
||||||
|
@ -2,32 +2,27 @@ import React from 'react'
|
|||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { Consumer } from '../store/createContext'
|
import { Consumer } from '../store/createContext'
|
||||||
import { numberFormatter, fiatFormatter } from '../util/moneyFormatter'
|
import { numberFormatter, fiatFormatter } from '../util/moneyFormatter'
|
||||||
|
import symbols from 'crypto-symbols'
|
||||||
|
|
||||||
const Balance = ({ balance }) => {
|
const Balance = ({ balance }) => (
|
||||||
const { ocean, btc, eth, eur, usd } = balance
|
|
||||||
|
|
||||||
return (
|
|
||||||
<h1 className="number">
|
<h1 className="number">
|
||||||
<Consumer>
|
<Consumer>
|
||||||
{({ currency }) =>
|
{({ currency }) => {
|
||||||
currency === 'ocean' ? (
|
const isFiat = currency === 'usd' || currency === 'eur'
|
||||||
<span className="balance">Ọ {numberFormatter(ocean) || 0}</span>
|
const symbol =
|
||||||
) : currency === 'btc' ? (
|
currency === 'ocean' ? 'Ọ' : symbols[currency.toUpperCase()]
|
||||||
<span className="balance">₿ {numberFormatter(btc) || 0}</span>
|
|
||||||
) : currency === 'eth' ? (
|
return isFiat ? (
|
||||||
<span className="balance">Ξ {numberFormatter(eth) || 0}</span>
|
fiatFormatter(currency.toUpperCase(), balance[currency])
|
||||||
) : currency === 'eur' ? (
|
|
||||||
<span className="balance">{fiatFormatter('EUR', eur)}</span>
|
|
||||||
) : currency === 'usd' ? (
|
|
||||||
<span className="balance">{fiatFormatter('USD', usd)}</span>
|
|
||||||
) : (
|
) : (
|
||||||
<span className="balance">{numberFormatter(currency)}</span>
|
<>
|
||||||
|
{symbol} {numberFormatter(balance[currency]) || 0}
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}}
|
||||||
</Consumer>
|
</Consumer>
|
||||||
</h1>
|
</h1>
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
Balance.propTypes = {
|
Balance.propTypes = {
|
||||||
balance: PropTypes.object.isRequired
|
balance: PropTypes.object.isRequired
|
||||||
|
@ -37,7 +37,7 @@ const Total = () => (
|
|||||||
return <Balance balance={balanceNew} />
|
return <Balance balance={balanceNew} />
|
||||||
}}
|
}}
|
||||||
</Consumer>
|
</Consumer>
|
||||||
<span className="label">Total balance</span>
|
<span className="label">Total Balance</span>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user