Skip to main content

closeRewardsPopup

This method attempts to close the Rewards popup and returns a result indicating whether the operation was successful or if an error occurred.

Usage example​

Ensure the SDK is ready, the Rewards popup widget is injected and Rewards module is ready before closing the Rewards popup.

function closeRewardsPopup() {
window.gw.sdk.rewards.methods
.closeRewardsPopup()
.then(console.log)
.catch(console.error);
}

function onWidgetInjected() {
const moduleName = window.gw.sdk.common.constants.modules.REWARDS;

window.gw.sdk.runIfModuleReady(moduleName, () => {
closeRewardsPopup();
});
}

function onSdkReady() {
const eventName = window.gw.sdk.common.events.WIDGET_INJECTED;

window.gw.sdk.on(eventName, (event) => {
if (event.detail.widgetName === "RewardsPopUpWidget") {
onWidgetInjected();
}
});
}

if (window.gw && window.gw.sdk) {
onSdkReady();
} else {
document.addEventListener("gwSdkReady", onSdkReady);
}

This code ensures that the SDK is ready, the RewardsPopUpWidget is injected and the Rewards module is ready before attempting to close the Rewards Popup. The method will either succeed, returning a success result, or fail, returning an error with details about what went wrong.