Skip to content

Commit

Permalink
fix: add window check
Browse files Browse the repository at this point in the history
  • Loading branch information
L03TJ3 committed Nov 8, 2023
1 parent a0b2527 commit d41350e
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions packages/good-design/src/apps/onramp/Onramper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,27 @@ export const Onramper = ({
const isMobile = deviceDetect();

useEffect(() => {
window.focus(); // first force focus for the step animation to start properly
window && window.focus(); // first force focus for the step animation to start properly
}, []);

// SO fiddle: http://jsfiddle.net/wk1yv6q3/
useEffect(() => {
const checkFocus = (e: any) => {
if (document.activeElement === document.querySelector("iframe") && step === -1) {
onGdEvent("buy_start");
setStep(0);
} else if (step === 0) {
setStep(-1);
}
};
window.addEventListener("focus", checkFocus);
window.addEventListener("blur", checkFocus);
return () => {
window.removeEventListener("blur", checkFocus);
window.removeEventListener("focus", checkFocus);
};
if (window) {
const checkFocus = (e: any) => {
if (document.activeElement === document.querySelector("iframe") && step === -1) {
onGdEvent("buy_start");
setStep(0);
} else if (step === 0) {
setStep(-1);
}
};
window.addEventListener("focus", checkFocus);
window.addEventListener("blur", checkFocus);
return () => {
window.removeEventListener("blur", checkFocus);
window.removeEventListener("focus", checkFocus);
};
}
}, [step]);

const devNextStep = useCallback(() => {
Expand Down

0 comments on commit d41350e

Please sign in to comment.