openRewardsPopup
This method attempts to open the Rewards popup, emulating a click on the Rewards button, and returns a result indicating whether the operation was successful or if an error occurred.
sdk.rewards.methods.openRewardsPopup()openRewardsPopup(): Promise<Success | ErrorResult>Returns
Promise<Success | ErrorResult>Usage example
Ensure the SDK is ready, the Rewards popup widget is injected, and the Rewards module is ready before opening the Rewards popup.
function openRewardsPopup() {
window.gw.sdk.rewards.methods
.openRewardsPopup()
.then(console.log)
.catch(console.error);
}
function onWidgetInjected() {
const moduleName = window.gw.sdk.common.constants.modules.REWARDS;
window.gw.sdk.runIfModuleReady(moduleName, () => {
openRewardsPopup();
});
}
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 open the Rewards popup. The method will either succeed, returning a success result, or fail, returning an error with details about what went wrong.