Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-history-page
Browse files Browse the repository at this point in the history
  • Loading branch information
Ibinola committed Dec 18, 2024
2 parents 98a5f6b + b8227c8 commit a74ca21
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
31 changes: 30 additions & 1 deletion frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ import { useConnectWallet } from 'hooks/useConnectWallet';
import OverviewPage from 'pages/spotnet/overview/Overview';
import { ActionModal } from 'components/ui/ActionModal';
import Stake from 'pages/vault/stake/Stake';
import { TELEGRAM_BOT_LINK } from 'utils/constants';
import { useCheckMobile } from 'hooks/useCheckMobile';
import { notifyError } from 'utils/notification';
import PositionHistory from 'pages/spotnet/position_history/PositionHistory';


function App() {
const { walletId, setWalletId, removeWalletId } = useWalletStore();
const [showModal, setShowModal] = useState(false);
const navigate = useNavigate();
const [isMobileRestrictionModalOpen, setisMobileRestrictionModalOpen] = useState(true);
const isMobile = useCheckMobile();

const disableDesktopOnMobile = process.env.REACT_APP_DISABLE_DESKTOP_ON_MOBILE !== 'false';

const connectWalletMutation = useConnectWallet(setWalletId);

Expand All @@ -47,6 +54,15 @@ function App() {
setShowModal(false);
};


const handleisMobileRestrictionModalClose = () => {
setisMobileRestrictionModalOpen(false);
};

const openTelegramBot = () => {
window.open(TELEGRAM_BOT_LINK, '_blank');
};

useEffect(() => {
if (window.Telegram?.WebApp?.initData) {
getTelegramUserWalletId(window.Telegram.WebApp.initDataUnsafe.user.id)
Expand All @@ -62,6 +78,7 @@ function App() {
}
}, [window.Telegram?.WebApp?.initDataUnsafe]);


return (
<div className="App">
<Notifier />
Expand Down Expand Up @@ -96,8 +113,20 @@ function App() {
</Routes>
</main>
<Footer />
{isMobile && disableDesktopOnMobile && (
<ActionModal
isOpen={isMobileRestrictionModalOpen}
title="Mobile website restriction"
subTitle="Please, use desktop version or telegram mini-app"
content={[]}
cancelLabel="Cancel"
submitLabel="Open in Telegram"
submitAction={openTelegramBot}
cancelAction={handleisMobileRestrictionModalClose}
/>
)}
</div>
);
}

export default App;
export default App;
26 changes: 26 additions & 0 deletions frontend/src/hooks/useCheckMobile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useState, useEffect } from 'react';

export const useCheckMobile = () => {
const [isMobile, setIsMobile] = useState(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);
const isMobileWidth = window.innerWidth <= 768;

setIsMobile(isMobileDevice || isMobileWidth);
};

checkMobile();

window.addEventListener('resize', checkMobile);

return () => window.removeEventListener('resize', checkMobile);
}, []);

return isMobile;
};
2 changes: 2 additions & 0 deletions frontend/src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const USDC_ADDRESS = '0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5

export const ONE_HOUR_IN_MILLISECONDS = 3600000;

export const TELEGRAM_BOT_LINK = 'https://t.me/spotnet_bot';

export function getDeployContractData(walletId) {
return {
classHash: CLASS_HASH,
Expand Down
10 changes: 6 additions & 4 deletions web_app/db/seed_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ def create_users(session: SessionLocal) -> list[User]:
"""
users = []
for _ in range(10):
wallet_id = fake.unique.uuid4()
print('wallet_id:', wallet_id)
user = User(
wallet_id=fake.unique.uuid4(),
wallet_id=wallet_id,
contract_address=fake.address(),
is_contract_deployed=fake.boolean(),
)
Expand All @@ -49,7 +51,7 @@ def create_positions(session: SessionLocal, users: list[User]) -> None:
for _ in range(2):
position = Position(
user_id=user.id,
token_symbol=fake.random_choices(
token_symbol=fake.random_element(
elements=[token.name for token in TokenParams.tokens()]
),
amount=fake.random_number(digits=5),
Expand Down Expand Up @@ -157,8 +159,8 @@ def create_vaults(session: SessionLocal, users: list[User]) -> None:
# Populate the database
users = create_users(session)
create_positions(session, users)
create_airdrops(session, users)
create_telegram_users(session, users)
# create_airdrops(session, users)
# create_telegram_users(session, users)
create_vaults(session, users)

logger.info("Database populated with fake data.")

0 comments on commit a74ca21

Please sign in to comment.