Skip to content

Commit

Permalink
Add wallet connect example
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz committed May 18, 2022
1 parent f883491 commit 75f986a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export class WalletConnectConnector implements Connector {

private async init() {
if (this.provider) return
this.provider = new Web3Provider(new WalletConnectProvider(this.opts))
const walletConnectProvider = new WalletConnectProvider(this.opts)
await walletConnectProvider.enable()
this.provider = new Web3Provider(walletConnectProvider)
}

async connectEagerly(): Promise<void> {
Expand Down
25 changes: 19 additions & 6 deletions packages/example/src/pages/ConnectorPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react'
import { MetamaskConnector, RpcConnector, useEtherBalance, useEthers } from '@usedapp/core'
import { MetamaskConnector, RpcConnector, WalletConnectConnector, useEtherBalance, useEthers } from '@usedapp/core'
import { Container, ContentBlock, ContentRow, MainContent, Section, SectionRow } from '../components/base/base'
import { Button } from '../components/base/Button'
import { Title } from '../typography/Title'
Expand All @@ -13,6 +13,7 @@ import { Web3Provider } from '@ethersproject/providers'
export const ConnectorPage = () => {
const { account, activate, deactivate } = useEthers()
const metamaskConnector = new MetamaskConnector()
const walletConnectConnector = new WalletConnectConnector({infuraId: 'd8df2cb7844e4a54ab0a782f608749dd',})
const rpcConnector = new RpcConnector('https://mainnet.infura.io/v3/d8df2cb7844e4a54ab0a782f608749dd')
const ethBalance = useEtherBalance(account)

Expand All @@ -36,22 +37,34 @@ export const ConnectorPage = () => {
<LoginButton onClick={deactivate}>Disconnect</LoginButton>
</>
) : (
<LoginButton onClick={() => {void activate(metamaskConnector.provider as Web3Provider)}}>Connect</LoginButton>
<LoginButton onClick={async () => {await metamaskConnector.activate();void activate(metamaskConnector.provider as Web3Provider)}}>Connect</LoginButton>
)}
</Account>
</SectionRow>
{/* <SectionRow>
<SectionRow>
<Title>Rpc Connector</Title>
<Account>
{account ? (
<>
<LoginButton onClick={() => rpcConnector.deactivate()}>Disconnect</LoginButton>
<LoginButton onClick={deactivate}>Disconnect</LoginButton>
</>
) : (
<LoginButton onClick={() => rpcConnector.activate()}>Connect</LoginButton>
<LoginButton onClick={async () => {await rpcConnector.activate();void activate(rpcConnector.provider as Web3Provider)}}>Connect</LoginButton>
)}
</Account>
</SectionRow> */}
</SectionRow>
<SectionRow>
<Title>WalletConnect Connector</Title>
<Account>
{account ? (
<>
<LoginButton onClick={deactivate}>Disconnect</LoginButton>
</>
) : (
<LoginButton onClick={async () => {await walletConnectConnector.activate();void activate(walletConnectConnector.provider)}}>Connect</LoginButton>
)}
</Account>
</SectionRow>
<ContentBlock>
{account && (
<ContentRow>
Expand Down

0 comments on commit 75f986a

Please sign in to comment.