Skip to content

Commit

Permalink
remove unnecessary changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JFrankfurt committed Aug 1, 2023
1 parent 4e186f7 commit beebc6d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
3 changes: 1 addition & 2 deletions example/connectors/walletConnectV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import { WalletConnect as WalletConnectV2 } from '@web3-react/walletconnect-v2'
import { MAINNET_CHAINS } from '../chains'

const [mainnet, ...optionalChains] = Object.keys(MAINNET_CHAINS).map(Number)
const chains = [mainnet]

export const [walletConnectV2, hooks] = initializeConnector<WalletConnectV2>(
(actions) =>
new WalletConnectV2({
actions,
options: {
projectId: process.env.walletConnectProjectId,
chains,
chains: [mainnet],
optionalChains,
showQrModal: true,
},
Expand Down
4 changes: 3 additions & 1 deletion packages/walletconnect-v2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,13 @@ export class WalletConnect extends Connector {
}
}

/**
* @param desiredChainId - The desired chainId to connect to.
*/
public async activate(desiredChainId?: number): Promise<void> {
const provider = await this.isomorphicInitialize(desiredChainId)

if (provider.session) {
console.log(provider.session.namespaces)
if (!desiredChainId || desiredChainId === provider.chainId) return
// WalletConnect exposes connected accounts, not chains: `eip155:${chainId}:${address}`
const isConnectedToDesiredChain = provider.session.namespaces.eip155.accounts.some((account) =>
Expand Down
7 changes: 6 additions & 1 deletion packages/walletconnect-v2/src/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getBestUrlMap } from './utils'
import { getBestUrlMap, getChainsWithDefault } from './utils'

class MockHttpConnection {
public readonly succeed: boolean
Expand Down Expand Up @@ -74,3 +74,8 @@ describe('getBestUrl', () => {
})
})

describe('getChainsWithDefault', () => {
test('puts the default chain first at the beginning', () => {
expect(getChainsWithDefault([1, 2, 3], 3)).toEqual([3, 1, 2])
})
})
2 changes: 1 addition & 1 deletion packages/walletconnect-v2/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async function getBestUrl(urls: string | string[], timeout: number): Promise<str
* @param chains - An array of chain IDs.
* @param defaultChainId - The chain ID to treat as the default (it will be the first element in the returned array).
*/
export function getChainsWithDefault(chains: number[], defaultChainId: number): number[] {
export function getChainsWithDefault(chains: number[], defaultChainId: number) {
const idx = chains.indexOf(defaultChainId)
if (idx === -1) {
throw new Error(
Expand Down

0 comments on commit beebc6d

Please sign in to comment.