Skip to content

Commit

Permalink
Added injected connector for in-wallet browsers.
Browse files Browse the repository at this point in the history
  • Loading branch information
babkenmes committed Dec 17, 2024
1 parent 017f528 commit b0df030
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions components/WalletProviders/Wagmi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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';
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";
Expand Down Expand Up @@ -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' })] : [])
Expand Down
9 changes: 9 additions & 0 deletions lib/wallets/connectors/getInjectedConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit b0df030

Please sign in to comment.