Browse Source

Fix counterValues

master
Loëck Vézien 7 years ago
parent
commit
e2a000a97a
No known key found for this signature in database GPG Key ID: CBCDCE384E853AC4
  1. 13
      src/actions/counterValues.js
  2. 2
      src/components/DashboardPage/AccountCard.js
  3. 2
      src/components/base/Chart/index.js
  4. 23
      src/components/modals/AddAccount/index.js
  5. 2
      src/renderer/init.js

13
src/actions/counterValues.js

@ -20,7 +20,7 @@ export const updateCounterValues: UpdateCounterValues = payload => ({
payload,
})
type FetchCounterValues = (?number) => (Dispatch<*>, Function) => void
type FetchCounterValues = (?number) => (Dispatch<*>, Function) => Promise<any>
export const fetchCounterValues: FetchCounterValues = coinType => (dispatch, getState) => {
const { accounts, counterValues } = getState()
@ -39,7 +39,7 @@ export const fetchCounterValues: FetchCounterValues = coinType => (dispatch, get
const todayCounterValues = get(counterValues, `${code}-USD.${today}`, null)
if (todayCounterValues !== null) {
return {}
return null
}
return axios
@ -56,13 +56,16 @@ export const fetchCounterValues: FetchCounterValues = coinType => (dispatch, get
}))
}
Promise.all(coinTypes.map(fetchCounterValuesByCoinType)).then(result => {
return Promise.all(coinTypes.map(fetchCounterValuesByCoinType)).then(result => {
const newCounterValues = result.reduce((r, v) => {
if (v.symbol) {
if (v !== null) {
r[v.symbol] = v.values
}
return r
}, {})
dispatch(updateCounterValues(newCounterValues))
if (Object.keys(newCounterValues).length !== 0) {
dispatch(updateCounterValues(newCounterValues))
}
})
}

2
src/components/DashboardPage/AccountCard.js

@ -86,7 +86,7 @@ const AccountCard = ({
color={account.currency.color}
height={52}
id={`account-chart-${account.id}`}
linearGradient={[[5, 0.2], [75, 0]]}
linearGradient={[[5, 0.2], [100, 0]]}
simple
strokeWidth={1.5}
/>

2
src/components/base/Chart/index.js

@ -206,7 +206,7 @@ export class AreaChart extends PureComponent<Chart> {
static defaultProps = {
height: 100,
id: 'chart',
linearGradient: [[5, 0.2], [50, 0]],
linearGradient: [[5, 0.2], [100, 0]],
strokeWidth: 2,
renderLabels: (d: Object) => d.y,
renderTickX: (t: any) => t,

23
src/components/modals/AddAccount/index.js

@ -171,25 +171,11 @@ class AddAccountModal extends PureComponent<Props, State> {
}
componentWillReceiveProps(nextProps) {
const { fetchingCounterValues, currency } = this.state
if (nextProps.accounts) {
this.setState(prev => ({
accounts: differenceBy(prev.accounts, nextProps.accounts, 'id'),
}))
}
if (currency !== null && fetchingCounterValues) {
const { code } = getDefaultUnitByCoinType(currency.coinType)
const symbol = `${code.toString()}-USD`
if (nextProps.counterValues[symbol]) {
this.setState({
fetchingCounterValues: false,
step: 'connectDevice',
})
}
}
}
componentDidUpdate() {
@ -297,7 +283,7 @@ class AddAccountModal extends PureComponent<Props, State> {
handleChangeCurrency = (currency: Currency) => this.setState({ currency })
handleSubmit = (e: SyntheticEvent<HTMLFormElement>) => {
handleSubmit = async (e: SyntheticEvent<HTMLFormElement>) => {
e.preventDefault()
const { fetchCounterValues } = this.props
@ -308,7 +294,12 @@ class AddAccountModal extends PureComponent<Props, State> {
fetchingCounterValues: true,
})
fetchCounterValues(currency.coinType)
await fetchCounterValues(currency.coinType)
this.setState({
fetchingCounterValues: false,
step: 'connectDevice',
})
}
}

2
src/renderer/init.js

@ -29,8 +29,8 @@ const history = createHistory()
const store = createStore(history)
const rootNode = document.getElementById('app')
store.dispatch(initCounterValues())
store.dispatch(fetchSettings())
store.dispatch(initCounterValues())
const state = store.getState() || {}
const language = getLanguage(state)

Loading…
Cancel
Save