From fde76becc44b0e8932097e6ae7f325abea3ee276 Mon Sep 17 00:00:00 2001 From: Rish Date: Wed, 24 Mar 2021 21:16:02 +0530 Subject: [PATCH] Updated default MRR currency from settings closes https://github.com/TryGhost/Team/issues/550 The MRR chart relied on first currency from the list in case of data for multiple currencies, falling back to USD in case of no MRR data for the site. This can be misleading, specially when the active currency set in payment settings is different from one picked to show on MRR chart. The change updates dashboard to always pick the currency from Payment settings as default for showing chart data. --- ghost/admin/app/controllers/dashboard.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ghost/admin/app/controllers/dashboard.js b/ghost/admin/app/controllers/dashboard.js index 3ad9f887c7..96f5b2b34d 100644 --- a/ghost/admin/app/controllers/dashboard.js +++ b/ghost/admin/app/controllers/dashboard.js @@ -71,10 +71,14 @@ export default class DashboardController extends Controller { this.mrrStatsLoading = true; this.membersStats.fetchMRR().then((stats) => { this.mrrStatsLoading = false; - const statsData = stats.data; - let currencyStats = statsData[0] || { + const statsData = stats.data || []; + const defaultCurrency = this.getDefaultCurrency() || 'usd'; + let currencyStats = statsData.find((stat) => { + return stat.currency === defaultCurrency; + }); + currencyStats = currencyStats || { data: [], - currency: 'usd' + currency: defaultCurrency }; if (currencyStats) { const currencyStatsData = this.membersStats.fillDates(currencyStats.data) || {}; @@ -240,6 +244,12 @@ export default class DashboardController extends Controller { }); } + getDefaultCurrency() { + const plans = this.settings.get('stripePlans') || []; + const monthly = plans.find(plan => plan.interval === 'month'); + return monthly && monthly.currency; + } + @action dismissLaunchBanner() { this.feature.set('launchComplete', true);