Skip to content

Commit

Permalink
Open store in new tab on failed load, adjust timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
NiftyAndy committed Aug 28, 2024
1 parent af65c3c commit 7c4a5fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import Loading from './Loading';
const isAndroid = (userAgent: string) => /.*(Mobile|Android).*/.test(userAgent);
const isIOS = (userAgent: string) => /.*(iPhone|iPad|iPod).*/.test(userAgent);

const redirectToAppStore = (userAgent: string, refcode: string) => {
const redirectToAppStore = (userAgent: string, refcode: string, newTab = false) => {
let appStoreURL = 'https://niftysmashers.com';
if (isAndroid(userAgent)) appStoreURL = `https://niftysmashers.com/android`;
if (isIOS(userAgent)) appStoreURL = `https://niftysmashers.com/ios`;
window.location.href = `${appStoreURL}/?referral=${refcode}`;
if (newTab) window.open(`${appStoreURL}/?referral=${refcode}`, '_blank');
else window.location.href = `${appStoreURL}/?referral=${refcode}`;
};

// Attempt to launch App if installed. Fallback to App Store after a timeout
Expand All @@ -19,14 +20,12 @@ const redirectToNativeApp = (userAgent: string, refcode: string) => {

const clearTimeoutHandler = () => {
clearTimeout(timeoutId);
setTimeout(() => redirectToAppStore(userAgent, refcode), 10000);
setTimeout(() => redirectToAppStore(userAgent, refcode, true), 5000);
window.removeEventListener('beforeunload', clearTimeoutHandler);
// window.removeEventListener('blur', clearTimeoutHandler);
};

// Clear the timeout if the page unloads (app opens) or blurred (popup opens)
// Clear the timeout if the page unloads (app opens)
window.addEventListener('beforeunload', clearTimeoutHandler);
// window.addEventListener('blur', clearTimeoutHandler);

// Attempt to launch the app
window.location.href = `nifty://niftysmashers/invite?profile=${refcode}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Image from 'next/image';
const Loading = () => (
<div style={{ width: '100vw', height: '100vh', display: 'flex', flexDirection: 'column' }}>
<h3 style={{ margin: 'auto' }} id="loading-message">
Loading...
Redirecting...
</h3>
<Image
alt="Nifty League Logo"
Expand Down

0 comments on commit 7c4a5fb

Please sign in to comment.