Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-2033 Update GBE account state in response to checkout-web events #555

Merged
merged 16 commits into from Jun 15, 2020
Merged
Changes from 1 commit
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

Listen for additional events in checkout_pages content script. Flesh …

…out handling of these events in background#handleCheckoutPages
  • Loading branch information
wlycdgr committed May 11, 2020
commit 5d53c82c95e298a13581c97e295201d173287a30
@@ -30,8 +30,11 @@ const CheckoutPagesContentScript = (function(window) {
* @package
*/
const _listeners = [
'checkoutPages.buyInsights',
'checkoutPage.buyPlus',
'checkoutPage.ping',
'checkoutPage.buyPremium',
'checkoutPage.login',
'checkoutPage.register',
];
const _initialize = function() {
_listeners.forEach(name => window.addEventListener(name, () => sendMessage(name)));
@@ -52,7 +52,8 @@
],
"matches": [
"https://account.ghostery.com/*",
"https://account.ghosterystage.com/*"
"https://account.ghosterystage.com/*",
"http://localhost:3001/*"
],
"run_at": "document_start"
},
@@ -63,7 +64,8 @@
],
"matches": [
"https://checkout.ghostery.com/*",
"https://checkout.ghosterystage.com/*"
"https://checkout.ghosterystage.com/*",
"http://localhost:3002/*"
],
"run_at": "document_start"
},
@@ -325,16 +325,33 @@ function handleAccountPages(name, callback) {
* @param {string} tab_url tab url
*/
function handleCheckoutPages(name, callback) {
console.error('checkoutPage event:');
console.error(name);

switch (name) {
case 'checkoutPage.buyInsights':
case 'checkoutPage.buyPlus':
// Update account info
console.error('background#handleCheckoutPages received "checkoutPage.buyPlus"');
case 'checkoutPage.buyPremium':
account.getUser()
.then(account.getUserSubscriptionData)
.catch((err) => {
log('handleCheckoutPages error', err);
});
return true;
case 'checkoutPage.ping':
console.error('ping received from Checkout Web');
case 'checkoutPage.login':
account.getUser()
.then(account.getUserSettings)
// account.getUserSettings will reject if user email is not validated
.catch(err => log('handleCheckoutPages error', err))
.then(account.getUserSubscriptionData)
// The user may not be a subscriber
.catch(err => log('handleCheckoutPages error', err));
return true;
case 'checkoutPage.register':
account.getUser();
return true;
default:
return false;
break;
}
}

ProTip! Use n and p to navigate between commits in a pull request.