Skip to content

Commit c05caab

Browse files
EdouardBougontmm
andauthoredOct 16, 2024··
fix: uniswap wallet trying to make itself look like MetaMask (#4336)
* fix: uniswap wallet trying to make itself look like MetaMask * chore: changeset --------- Co-authored-by: Tom Meagher <tom@meagher.co>
1 parent 608322c commit c05caab

File tree

2 files changed

+65
-56
lines changed

2 files changed

+65
-56
lines changed
 

‎.changeset/brave-students-give.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@wagmi/core": patch
3+
---
4+
5+
Added deprecation notice to `injected` target flags.

‎packages/core/src/connectors/injected.ts

+60-56
Original file line numberDiff line numberDiff line change
@@ -37,59 +37,6 @@ export type InjectedParameters = {
3737
// Regex of wallets/providers that can accurately simulate contract calls & display contract revert reasons.
3838
const supportsSimulationIdRegex = /(rabby|trustwallet)/
3939

40-
const targetMap = {
41-
coinbaseWallet: {
42-
id: 'coinbaseWallet',
43-
name: 'Coinbase Wallet',
44-
provider(window) {
45-
if (window?.coinbaseWalletExtension) return window.coinbaseWalletExtension
46-
return findProvider(window, 'isCoinbaseWallet')
47-
},
48-
},
49-
metaMask: {
50-
id: 'metaMask',
51-
name: 'MetaMask',
52-
provider(window) {
53-
return findProvider(window, (provider) => {
54-
if (!provider.isMetaMask) return false
55-
// Brave tries to make itself look like MetaMask
56-
// Could also try RPC `web3_clientVersion` if following is unreliable
57-
if (provider.isBraveWallet && !provider._events && !provider._state)
58-
return false
59-
// Other wallets that try to look like MetaMask
60-
const flags: WalletProviderFlags[] = [
61-
'isApexWallet',
62-
'isAvalanche',
63-
'isBitKeep',
64-
'isBlockWallet',
65-
'isKuCoinWallet',
66-
'isMathWallet',
67-
'isOkxWallet',
68-
'isOKExWallet',
69-
'isOneInchIOSWallet',
70-
'isOneInchAndroidWallet',
71-
'isOpera',
72-
'isPortal',
73-
'isRabby',
74-
'isTokenPocket',
75-
'isTokenary',
76-
'isZerion',
77-
]
78-
for (const flag of flags) if (provider[flag]) return false
79-
return true
80-
})
81-
},
82-
},
83-
phantom: {
84-
id: 'phantom',
85-
name: 'Phantom',
86-
provider(window) {
87-
if (window?.phantom?.ethereum) return window.phantom?.ethereum
88-
return findProvider(window, 'isPhantom')
89-
},
90-
},
91-
} as const satisfies TargetMap
92-
9340
injected.type = 'injected' as const
9441
export function injected(parameters: InjectedParameters = {}) {
9542
const { shimDisconnect = true, unstable_shimAsyncInject } = parameters
@@ -582,6 +529,62 @@ export function injected(parameters: InjectedParameters = {}) {
582529
}))
583530
}
584531

532+
const targetMap = {
533+
coinbaseWallet: {
534+
id: 'coinbaseWallet',
535+
name: 'Coinbase Wallet',
536+
provider(window) {
537+
if (window?.coinbaseWalletExtension) return window.coinbaseWalletExtension
538+
return findProvider(window, 'isCoinbaseWallet')
539+
},
540+
},
541+
metaMask: {
542+
id: 'metaMask',
543+
name: 'MetaMask',
544+
provider(window) {
545+
return findProvider(window, (provider) => {
546+
if (!provider.isMetaMask) return false
547+
// Brave tries to make itself look like MetaMask
548+
// Could also try RPC `web3_clientVersion` if following is unreliable
549+
if (provider.isBraveWallet && !provider._events && !provider._state)
550+
return false
551+
// Other wallets that try to look like MetaMask
552+
const flags = [
553+
'isApexWallet',
554+
'isAvalanche',
555+
'isBitKeep',
556+
'isBlockWallet',
557+
'isKuCoinWallet',
558+
'isMathWallet',
559+
'isOkxWallet',
560+
'isOKExWallet',
561+
'isOneInchIOSWallet',
562+
'isOneInchAndroidWallet',
563+
'isOpera',
564+
'isPortal',
565+
'isRabby',
566+
'isTokenPocket',
567+
'isTokenary',
568+
'isUniswapWallet',
569+
'isZerion',
570+
] satisfies WalletProviderFlags[]
571+
for (const flag of flags) if (provider[flag]) return false
572+
return true
573+
})
574+
},
575+
},
576+
phantom: {
577+
id: 'phantom',
578+
name: 'Phantom',
579+
provider(window) {
580+
if (window?.phantom?.ethereum) return window.phantom?.ethereum
581+
return findProvider(window, 'isPhantom')
582+
},
583+
},
584+
} as const satisfies TargetMap
585+
586+
type TargetMap = { [_ in TargetId]?: Target | undefined }
587+
585588
type Target = {
586589
icon?: string | undefined
587590
id: string
@@ -599,9 +602,9 @@ type TargetId = Compute<WalletProviderFlags> extends `is${infer name}`
599602
: never
600603
: never
601604

602-
type TargetMap = { [_ in TargetId]?: Target | undefined }
603-
604-
/** @deprecated */
605+
/**
606+
* @deprecated As of 2024/10/16, we are no longer accepting new provider flags as EIP-6963 should be used instead.
607+
*/
605608
type WalletProviderFlags =
606609
| 'isApexWallet'
607610
| 'isAvalanche'
@@ -638,6 +641,7 @@ type WalletProviderFlags =
638641
| 'isTokenary'
639642
| 'isTrust'
640643
| 'isTrustWallet'
644+
| 'isUniswapWallet'
641645
| 'isXDEFI'
642646
| 'isZerion'
643647

0 commit comments

Comments
 (0)
Please sign in to comment.