From b0df0309288a1c93bf4926501b3d53fe73b8bfec Mon Sep 17 00:00:00 2001 From: babkenmes Date: Tue, 17 Dec 2024 14:54:13 +0400 Subject: [PATCH] Added injected connector for in-wallet browsers. --- components/WalletProviders/Wagmi.tsx | 6 ++++-- lib/wallets/connectors/getInjectedConnector.ts | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/components/WalletProviders/Wagmi.tsx b/components/WalletProviders/Wagmi.tsx index 0e8f34235..fb556d784 100644 --- a/components/WalletProviders/Wagmi.tsx +++ b/components/WalletProviders/Wagmi.tsx @@ -5,7 +5,7 @@ import { NetworkType } from "../../Models/Network"; import resolveChain from "../../lib/resolveChain"; import React from "react"; import NetworkSettings from "../../lib/NetworkSettings"; -import { WagmiProvider } from 'wagmi' +import { WagmiProvider, injected } from 'wagmi' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { createConfig } from 'wagmi'; import { Chain, http } from 'viem'; @@ -13,7 +13,7 @@ import { WalletModalProvider } from '../WalletModal'; import { my_argent } from '../../lib/wallets/connectors/argent'; import { my_rainbow } from '../../lib/wallets/connectors/rainbow'; import { coinbaseWallet, metaMask, walletConnect } from 'wagmi/connectors' -import { hasInjectedProvider } from '../../lib/wallets/connectors/getInjectedConnector'; +import { hasInjectedProvider, explicitInjectedproviderDetected } from '../../lib/wallets/connectors/getInjectedConnector'; import { my_bitget } from '../../lib/wallets/connectors/bitget'; import { isMobile } from '../../lib/isMobile'; import FuelProviderWrapper from "./FuelProvider"; @@ -47,11 +47,13 @@ function WagmiComponent({ children }: Props) { flag: 'isBitKeep', }); + const enableInjectedConnector = isMobile() && explicitInjectedproviderDetected() const config = createConfig({ connectors: [ coinbaseWallet(), walletConnect({ projectId: WALLETCONNECT_PROJECT_ID, showQrModal: isMobile(), customStoragePrefix: 'walletConnect' }), my_argent({ projectId: WALLETCONNECT_PROJECT_ID, showQrModal: false, customStoragePrefix: 'argent' }), + ...(enableInjectedConnector ? [injected()] : []), ...(!isMetaMaskInjected ? [metaMask()] : []), ...(!isRainbowInjected ? [my_rainbow({ projectId: WALLETCONNECT_PROJECT_ID, showQrModal: false, customStoragePrefix: 'rainbow' })] : []), ...(!isBitKeepInjected ? [my_bitget({ projectId: WALLETCONNECT_PROJECT_ID, showQrModal: false, customStoragePrefix: 'bitget' })] : []) diff --git a/lib/wallets/connectors/getInjectedConnector.ts b/lib/wallets/connectors/getInjectedConnector.ts index 6771d3f2f..56733f554 100644 --- a/lib/wallets/connectors/getInjectedConnector.ts +++ b/lib/wallets/connectors/getInjectedConnector.ts @@ -19,6 +19,15 @@ function getExplicitInjectedProvider(flag: WalletProviderFlags) { : undefined; } + +export function explicitInjectedproviderDetected() { + const _window = + typeof window !== 'undefined' ? (window as WindowProvider) : undefined; + if (typeof _window === 'undefined' || typeof _window.ethereum === 'undefined') + return false; + return !!_window.ethereum; +} + /* * Gets the `window.namespace` window provider if it exists */