Skip to content

Commit b0d9d7d

Browse files
committed
Fix the dashboard price history graph
There were multiple things that made it stop working correctly: - The cryptocompare.com API changed the max value for the `limit` parameter - My previous optimization of the login stage didn't account for things being dependent on each other. It now also does not hide the resolution buttons while the stats are loading. Fixes #572
1 parent d6d1745 commit b0d9d7d

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

app/renderer/containers/Dashboard.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class DashboardContainer extends SuperContainer {
107107
case 'year':
108108
return getUrlForDays(365);
109109
case 'all':
110-
return getUrlForDays(100000, 7);
110+
return getUrlForDays(2000, 7);
111111
default:
112112
throw new Error('Unsupported resolution');
113113
}
@@ -194,7 +194,7 @@ class DashboardContainer extends SuperContainer {
194194
const symbol = this.activeCurrencySymbol;
195195
const prices = await this.getCurrencyHistory(symbol);
196196

197-
this.setState(prevState => {
197+
await this.setState(prevState => {
198198
prevState.currencyHistory[prevState.currencyHistoryResolution][symbol] = prices;
199199
return prevState;
200200
});

app/renderer/containers/Login.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,17 @@ class LoginContainer extends Container {
144144

145145
const api = await createApi(seedPhrase);
146146

147-
await Promise.all([
148-
enableCurrencies(api),
149-
watchFiatPrice(),
150-
watchAllCurrencyHistory(),
151-
]);
147+
await enableCurrencies(api);
152148

153-
// This method depends on the data from `enableCurrencies()` and `watchFiatPrice()`
149+
// Depends on the data from `enableCurrencies()`
150+
await watchFiatPrice();
151+
152+
// Depends on the data from `enableCurrencies()` and `watchFiatPrice()`
154153
await watchCurrencies();
155154

155+
// Depends on data from `enableCurrencies() and `watchFiatPrice()`
156+
await watchAllCurrencyHistory();
157+
156158
config.set('lastActivePortfolioId', portfolio.id);
157159
setAppWindowBounds();
158160
appContainer.logIn(portfolio);

app/renderer/views/Dashboard/Chart.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,20 @@ const Chart = () => {
3232
const {portfolioHistory, currencyHistory, activeView} = state;
3333
const symbol = dashboardContainer.activeCurrencySymbol;
3434

35-
const data = activeView === 'Portfolio' ?
36-
portfolioHistory[state.currencyHistoryResolution] :
37-
currencyHistory[state.currencyHistoryResolution][symbol];
35+
// TODO: Add a indicator for when the stats are loading when React supports Suspense fetching
36+
37+
const getHistory = resolution => {
38+
return activeView === 'Portfolio' ?
39+
portfolioHistory[resolution] :
40+
currencyHistory[resolution][symbol];
41+
};
42+
43+
const data = getHistory(state.currencyHistoryResolution);
44+
45+
const hasDataInAtLeastOneResolution = Object.keys(currencyHistory).some(resolution => {
46+
const history = getHistory(resolution);
47+
return history && history.length > 0;
48+
});
3849

3950
return (
4051
<div className="Dashboard--Chart">
@@ -44,7 +55,7 @@ const Chart = () => {
4455
/>
4556
<div className="overlay">
4657
<h3>{activeView === 'Portfolio' ? t('chart.portfolioValue') : t('chart.symbolChart', {symbol})}</h3>
47-
{data &&
58+
{hasDataInAtLeastOneResolution &&
4859
<div className="resolution-buttons">
4960
<ResolutionButton title="1h" resolution="hour"/>
5061
<ResolutionButton title="1d" resolution="day"/>

0 commit comments

Comments
 (0)