poll subscription status only when button got clicked

otherwise, both stripe, our appstore db is bombarded
This commit is contained in:
Girish Ramakrishnan
2019-05-13 16:39:52 -07:00
parent 5695da1d86
commit 84473dc10d
2 changed files with 14 additions and 6 deletions

View File

@@ -314,6 +314,15 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca
Client.getSubscription(function (error, result) {
$scope.subscriptionBusy = false;
if (error && error.statusCode === 412) return; // not yet registered
if (error) return console.error(error);
$scope.subscription = result;
});
}
$scope.pollSubscriptionStatus = function () {
Client.getSubscription(function (error, result) {
if (error && error.statusCode === 412) return; // not yet registered
if (error) return console.error(error);
if (!$scope.$parent) return; // user changed view. otherwise we get an error that $scope.$parent is null
@@ -323,10 +332,9 @@ angular.module('Application').controller('SettingsController', ['$scope', '$loca
// also reload the subscription on the main controller
$scope.$parent.updateSubscriptionStatus();
// check again to give more immediate feedback once a subscription was setup
if (result.plan.id === 'free') $timeout(getSubscription, 10000);
$timeout($scope.pollSubscriptionStatus, 10 * 1000);
});
}
};
$('#avatarFileInput').get(0).onchange = function (event) {
var fr = new FileReader();