Browse Source

initial version of a Placeholder for when no countervalues loaded yet

master
Gaëtan Renaudeau 7 years ago
parent
commit
93cc431a24
  1. 10
      src/components/AccountPage/index.js
  2. 41
      src/components/BalanceSummary/BalanceInfos.js
  3. 11
      src/components/BalanceSummary/index.js
  4. 9
      src/components/DashboardPage/index.js
  5. 9
      src/components/Placeholder.js
  6. 4
      src/config/constants.js
  7. 3
      src/helpers/countervalues.js

10
src/components/AccountPage/index.js

@ -148,10 +148,14 @@ class AccountPage extends PureComponent<Props> {
counterValue={counterValue} counterValue={counterValue}
daysCount={daysCount} daysCount={daysCount}
selectedTimeRange={selectedTimeRange} selectedTimeRange={selectedTimeRange}
renderHeader={({ totalBalance, sinceBalance, refBalance }) => ( renderHeader={({ isAvailable, totalBalance, sinceBalance, refBalance }) => (
<Box flow={4} mb={2}> <Box flow={4} mb={2}>
<Box horizontal> <Box horizontal>
<BalanceTotal totalBalance={account.balance} unit={account.unit}> <BalanceTotal
isAvailable={isAvailable}
totalBalance={account.balance}
unit={account.unit}
>
<FormattedVal <FormattedVal
animateTicker animateTicker
alwaysShowSign={false} alwaysShowSign={false}
@ -171,6 +175,7 @@ class AccountPage extends PureComponent<Props> {
</Box> </Box>
<Box horizontal justifyContent="center" flow={7}> <Box horizontal justifyContent="center" flow={7}>
<BalanceSincePercent <BalanceSincePercent
isAvailable={isAvailable}
t={t} t={t}
alignItems="center" alignItems="center"
totalBalance={totalBalance} totalBalance={totalBalance}
@ -179,6 +184,7 @@ class AccountPage extends PureComponent<Props> {
since={selectedTimeRange} since={selectedTimeRange}
/> />
<BalanceSinceDiff <BalanceSinceDiff
isAvailable={isAvailable}
t={t} t={t}
counterValue={counterValue} counterValue={counterValue}
alignItems="center" alignItems="center"

41
src/components/BalanceSummary/BalanceInfos.js

@ -9,6 +9,7 @@ import type { T } from 'types/common'
import Box from 'components/base/Box' import Box from 'components/base/Box'
import FormattedVal from 'components/base/FormattedVal' import FormattedVal from 'components/base/FormattedVal'
import DeltaChange from '../DeltaChange' import DeltaChange from '../DeltaChange'
import { PlaceholderLine } from '../Placeholder'
const Sub = styled(Box).attrs({ const Sub = styled(Box).attrs({
ff: 'Open Sans', ff: 'Open Sans',
@ -22,12 +23,14 @@ type BalanceSinceProps = {
totalBalance: number, totalBalance: number,
sinceBalance: number, sinceBalance: number,
refBalance: number, refBalance: number,
isAvailable: boolean,
t: T, t: T,
} }
type BalanceTotalProps = { type BalanceTotalProps = {
children?: any, children?: any,
unit: Unit, unit: Unit,
isAvailable: boolean,
totalBalance: number, totalBalance: number,
} }
@ -36,9 +39,12 @@ type Props = {
} & BalanceSinceProps } & BalanceSinceProps
export function BalanceSincePercent(props: BalanceSinceProps) { export function BalanceSincePercent(props: BalanceSinceProps) {
const { t, totalBalance, sinceBalance, refBalance, since, ...otherProps } = props const { t, totalBalance, sinceBalance, refBalance, since, isAvailable, ...otherProps } = props
return ( return (
<Box {...otherProps}> <Box {...otherProps}>
{!isAvailable ? (
<PlaceholderLine width={100} />
) : (
<DeltaChange <DeltaChange
from={refBalance} from={refBalance}
to={totalBalance} to={totalBalance}
@ -47,15 +53,23 @@ export function BalanceSincePercent(props: BalanceSinceProps) {
fontSize={7} fontSize={7}
withIcon withIcon
/> />
)}
{!isAvailable ? (
<PlaceholderLine dark width={60} />
) : (
<Sub>{t(`app:time.since.${since}`)}</Sub> <Sub>{t(`app:time.since.${since}`)}</Sub>
)}
</Box> </Box>
) )
} }
export function BalanceSinceDiff(props: Props) { export function BalanceSinceDiff(props: Props) {
const { t, totalBalance, sinceBalance, since, counterValue, ...otherProps } = props const { t, totalBalance, sinceBalance, since, counterValue, isAvailable, ...otherProps } = props
return ( return (
<Box {...otherProps}> <Box {...otherProps}>
{!isAvailable ? (
<PlaceholderLine width={100} />
) : (
<FormattedVal <FormattedVal
color="dark" color="dark"
animateTicker animateTicker
@ -65,15 +79,23 @@ export function BalanceSinceDiff(props: Props) {
val={totalBalance - sinceBalance} val={totalBalance - sinceBalance}
withIcon withIcon
/> />
)}
{!isAvailable ? (
<PlaceholderLine dark width={60} />
) : (
<Sub>{t(`app:time.since.${since}`)}</Sub> <Sub>{t(`app:time.since.${since}`)}</Sub>
)}
</Box> </Box>
) )
} }
export function BalanceTotal(props: BalanceTotalProps) { export function BalanceTotal(props: BalanceTotalProps) {
const { unit, totalBalance, children } = props const { unit, totalBalance, isAvailable, children } = props
return ( return (
<Box grow {...props}> <Box grow {...props}>
{!isAvailable ? (
<PlaceholderLine width={150} />
) : (
<FormattedVal <FormattedVal
animateTicker animateTicker
color="dark" color="dark"
@ -82,7 +104,8 @@ export function BalanceTotal(props: BalanceTotalProps) {
showCode showCode
val={totalBalance} val={totalBalance}
/> />
{children} )}
{!isAvailable ? <PlaceholderLine dark width={50} /> : children}
</Box> </Box>
) )
} }
@ -93,16 +116,21 @@ BalanceTotal.defaultProps = {
} }
function BalanceInfos(props: Props) { function BalanceInfos(props: Props) {
const { t, totalBalance, since, sinceBalance, refBalance, counterValue } = props const { t, totalBalance, since, sinceBalance, refBalance, isAvailable, counterValue } = props
return ( return (
<Box horizontal alignItems="center" flow={7}> <Box horizontal alignItems="center" flow={7}>
<BalanceTotal unit={counterValue.units[0]} totalBalance={totalBalance}> <BalanceTotal
unit={counterValue.units[0]}
isAvailable={isAvailable}
totalBalance={totalBalance}
>
<Sub>{t('app:dashboard.totalBalance')}</Sub> <Sub>{t('app:dashboard.totalBalance')}</Sub>
</BalanceTotal> </BalanceTotal>
<BalanceSincePercent <BalanceSincePercent
alignItems="flex-end" alignItems="flex-end"
totalBalance={totalBalance} totalBalance={totalBalance}
sinceBalance={sinceBalance} sinceBalance={sinceBalance}
isAvailable={isAvailable}
refBalance={refBalance} refBalance={refBalance}
since={since} since={since}
t={t} t={t}
@ -110,6 +138,7 @@ function BalanceInfos(props: Props) {
<BalanceSinceDiff <BalanceSinceDiff
counterValue={counterValue} counterValue={counterValue}
alignItems="flex-end" alignItems="flex-end"
isAvailable={isAvailable}
totalBalance={totalBalance} totalBalance={totalBalance}
sinceBalance={sinceBalance} sinceBalance={sinceBalance}
refBalance={refBalance} refBalance={refBalance}

11
src/components/BalanceSummary/index.js

@ -21,6 +21,7 @@ type Props = {
totalBalance: number, totalBalance: number,
sinceBalance: number, sinceBalance: number,
refBalance: number, refBalance: number,
isAvailable: boolean,
}) => *, }) => *,
} }
@ -37,12 +38,12 @@ const BalanceSummary = ({
return ( return (
<Card p={0} py={5}> <Card p={0} py={5}>
<CalculateBalance accounts={accounts} daysCount={daysCount}> <CalculateBalance accounts={accounts} daysCount={daysCount}>
{({ isAvailable, balanceHistory, balanceStart, balanceEnd }) => {({ isAvailable, balanceHistory, balanceStart, balanceEnd }) => (
!isAvailable ? null : (
<Fragment> <Fragment>
{renderHeader ? ( {renderHeader ? (
<Box px={6}> <Box px={6}>
{renderHeader({ {renderHeader({
isAvailable,
selectedTimeRange, selectedTimeRange,
// FIXME refactor these // FIXME refactor these
totalBalance: balanceEnd, totalBalance: balanceEnd,
@ -55,12 +56,13 @@ const BalanceSummary = ({
<Chart <Chart
id={chartId} id={chartId}
unit={account ? account.unit : null} unit={account ? account.unit : null}
color={chartColor} color={!isAvailable ? 'transparent' : chartColor}
data={balanceHistory} data={balanceHistory}
height={200} height={200}
currency={counterValue} currency={counterValue}
tickXScale={selectedTimeRange} tickXScale={selectedTimeRange}
renderTickY={val => formatShort(counterValue.units[0], val)} renderTickY={val => formatShort(counterValue.units[0], val)}
isInteractive={isAvailable}
renderTooltip={ renderTooltip={
isAvailable && !account isAvailable && !account
? d => ( ? d => (
@ -83,8 +85,7 @@ const BalanceSummary = ({
/> />
</Box> </Box>
</Fragment> </Fragment>
) )}
}
</CalculateBalance> </CalculateBalance>
</Card> </Card>
) )

9
src/components/DashboardPage/index.js

@ -120,10 +120,17 @@ class DashboardPage extends PureComponent<Props> {
accounts={accounts} accounts={accounts}
selectedTimeRange={selectedTimeRange} selectedTimeRange={selectedTimeRange}
daysCount={daysCount} daysCount={daysCount}
renderHeader={({ totalBalance, selectedTimeRange, sinceBalance, refBalance }) => ( renderHeader={({
isAvailable,
totalBalance,
selectedTimeRange,
sinceBalance,
refBalance,
}) => (
<BalanceInfos <BalanceInfos
t={t} t={t}
counterValue={counterValue} counterValue={counterValue}
isAvailable={isAvailable}
totalBalance={totalBalance} totalBalance={totalBalance}
since={selectedTimeRange} since={selectedTimeRange}
sinceBalance={sinceBalance} sinceBalance={sinceBalance}

9
src/components/Placeholder.js

@ -0,0 +1,9 @@
import styled from 'styled-components'
export const PlaceholderLine = styled.div`
background-color: ${p => (p.dark ? '#C2C2C2' : '#D6D6D6')};
width: ${p => p.width}px;
height: 10px;
border-radius: 5px;
margin: 5px 0;
`

4
src/config/constants.js

@ -29,6 +29,10 @@ export const DEVICE_DISCONNECT_DEBOUNCE = intFromEnv('LEDGER_DEVICE_DISCONNECT_D
// Endpoints... // Endpoints...
export const LEDGER_COUNTERVALUES_API = stringFromEnv(
'LEDGER_COUNTERVALUES_API',
'https://ledger-countervalue-poc.herokuapp.com',
)
export const LEDGER_REST_API_BASE = stringFromEnv( export const LEDGER_REST_API_BASE = stringFromEnv(
'LEDGER_REST_API_BASE', 'LEDGER_REST_API_BASE',
'https://api.ledgerwallet.com/', 'https://api.ledgerwallet.com/',

3
src/helpers/countervalues.js

@ -1,6 +1,7 @@
// @flow // @flow
import { createSelector } from 'reselect' import { createSelector } from 'reselect'
import { LEDGER_COUNTERVALUES_API } from 'config/constants'
import createCounterValues from '@ledgerhq/live-common/lib/countervalues' import createCounterValues from '@ledgerhq/live-common/lib/countervalues'
import { setExchangePairsAction } from 'actions/settings' import { setExchangePairsAction } from 'actions/settings'
import { currenciesSelector } from 'reducers/accounts' import { currenciesSelector } from 'reducers/accounts'
@ -53,7 +54,7 @@ const addExtraPollingHooks = (schedulePoll, cancelPoll) => {
const CounterValues = createCounterValues({ const CounterValues = createCounterValues({
log: (...args) => logger.log('CounterValues:', ...args), log: (...args) => logger.log('CounterValues:', ...args),
getAPIBaseURL: () => 'https://ledger-countervalue-poc.herokuapp.com', getAPIBaseURL: () => LEDGER_COUNTERVALUES_API,
storeSelector: state => state.countervalues, storeSelector: state => state.countervalues,
pairsSelector, pairsSelector,
setExchangePairsAction, setExchangePairsAction,

Loading…
Cancel
Save