Code Examples from the Repository
Login via Telegram
export const useInitialFetch = () => {
// Get user data from the Redux store
const userData = useAppSelector((state) => state.user)
// Initialize the Telegram login mutation
const [telegramLogin] = useTelegramLoginMutation()
// Get the router object for navigation
const { push } = useRouter()
// Function to check Telegram WebApp and perform login if necessary
const checkTelegramWebApp = async () => {
// Check if running in a browser environment and Telegram WebApp is available
if (typeof window !== 'undefined' && Telegram?.WebApp) {
const initDataUnsafe = Telegram.WebApp?.initDataUnsafe
const telegramUser = initDataUnsafe?.user
const refCode = initDataUnsafe?.start_param
// If Telegram user exists and no user data in the store, perform login
if (telegramUser && !userData?.user) {
await telegramLogin({
id: telegramUser.id,
first_name: telegramUser.first_name,
last_name: telegramUser.last_name,
username: telegramUser.username,
telegramSimpleString: Telegram.WebApp?.initData,
...(refCode && { referralCode: refCode })
}).unwrap()
push(AppPath.LOGIN)
}
} else {
// Retry checking Telegram WebApp after 100ms if not available
setTimeout(checkTelegramWebApp, 100)
}
}
// useEffect to run the checkTelegramWebApp function on component mount
useEffect(() => {
checkTelegramWebApp()
}, [])
}
Adding a Wallet to Metapro ID

Opening in Wallet App using Universal Links

Last updated