-
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): reapply "feat(wallets): add metaMask SDK connector (#5028
)" (#5215) (#5223) * Reapply "feat(wallets): add metaMask SDK connector (#5028)" (#5215) This reverts commit 889b78e. * chore: update MetaMask SDK to 0.31.4 --------- Co-authored-by: Leandro <[email protected]>
- Loading branch information
1 parent
1626a04
commit 28fcda9
Showing
12 changed files
with
681 additions
and
65 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.