Skip to content

Commit

Permalink
refactor: connect with walletconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Dec 12, 2021
1 parent c390926 commit c0638e0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/connectors/walletConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export class WalletConnectConnector extends BaseConnector {

async connect() {
try {
if (!this._provider)
this._provider = new WalletConnectProvider(this._options)
// Use new provider instance for every connect
this._provider = new WalletConnectProvider(this._options)

this._provider.on('accountsChanged', this.onAccountsChanged)
this._provider.on('chainChanged', this.onChainChanged)
Expand Down
10 changes: 2 additions & 8 deletions src/hooks/useConnect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'

import { Connector, WalletConnectConnector } from '../connectors'
import { Connector } from '../connectors'
import { useContext } from './useContext'

type State = {
Expand All @@ -23,20 +23,14 @@ export const useConnect = () => {
const activeConnector = globalState?.connector
if (connector === activeConnector) return

// Manually reset connector if user already tried WalletConnect
if (
connector instanceof WalletConnectConnector &&
connector.provider?.isWalletConnect
)
connector.provider = undefined

setState((x) => ({
...x,
loading: true,
connector,
error: undefined,
}))
const data = await connector.connect()

// Update connector globally only after successful connection
setGlobalState((x) => ({ ...x, connector, data }))
setLastUsedConnector(connector.name)
Expand Down

0 comments on commit c0638e0

Please sign in to comment.