Skip to content

Commit 8507a82

Browse files
authored
feat: add Uniswap ESLint config (#751)
* feat: add uniswap eslint config * chore: accidentally added while rebasing * chore: fix lint issues
1 parent b52f668 commit 8507a82

File tree

28 files changed

+740
-216
lines changed

28 files changed

+740
-216
lines changed

.eslintrc.js

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
1+
/* eslint-env node */
2+
3+
require('@uniswap/eslint-config/load')
4+
15
module.exports = {
2-
root: true,
3-
parser: '@typescript-eslint/parser',
4-
parserOptions: {
5-
tsconfigRootDir: __dirname,
6-
project: ['./tsconfig.json', './packages/*/tsconfig.json'],
7-
},
8-
plugins: ['@typescript-eslint', 'react-hooks', 'eslint-plugin-tsdoc'],
9-
extends: [
10-
'eslint:recommended',
11-
'plugin:@typescript-eslint/recommended',
12-
'plugin:@typescript-eslint/recommended-requiring-type-checking',
13-
],
6+
extends: '@uniswap/eslint-config/react',
147
rules: {
15-
'react-hooks/rules-of-hooks': 'error',
16-
'react-hooks/exhaustive-deps': 'warn',
17-
'tsdoc/syntax': 'warn',
18-
},
19-
env: {
20-
browser: true,
21-
},
8+
'import/no-unused-modules': 'off'
9+
}
2210
}

.prettierrc.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

example/components/Card.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { GnosisSafe } from '@web3-react/gnosis-safe'
44
import { MetaMask } from '@web3-react/metamask'
55
import { Network } from '@web3-react/network'
66
import { WalletConnect } from '@web3-react/walletconnect'
7+
78
import { getName } from '../utils'
89
import { Accounts } from './Accounts'
910
import { Chain } from './Chain'

example/components/Chain.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Web3ReactHooks } from '@web3-react/core'
2+
23
import { CHAINS } from '../chains'
34

45
export function Chain({ chainId }: { chainId: ReturnType<Web3ReactHooks['useChainId']> }) {

example/components/ConnectWithSelect.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { MetaMask } from '@web3-react/metamask'
55
import { Network } from '@web3-react/network'
66
import { WalletConnect } from '@web3-react/walletconnect'
77
import { useCallback, useState } from 'react'
8+
89
import { CHAINS, getAddChainParameters, URLS } from '../chains'
910

1011
function ChainSelect({

example/components/ProviderExample.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useWeb3React, Web3ReactHooks, Web3ReactProvider } from '@web3-react/cor
33
import { MetaMask } from '@web3-react/metamask'
44
import { Network } from '@web3-react/network'
55
import { WalletConnect } from '@web3-react/walletconnect'
6+
67
import { coinbaseWallet, hooks as coinbaseWalletHooks } from '../connectors/coinbaseWallet'
78
import { hooks as metaMaskHooks, metaMask } from '../connectors/metaMask'
89
import { hooks as networkHooks, network } from '../connectors/network'

example/components/connectorCards/CoinbaseWalletCard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useEffect, useState } from 'react'
2+
23
import { coinbaseWallet, hooks } from '../../connectors/coinbaseWallet'
34
import { Card } from '../Card'
45

example/components/connectorCards/GnosisSafeCard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useEffect, useState } from 'react'
2+
23
import { gnosisSafe, hooks } from '../../connectors/gnosisSafe'
34
import { Card } from '../Card'
45

example/components/connectorCards/MetaMaskCard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useEffect, useState } from 'react'
2+
23
import { hooks, metaMask } from '../../connectors/metaMask'
34
import { Card } from '../Card'
45

example/components/connectorCards/NetworkCard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useEffect, useState } from 'react'
2+
23
import { hooks, network } from '../../connectors/network'
34
import { Card } from '../Card'
45

example/components/connectorCards/WalletConnectCard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { URI_AVAILABLE } from '@web3-react/walletconnect'
22
import { useEffect, useState } from 'react'
3+
34
import { hooks, walletConnect } from '../../connectors/walletConnect'
45
import { Card } from '../Card'
56

example/connectors/coinbaseWallet.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CoinbaseWallet } from '@web3-react/coinbase-wallet'
22
import { initializeConnector } from '@web3-react/core'
3+
34
import { URLS } from '../chains'
45

56
export const [coinbaseWallet, hooks] = initializeConnector<CoinbaseWallet>(

example/connectors/eip1193.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Eip1193Bridge } from '@ethersproject/experimental'
22
import { JsonRpcProvider } from '@ethersproject/providers'
33
import { initializeConnector } from '@web3-react/core'
44
import { EIP1193 } from '@web3-react/eip1193'
5+
56
import { URLS } from '../chains'
67

78
class Eip1193BridgeWithoutAccounts extends Eip1193Bridge {

example/connectors/empty.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { initializeConnector } from '@web3-react/core'
2-
import { Empty, EMPTY } from '@web3-react/empty'
2+
import { EMPTY, Empty } from '@web3-react/empty'
33

44
export const [empty, hooks] = initializeConnector<Empty>(() => EMPTY)

example/connectors/network.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { initializeConnector } from '@web3-react/core'
22
import { Network } from '@web3-react/network'
3+
34
import { URLS } from '../chains'
45

56
export const [network, hooks] = initializeConnector<Network>((actions) => new Network({ actions, urlMap: URLS }))

example/connectors/url.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { initializeConnector } from '@web3-react/core'
22
import { Url } from '@web3-react/url'
3+
34
import { URLS } from '../chains'
45

56
export const [url, hooks] = initializeConnector<Url>((actions) => new Url({ actions, url: URLS[1][0] }))

example/connectors/walletConnect.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { initializeConnector } from '@web3-react/core'
22
import { WalletConnect } from '@web3-react/walletconnect'
3+
34
import { URLS } from '../chains'
45

56
export const [walletConnect, hooks] = initializeConnector<WalletConnect>(

example/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { CoinbaseWallet } from '@web3-react/coinbase-wallet'
22
import { GnosisSafe } from '@web3-react/gnosis-safe'
33
import { MetaMask } from '@web3-react/metamask'
44
import { Network } from '@web3-react/network'
5-
import { WalletConnect } from '@web3-react/walletconnect'
65
import type { Connector } from '@web3-react/types'
6+
import { WalletConnect } from '@web3-react/walletconnect'
77

88
export function getName(connector: Connector) {
99
if (connector instanceof MetaMask) return 'MetaMask'

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@
2626
"@types/react": "^18.0.5",
2727
"@typescript-eslint/eslint-plugin": "^5.19.0",
2828
"@typescript-eslint/parser": "^5.19.0",
29+
"@uniswap/eslint-config": "^1.1.1",
2930
"@walletconnect/ethereum-provider": "^1.7.8",
3031
"eslint": "^8.13.0",
31-
"eslint-plugin-react-hooks": "^4.4.0",
32-
"eslint-plugin-tsdoc": "^0.2.16",
3332
"eth-provider": "^0.9.4",
3433
"jest": "^27.5.1",
3534
"lerna": "^4.0.0",
36-
"prettier": "2.6.2",
3735
"react": "^18.0.0",
3836
"react-test-renderer": "^18.0.0",
3937
"ts-jest": "^27.1.4",

packages/coinbase-wallet/src/index.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ export class CoinbaseWallet extends Connector {
8989

9090
// Wallets may resolve eth_chainId and hang on eth_accounts pending user interaction, which may include changing
9191
// chains; they should be requested serially, with accounts first, so that the chainId can settle.
92-
const accounts = await this.provider.request<string[]>({ method: 'eth_accounts' })
92+
const accounts = await this.provider.request<string[]>({ method: 'eth_accounts' })
9393
if (!accounts.length) throw new Error('No accounts returned')
94-
const chainId = await this.provider.request<string>({ method: 'eth_chainId' })
94+
const chainId = await this.provider.request<string>({ method: 'eth_chainId' })
9595
this.actions.update({ chainId: parseChainId(chainId), accounts })
9696
} catch (error) {
9797
cancelActivation()
@@ -118,21 +118,23 @@ export class CoinbaseWallet extends Connector {
118118
if (!desiredChainId || desiredChainId === parseChainId(this.provider.chainId)) return
119119

120120
const desiredChainIdHex = `0x${desiredChainId.toString(16)}`
121-
return this.provider.request<void>({
122-
method: 'wallet_switchEthereumChain',
123-
params: [{ chainId: desiredChainIdHex }],
124-
}).catch(async (error: ProviderRpcError) => {
125-
if (error.code === 4902 && typeof desiredChainIdOrChainParameters !== 'number') {
126-
if (!this.provider) throw new Error('No provider')
127-
// if we're here, we can try to add a new network
128-
return this.provider.request<void>({
129-
method: 'wallet_addEthereumChain',
130-
params: [{ ...desiredChainIdOrChainParameters, chainId: desiredChainIdHex }],
131-
})
132-
}
121+
return this.provider
122+
.request<void>({
123+
method: 'wallet_switchEthereumChain',
124+
params: [{ chainId: desiredChainIdHex }],
125+
})
126+
.catch(async (error: ProviderRpcError) => {
127+
if (error.code === 4902 && typeof desiredChainIdOrChainParameters !== 'number') {
128+
if (!this.provider) throw new Error('No provider')
129+
// if we're here, we can try to add a new network
130+
return this.provider.request<void>({
131+
method: 'wallet_addEthereumChain',
132+
params: [{ ...desiredChainIdOrChainParameters, chainId: desiredChainIdHex }],
133+
})
134+
}
133135

134-
throw error
135-
})
136+
throw error
137+
})
136138
}
137139

138140
const cancelActivation = this.actions.startActivation()

packages/core/src/provider.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { BaseProvider, Web3Provider } from '@ethersproject/providers'
33
import type { Connector, Web3ReactStore } from '@web3-react/types'
44
import type { Context, MutableRefObject, ReactNode } from 'react'
55
import React, { createContext, useContext, useRef } from 'react'
6+
67
import type { Web3ReactHooks, Web3ReactPriorityHooks } from './hooks'
78
import { getPriorityConnector } from './hooks'
89

packages/eip1193/src/index.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ export class EIP1193 extends Connector {
4949
// Wallets may resolve eth_chainId and hang on eth_accounts pending user interaction, which may include changing
5050
// chains; they should be requested serially, with accounts first, so that the chainId can settle.
5151
const accounts = await requestAccounts()
52-
const chainId = await this.provider.request({ method: 'eth_chainId' }) as string
52+
const chainId = (await this.provider.request({ method: 'eth_chainId' })) as string
5353
this.actions.update({ chainId: parseChainId(chainId), accounts })
5454
} catch (error) {
55-
cancelActivation()
56-
throw error
55+
cancelActivation()
56+
throw error
5757
}
5858
}
5959

@@ -64,8 +64,11 @@ export class EIP1193 extends Connector {
6464

6565
/** {@inheritdoc Connector.activate} */
6666
public async activate(): Promise<void> {
67-
return this.activateAccounts(() => this.provider
68-
.request({ method: 'eth_requestAccounts' })
69-
.catch(() => this.provider.request({ method: 'eth_accounts' })) as Promise<string[]>)
67+
return this.activateAccounts(
68+
() =>
69+
this.provider
70+
.request({ method: 'eth_requestAccounts' })
71+
.catch(() => this.provider.request({ method: 'eth_accounts' })) as Promise<string[]>
72+
)
7073
}
7174
}

packages/eip1193/src/mock.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { ProviderRpcError, RequestArguments } from '@web3-react/types'
21
import { EventEmitter } from 'node:events'
32

3+
import type { ProviderRpcError, RequestArguments } from '@web3-react/types'
4+
45
export class MockEIP1193Provider extends EventEmitter {
56
public chainId?: string
67
public accounts?: string[]

packages/metamask/src/index.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import type {
1010
import { Connector } from '@web3-react/types'
1111

1212
type MetaMaskProvider = Provider & {
13-
isMetaMask?: boolean; isConnected?: () => boolean
13+
isMetaMask?: boolean
14+
isConnected?: () => boolean
1415
providers?: MetaMaskProvider[]
1516
get chainId(): string
1617
get accounts(): string[]
@@ -104,16 +105,16 @@ export class MetaMask extends Connector {
104105

105106
// Wallets may resolve eth_chainId and hang on eth_accounts pending user interaction, which may include changing
106107
// chains; they should be requested serially, with accounts first, so that the chainId can settle.
107-
const accounts = await this.provider.request({ method: 'eth_accounts' }) as string[]
108+
const accounts = (await this.provider.request({ method: 'eth_accounts' })) as string[]
108109
if (!accounts.length) throw new Error('No accounts returned')
109-
const chainId = await this.provider.request({ method: 'eth_chainId' }) as string
110+
const chainId = (await this.provider.request({ method: 'eth_chainId' })) as string
110111
this.actions.update({ chainId: parseChainId(chainId), accounts })
111112
} catch (error) {
112-
console.debug('Could not connect eagerly', error)
113-
// we should be able to use `cancelActivation` here, but on mobile, metamask emits a 'connect'
114-
// event, meaning that chainId is updated, and cancelActivation doesn't work because an intermediary
115-
// update has occurred, so we reset state instead
116-
this.actions.resetState()
113+
console.debug('Could not connect eagerly', error)
114+
// we should be able to use `cancelActivation` here, but on mobile, metamask emits a 'connect'
115+
// event, meaning that chainId is updated, and cancelActivation doesn't work because an intermediary
116+
// update has occurred, so we reset state instead
117+
this.actions.resetState()
117118
}
118119
}
119120

@@ -136,8 +137,8 @@ export class MetaMask extends Connector {
136137

137138
// Wallets may resolve eth_chainId and hang on eth_accounts pending user interaction, which may include changing
138139
// chains; they should be requested serially, with accounts first, so that the chainId can settle.
139-
const accounts = await this.provider.request({ method: 'eth_requestAccounts' }) as string[]
140-
const chainId = await this.provider.request({ method: 'eth_chainId' }) as string
140+
const accounts = (await this.provider.request({ method: 'eth_requestAccounts' })) as string[]
141+
const chainId = (await this.provider.request({ method: 'eth_chainId' })) as string
141142
const receivedChainId = parseChainId(chainId)
142143
const desiredChainId =
143144
typeof desiredChainIdOrChainParameters === 'number'
@@ -151,10 +152,11 @@ export class MetaMask extends Connector {
151152
const desiredChainIdHex = `0x${desiredChainId.toString(16)}`
152153

153154
// if we're here, we can try to switch networks
154-
return this.provider.request({
155-
method: 'wallet_switchEthereumChain',
156-
params: [{ chainId: desiredChainIdHex }],
157-
})
155+
return this.provider
156+
.request({
157+
method: 'wallet_switchEthereumChain',
158+
params: [{ chainId: desiredChainIdHex }],
159+
})
158160
.catch((error: ProviderRpcError) => {
159161
if (error.code === 4902 && typeof desiredChainIdOrChainParameters !== 'number') {
160162
if (!this.provider) throw new Error('No provider')

packages/network/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { JsonRpcProvider } from '@ethersproject/providers'
22
import type { ConnectionInfo } from '@ethersproject/web'
33
import type { Actions } from '@web3-react/types'
44
import { Connector } from '@web3-react/types'
5+
56
import { getBestProvider } from './utils'
67

78
type url = string | ConnectionInfo

packages/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { EventEmitter } from 'node:events'
2+
23
import type { StoreApi } from 'zustand'
34

45
export interface Web3ReactState {

packages/walletconnect/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import type { EventEmitter } from 'node:events'
2+
13
import type WalletConnectProvider from '@walletconnect/ethereum-provider'
24
import type { IWCEthRpcConnectionOptions } from '@walletconnect/types'
35
import type { Actions, ProviderRpcError } from '@web3-react/types'
46
import { Connector } from '@web3-react/types'
57
import EventEmitter3 from 'eventemitter3'
6-
import type { EventEmitter } from 'node:events'
8+
79
import { getBestUrl } from './utils'
810

911
export const URI_AVAILABLE = 'URI_AVAILABLE'

0 commit comments

Comments
 (0)