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

feat: implement restriction to mobile devices #391

Merged
merged 13 commits into from
Dec 18, 2024
46 changes: 46 additions & 0 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ function App() {
const [tgUser, setTgUser] = useState(JSON.parse(localStorage.getItem('tg_user')));
const [showModal, setShowModal] = useState(false);
const navigate = useNavigate();
const [isMobile, setIsMobile] = useState(false);
const [modal, setModal] = useState(true);
Akshola00 marked this conversation as resolved.
Show resolved Hide resolved


const connectWalletMutation = useConnectWallet(setWalletId);
useEffect(() => {
Expand Down Expand Up @@ -69,6 +72,35 @@ function App() {
const closeModal = () => {
setShowModal(false);
};

useEffect(() => {
const checkMobile = () => {
const userAgent = navigator.userAgent || navigator.vendor || window.opera;

const mobileRegex = /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i;

const isMobileDevice = mobileRegex.test(userAgent);
setIsMobile(isMobileDevice);

const isMobileWidth = window.innerWidth <= 768;
setIsMobile(isMobileDevice || isMobileWidth);
};

checkMobile();

window.addEventListener('resize', checkMobile);

return () => window.removeEventListener('resize', checkMobile);
}, []);
whateverfw marked this conversation as resolved.
Show resolved Hide resolved

const handleCloseModal = () => {
setModal(false);
};

const openTelegramBot = () => {
const telegramBotLink = 'https://t.me/spotnet_bot';
Akshola00 marked this conversation as resolved.
Show resolved Hide resolved
window.open(telegramBotLink, '_blank');
};

return (
<div className="App">
Expand Down Expand Up @@ -109,6 +141,20 @@ function App() {
</Routes>
</main>
<Footer />
{isMobile && (
<ActionModal
isOpen={modal}
title="Mobile website restriction"
subTitle=""
content={[
Akshola00 marked this conversation as resolved.
Show resolved Hide resolved
'Please, use desktop version or telegram mini-app'
]}
cancelLabel="Cancel"
submitLabel="Open in Telegram"
submitAction={openTelegramBot}
cancelAction={handleCloseModal}
/>
)}
</div>
);
}
Expand Down
Loading