-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Link to minimal reproducible example
Steps to Reproduce
- Open a website in Telegram (I entered it from the chat window)
2.Click Connect Wallet to jump to the corresponding wallet application and connect the wallet
3.Back to the Telegram app
Andriod:
https://github.com/user-attachments/assets/4e0cb5e8-05dd-46a4-a409-da7c703e7e60
ios:
https://github.com/user-attachments/assets/f76b1aec-0062-46f6-b667-eced158142f3
iOS will have a wc callback, while Android cannot call the wallet connection. It is normal on the browser. Currently, only Telegram has the problem, and Discord has not been tested yet.
The address that appears after iOS calls the wallet is
metamask://wc?uri=wc%3Ab47cfd59150b12671a91814bc86e209684083a7c3cf705adaa7d8e826b710755%402%3Frelay-protocol%3Dirn%26symKey%3D9f43d8967336cafbfa9a696b86581f30d1801bce5a5ad8ea149ceeb762fe4864%26expiryTimestamp%3D1756523145
The latest discovery is that not only metamask, but also trust and okx have problems
Summary
Use the official demo on the Telegram platform
I tried to use the following code to solve it, but this is invalid
`import { defineNuxtPlugin } from '#imports'
import { createAppKit } from '@reown/appkit/vue'
import { WagmiAdapter } from '@reown/appkit-adapter-wagmi'
import { getWagmiAdapter, networks, solanaWeb3JsAdapter } from '~/config/appkit'
// import type { AppKitNetwork } from '@reown/appkit/networks'
export default defineNuxtPlugin(() => {
console.log('window.ethereum', window.ethereum)
const config = useRuntimeConfig()
const projectId = config.public.projectId || ''
const appkitNetworks = networks
const wagmiAdapter = getWagmiAdapter(projectId)
// 🔥 check Telegram
const isTelegramBrowser = () => {
if (import.meta.server) return false;
const userAgent = navigator.userAgent.toLowerCase();
const url = window.location.href;
const checks = {
// iOS Telegram
hasWebApp: !!window.Telegram?.WebApp,
hasPlatform: !!window.Telegram?.WebApp?.platform,
hasInitData: !!window.Telegram?.WebApp?.initData,
hasVersion: !!window.Telegram?.WebApp?.version,
// Android Telegram
hasWebviewProxy: !!window.TelegramWebviewProxy,
hasWebview: !!window.TelegramWebview,
hasTelegramGlobal: !!window.__telegram,
// User Agent check(Android and iOS )
userAgentTelegram: userAgent.includes('telegram'),
userAgentTgBot: userAgent.includes('tgbot'),
userAgentTelegramBot: userAgent.includes('telegrambot'),
userAgentTgOwt: userAgent.includes('tg_owt'),
userAgentAndroid: userAgent.includes('android') && userAgent.includes('telegram'),
// URL
urlTgWebAppData: url.includes('tgWebAppData'),
urlTgWebAppStartParam: url.includes('tgWebAppStartParam'),
urlTelegram: url.includes('telegram'),
urlTgParam: url.includes('tg_'),
// Referrer
referrerTelegram: document.referrer?.toLowerCase().includes('telegram'),
// Android Telegram
hasAndroidWebView: userAgent.includes('wv') && userAgent.includes('android'),
hasSpecialHeaders: !!document.querySelector('meta[name="telegram-webapp"]'),
hasInlineBot: !!document.querySelector('[data-telegram-inline-bot]'),
inIframe: window.self !== window.top,
hasTelegramTheme: getComputedStyle(document.documentElement).getPropertyValue('--tg-theme-bg-color') !== ''
};
const trueCount = Object.values(checks).filter(Boolean).length;
console.log('🎯 count:', trueCount, '/ ', Object.keys(checks).length);
const isAndroid = userAgent.includes('android');
const isIOS = userAgent.includes('iphone') || userAgent.includes('ipad') || userAgent.includes('ios');
let isTelegram = false;
if (isIOS) {
isTelegram = checks.hasWebApp ||
checks.hasPlatform ||
checks.hasInitData ||
checks.hasVersion ||
checks.userAgentTelegram ||
checks.urlTgWebAppData ||
checks.urlTgWebAppStartParam ||
checks.urlTelegram ||
checks.referrerTelegram ||
trueCount >= 1;
console.log('📱 iOS Telegram :', isTelegram);
console.log('📱 iOS :', {
hasWebApp: checks.hasWebApp,
hasPlatform: checks.hasPlatform,
hasInitData: checks.hasInitData,
hasVersion: checks.hasVersion,
userAgentTelegram: checks.userAgentTelegram,
urlTgWebAppData: checks.urlTgWebAppData,
urlTelegram: checks.urlTelegram,
referrerTelegram: checks.referrerTelegram
});
} else if (isAndroid) {
isTelegram = trueCount >= 1 ||
checks.hasWebviewProxy ||
checks.userAgentTelegram ||
checks.urlTgWebAppData ||
checks.hasAndroidWebView ||
checks.inIframe;
console.log('🤖 Android Telegram :', isTelegram);
} else {
// PC and other
isTelegram = trueCount >= 1; // 🔥
console.log('💻 Desktop Telegram :', isTelegram);
}
// 🔥 If automatic detection fails, check for manual enforcement mode
if (!isTelegram) {
const urlParams = new URLSearchParams(window.location.search);
const forceMode = urlParams.get('telegram') === 'true' ||
urlParams.get('tg') === 'true' ||
localStorage.getItem('force_telegram_mode') === 'true';
if (forceMode) {
console.log('🔧 Telegram mode');
isTelegram = true;
}
}
return isTelegram;
};
const isInTelegram = isTelegramBrowser();
console.log('🔍 AppKit Telegram :', isInTelegram);
createAppKit({
adapters: [wagmiAdapter, solanaWeb3JsAdapter],
networks: appkitNetworks,
projectId,
metadata: {
name: 'Dapp Game',
description: 'A Dapp Game',
url: 'http://localhost/',
icons: ['https://avatars.githubusercontent.com/u/179229932?s=200&v=4']
},
features: {
email: false,
socials: false,
emailShowWallets: false,
swaps: false,
},
allowUnsupportedChain: true,
termsConditionsUrl: "https://luckyx.gitbook.io/luckyx/feng-xian-yu-he-gui/fu-wu-tiao-kuan",
// 🔥
...(isInTelegram && {
enableMobile: true,
enableDesktop: false,
walletConnectOptions: {
qrModalOptions: {
mobileWallets: [
{
id: 'metamask',
name: 'MetaMask',
links: {
native: '',
universal: 'https://metamask.app.link/dapp/' + window.location.host
}
}
]
},
enableMobileWalletSelection: true,
mobileWalletConnectUri: (uri: string) => {
console.log('🔗 WalletConnect URI:', uri);
return `https://metamask.app.link/wc?uri=${encodeURIComponent(uri)}`;
}
},
connectorImages: {
metamask: 'https://avatars.githubusercontent.com/u/11744586?s=200&v=4'
}
})
})
})`
List of related npm package versions
"nuxt": "^3.17.6",
"@reown/appkit": "^1.7.20",
"@reown/appkit-adapter-solana": "^1.7.20",
"@reown/appkit-adapter-wagmi": "^1.7.20",
"@solana/web3.js": "^1.98.2",
"@tanstack/vue-query": "^5.83.0",
"wagmi": "^2.16.0",
"@wagmi/core": "^2.18.0",
"@wagmi/vue": "^0.1.24",
Node.js Version
v22.17.0
Package Manager
pnpm 10.12.4