fix: detect imtoken injected provider by browser
This commit is contained in:
@@ -138,6 +138,11 @@ export function getInjectedEthereum(): EthereumProvider | null {
|
||||
return maybeWindow.ethereum ?? null;
|
||||
}
|
||||
|
||||
function isImTokenBrowser(): boolean {
|
||||
if (typeof navigator === "undefined") return false;
|
||||
return /imtoken/i.test(navigator.userAgent || "");
|
||||
}
|
||||
|
||||
export function getInjectedWallet(kind?: WalletKind): EthereumProvider | null {
|
||||
const ethereum = getInjectedEthereum();
|
||||
if (!ethereum || !kind) return ethereum;
|
||||
@@ -150,7 +155,15 @@ export function getInjectedWallet(kind?: WalletKind): EthereumProvider | null {
|
||||
if (kind === "imToken") return provider.isImToken;
|
||||
return false;
|
||||
});
|
||||
return match ?? null;
|
||||
if (match) return match;
|
||||
|
||||
// Some imToken mobile versions inject a usable EIP-1193 provider without
|
||||
// setting `isImToken`. Inside the imToken in-app browser, prefer the injected
|
||||
// provider instead of falling back to WalletConnect, which can leave the UI at
|
||||
// connected:no on China networks.
|
||||
if (kind === "imToken" && isImTokenBrowser()) return providers[0] ?? ethereum;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function getConnectedInjectedAddress(
|
||||
|
||||
Reference in New Issue
Block a user