Loëck Vézien
7 years ago
committed by
GitHub
8 changed files with 152 additions and 37 deletions
@ -0,0 +1,57 @@ |
|||
// @flow
|
|||
|
|||
import React from 'react' |
|||
import { connect } from 'react-redux' |
|||
import styled from 'styled-components' |
|||
|
|||
import type { MapStateToProps } from 'react-redux' |
|||
|
|||
import { getTotalBalance } from 'reducers/accounts' |
|||
|
|||
import Box from 'components/base/Box' |
|||
import Text from 'components/base/Text' |
|||
import FormattedVal from 'components/base/FormattedVal' |
|||
|
|||
const mapStateToProps: MapStateToProps<*, *, *> = state => ({ |
|||
totalBalance: getTotalBalance(state), |
|||
}) |
|||
|
|||
type Props = { |
|||
totalBalance: number, |
|||
} |
|||
|
|||
const Sub = styled(Text).attrs({ |
|||
ff: 'Open Sans', |
|||
color: 'warmGrey', |
|||
fontSize: 4, |
|||
})`` |
|||
|
|||
function BalanceInfos(props: Props) { |
|||
const { totalBalance } = props |
|||
return ( |
|||
<Box horizontal align="flex-end" flow={7}> |
|||
<Box grow> |
|||
<FormattedVal |
|||
val={totalBalance} |
|||
currency="BTC" |
|||
alwaysShowSign={false} |
|||
showCode |
|||
fontSize={8} |
|||
color="dark" |
|||
style={{ lineHeight: 1 }} |
|||
/> |
|||
<Sub>{'Total balance'}</Sub> |
|||
</Box> |
|||
<Box align="flex-end"> |
|||
<FormattedVal isPercent val={9.25} alwaysShowSign fontSize={7} /> |
|||
<Sub>{'since one week'}</Sub> |
|||
</Box> |
|||
<Box align="flex-end"> |
|||
<FormattedVal currency="USD" alwaysShowSign showCode val={6132.23} fontSize={7} /> |
|||
<Sub>{'since one week'}</Sub> |
|||
</Box> |
|||
</Box> |
|||
) |
|||
} |
|||
|
|||
export default connect(mapStateToProps)(BalanceInfos) |
@ -0,0 +1,72 @@ |
|||
// @flow
|
|||
|
|||
import React from 'react' |
|||
import styled from 'styled-components' |
|||
|
|||
import { formatCurrencyUnit } from '@ledgerhq/currencies' |
|||
|
|||
import Text from 'components/base/Text' |
|||
|
|||
const T = styled(Text).attrs({ |
|||
ff: 'Rubik', |
|||
color: p => (p.isNegative ? p.theme.colors.grenade : p.theme.colors.green), |
|||
})`` |
|||
|
|||
const currencies = { |
|||
BTC: { |
|||
name: 'bitcoin', |
|||
code: 'BTC', |
|||
symbol: 'b', |
|||
magnitude: 8, |
|||
}, |
|||
USD: { |
|||
name: 'dollar', |
|||
code: 'USD', |
|||
symbol: '$', |
|||
magnitude: 0, |
|||
}, |
|||
} |
|||
|
|||
type Props = { |
|||
val: number, |
|||
isPercent?: boolean, |
|||
currency?: any, |
|||
alwaysShowSign?: boolean, |
|||
showCode?: boolean, |
|||
} |
|||
|
|||
function FormattedVal(props: Props) { |
|||
const { val, isPercent, currency, alwaysShowSign, showCode, ...p } = props |
|||
|
|||
const isNegative = val < 0 |
|||
|
|||
let text = '' |
|||
|
|||
if (isPercent) { |
|||
text = `${alwaysShowSign ? (isNegative ? '- ' : '+ ') : ''}${val} %` |
|||
} else { |
|||
const curr = currency ? currencies[currency] : null |
|||
if (!curr) { |
|||
return `[invalid currency ${currency || '(null)'}]` |
|||
} |
|||
text = formatCurrencyUnit(curr, val, { |
|||
alwaysShowSign, |
|||
showCode, |
|||
}) |
|||
} |
|||
|
|||
return ( |
|||
<T isNegative={isNegative} {...p}> |
|||
{text} |
|||
</T> |
|||
) |
|||
} |
|||
|
|||
FormattedVal.defaultProps = { |
|||
currency: null, |
|||
isPercent: false, |
|||
alwaysShowSign: false, |
|||
showCode: false, |
|||
} |
|||
|
|||
export default FormattedVal |
Binary file not shown.
Loading…
Reference in new issue