-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve conflicts between evm providers
- Loading branch information
1 parent
8091128
commit 9a6734c
Showing
7 changed files
with
115 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,95 @@ | ||
import { getCoinbaseInstance } from '@rango-dev/wallets-shared'; | ||
function isMetamaskProvider(ethereum: any): boolean { | ||
const isMetamask = !!ethereum?.isMetaMask; | ||
if (!isMetamask) { | ||
return false; | ||
} | ||
/* | ||
* Brave tries to make itself look like MetaMask | ||
* Could also try RPC `web3_clientVersion` if following is unreliable | ||
*/ | ||
if (ethereum.isBraveWallet && !ethereum._events && !ethereum._state) { | ||
return false; | ||
} | ||
if (ethereum.isApexWallet) { | ||
return false; | ||
} | ||
if (ethereum.isAvalanche) { | ||
return false; | ||
} | ||
if (ethereum.isBitKeep) { | ||
return false; | ||
} | ||
if (ethereum.isBlockWallet) { | ||
return false; | ||
} | ||
if (ethereum.isCoin98) { | ||
return false; | ||
} | ||
if (ethereum.isFordefi) { | ||
return false; | ||
} | ||
if (ethereum.__XDEFI) { | ||
return false; | ||
} | ||
if (ethereum.isMathWallet) { | ||
return false; | ||
} | ||
if (ethereum.isOkxWallet || ethereum.isOKExWallet) { | ||
return false; | ||
} | ||
if (ethereum.isOneInchIOSWallet || ethereum.isOneInchAndroidWallet) { | ||
return false; | ||
} | ||
if (ethereum.isOpera) { | ||
return false; | ||
} | ||
if (ethereum.isPortal) { | ||
return false; | ||
} | ||
if (ethereum.isRabby) { | ||
return false; | ||
} | ||
if (ethereum.isDefiant) { | ||
return false; | ||
} | ||
if (ethereum.isTokenPocket) { | ||
return false; | ||
} | ||
if (ethereum.isTokenary) { | ||
return false; | ||
} | ||
if (ethereum.isZeal) { | ||
return false; | ||
} | ||
if (ethereum.isZerion) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
export function metamask() { | ||
const isCoinbaseWalletAvailable = !!getCoinbaseInstance(); | ||
const { ethereum } = window; | ||
|
||
// Some wallets overriding the metamask. So we need to get it properly. | ||
if (isCoinbaseWalletAvailable) { | ||
// Getting intance from overrided structure from coinbase. | ||
return getCoinbaseInstance('metamask'); | ||
} else { | ||
if (!!ethereum && ethereum.isMetaMask) { | ||
return ethereum; | ||
if (Array.isArray(ethereum?.providers)) { | ||
/* | ||
* When alternative EVM wallets are enabled and take precedence over MetaMask, | ||
* they append MetaMask or other EVM wallets to the ethereum.providers array. | ||
* example: 'Core' wallet | ||
*/ | ||
let providers = ethereum.providers; | ||
//Exceptions exist, such as when only 'MetaMask' and 'Coinbase' are enabled. | ||
if ( | ||
providers.length > 0 && | ||
Array.isArray(ethereum.providers[0]?.providers) && | ||
providers[0]?.providers.length > 0 | ||
) { | ||
providers = providers[0]?.providers; | ||
} | ||
|
||
const metamaskProvider = providers.find(isMetamaskProvider); | ||
if (metamaskProvider) { | ||
return metamaskProvider; | ||
} | ||
} | ||
return null; | ||
return ethereum?.isMetaMask ? ethereum : null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters