From 5592a18b8be32d7de82dff5fc52debf280eb6345 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 18 Sep 2020 15:23:55 -0400 Subject: [PATCH 1/2] Move sign_in_success ping to Account#getUserSubscriptionData to fix race condition --- src/background.js | 3 --- src/classes/Account.js | 8 ++++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/background.js b/src/background.js index f17467dfd..acf96f699 100644 --- a/src/background.js +++ b/src/background.js @@ -822,9 +822,6 @@ function onMessageHandler(request, sender, callback) { const { email, password } = message; account.login(email, password) .then((response) => { - if (!response.hasOwnProperty('errors')) { - metrics.ping('sign_in_success'); - } callback(response); }) .catch((err) => { diff --git a/src/classes/Account.js b/src/classes/Account.js index 9f2e55a34..fdc9f4251 100644 --- a/src/classes/Account.js +++ b/src/classes/Account.js @@ -22,6 +22,7 @@ import conf from './Conf'; import dispatcher from './Dispatcher'; import { log } from '../utils/common'; import Api from '../utils/api'; +import metrics from '../classes/Metrics'; const api = new Api(); const { @@ -85,7 +86,7 @@ class Account { } this._getUserIDFromCookie().then((userID) => { this._setAccountInfo(userID); - this.getUserSubscriptionData(); + this.getUserSubscriptionData({ calledFrom: 'login' }); }); return {}; }); @@ -162,7 +163,7 @@ class Account { /** * @return {array} All subscriptions the user has, empty if none */ - getUserSubscriptionData = () => ( + getUserSubscriptionData = (options) => ( this._getUserID() .then(userID => api.get('stripe/customers', userID, 'cards,subscriptions')) .then((res) => { @@ -189,6 +190,9 @@ class Account { this._setSubscriptionData(plusSubscription); } } + if (options && options.calledFrom === 'login') { + metrics.ping('sign_in_success'); + } return subscriptions; }) From f0897cce68697d2a6c1d20e184d72a5c60d581cf Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 18 Sep 2020 15:28:40 -0400 Subject: [PATCH 2/2] Fix linter --- src/classes/Account.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/classes/Account.js b/src/classes/Account.js index fdc9f4251..edf883474 100644 --- a/src/classes/Account.js +++ b/src/classes/Account.js @@ -22,7 +22,7 @@ import conf from './Conf'; import dispatcher from './Dispatcher'; import { log } from '../utils/common'; import Api from '../utils/api'; -import metrics from '../classes/Metrics'; +import metrics from './Metrics'; const api = new Api(); const { @@ -163,7 +163,7 @@ class Account { /** * @return {array} All subscriptions the user has, empty if none */ - getUserSubscriptionData = (options) => ( + getUserSubscriptionData = options => ( this._getUserID() .then(userID => api.get('stripe/customers', userID, 'cards,subscriptions')) .then((res) => {