-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wallets): add metaMask SDK connector (#5028)
* feat: add metaMask SDK connector * fix: display wallet connectors once * fix: load balances and switch network * fix: display installed wallets first when MetaMask isn't installed * fix: babel syntax error * feat: add metaMask SDK connector 0.31.2 * chore: update yarnlock * chore: fix wallets ordering * chore: remove excessive condition --------- Co-authored-by: Baptiste Marchand <[email protected]> Co-authored-by: shoom3301 <[email protected]>
- Loading branch information
1 parent
c45b37d
commit fe8f376
Showing
12 changed files
with
653 additions
and
62 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
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { RPC_URLS } from '@cowprotocol/common-const' | ||
import { initializeConnector } from '@web3-react/core' | ||
|
||
import { onError } from './onError' | ||
|
||
import { default as MetamaskImage } from '../../api/assets/metamask.png' | ||
import { ConnectWalletOption } from '../../api/pure/ConnectWalletOption' | ||
import { ConnectionType } from '../../api/types' | ||
import { getConnectionName } from '../../api/utils/connection' | ||
import { MetaMaskSDK } from '../connectors/metaMaskSdk' | ||
import { useIsActiveConnection } from '../hooks/useIsActiveConnection' | ||
import { ConnectionOptionProps, Web3ReactConnection } from '../types' | ||
|
||
const metaMaskOption = { | ||
color: '#E8831D', | ||
icon: MetamaskImage, | ||
id: 'metamask', | ||
} | ||
|
||
const [web3MetaMask, web3MetaMaskHooks] = initializeConnector<MetaMaskSDK>( | ||
(actions) => | ||
new MetaMaskSDK({ | ||
actions, | ||
options: { | ||
dappMetadata: { | ||
name: 'CoW Swap', | ||
url: 'https://swap.cow.fi', | ||
}, | ||
readonlyRPCMap: Object.fromEntries( | ||
Object.entries(RPC_URLS).map(([chainId, url]) => [`0x${Number(chainId).toString(16)}`, url]), | ||
), | ||
}, | ||
onError, | ||
}), | ||
) | ||
|
||
export const metaMaskSdkConnection: Web3ReactConnection = { | ||
connector: web3MetaMask, | ||
hooks: web3MetaMaskHooks, | ||
type: ConnectionType.METAMASK, | ||
} | ||
|
||
export function MetaMaskSdkOption({ tryActivation, selectedWallet }: ConnectionOptionProps) { | ||
const isActive = useIsActiveConnection(selectedWallet, metaMaskSdkConnection) | ||
|
||
return ( | ||
<ConnectWalletOption | ||
{...metaMaskOption} | ||
isActive={isActive} | ||
onClick={() => tryActivation(metaMaskSdkConnection.connector)} | ||
header={getConnectionName(ConnectionType.METAMASK)} | ||
/> | ||
) | ||
} |
Oops, something went wrong.