Skip to content

Commit

Permalink
chore: tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Mar 27, 2024
1 parent 50c6318 commit e1ca4e6
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-planes-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wagmi/cli": patch
---

Added title to CLI process.
7 changes: 7 additions & 0 deletions .changeset/purple-mangos-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@wagmi/connectors": patch
"@wagmi/core": patch
"wagmi": patch
---

Deprecated `normalizeChainId`. Use `Number` instead.
12 changes: 11 additions & 1 deletion docs/shared/utilities/normalizeChainId.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ import { normalizeChainId } from '{{packageName}}'

## Usage

:::warning Deprecated
Use `Number` instead.

```ts-vue
import { normalizeChainId } from '{{packageName}}' // [!code --]
const chainId = normalizeChainId(123n) // [!code --]
const chainId = Number(123n) // [!code ++]
```
:::

```ts-vue
import { normalizeChainId } from '{{packageName}}'
Expand Down Expand Up @@ -43,4 +53,4 @@ normalizeChainId('0x1')

`number`

The normalized chain ID.
The normalized chain ID.
4 changes: 4 additions & 0 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ cli.help()
cli.version(version)

void (async () => {
try {
process.title = 'node (wagmi)'
} catch {}

try {
// Parse CLI args without running command
cli.parse(process.argv, { run: false })
Expand Down
11 changes: 4 additions & 7 deletions packages/connectors/src/coinbaseWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import {
type CoinbaseWalletProvider,
type CoinbaseWalletSDK,
} from '@coinbase/wallet-sdk'
import {
ChainNotConfiguredError,
createConnector,
normalizeChainId,
} from '@wagmi/core'
import { ChainNotConfiguredError, createConnector } from '@wagmi/core'
import type { Evaluate, Mutable, Omit } from '@wagmi/core/internal'
import {
type ProviderRpcError,
Expand Down Expand Up @@ -111,7 +107,7 @@ export function coinbaseWallet(parameters: CoinbaseWalletParameters) {
async getChainId() {
const provider = await this.getProvider()
const chainId = await provider.request<number>({ method: 'eth_chainId' })
return normalizeChainId(chainId)
return Number(chainId)
},
async getProvider() {
if (!walletProvider) {
Expand Down Expand Up @@ -147,6 +143,7 @@ export function coinbaseWallet(parameters: CoinbaseWalletParameters) {

walletProvider = sdk.makeWeb3Provider(jsonRpcUrl, chainId)
}

return walletProvider
},
async isAuthorized() {
Expand Down Expand Up @@ -203,7 +200,7 @@ export function coinbaseWallet(parameters: CoinbaseWalletParameters) {
})
},
onChainChanged(chain) {
const chainId = normalizeChainId(chain)
const chainId = Number(chain)
config.emitter.emit('change', { chainId })
},
async onDisconnect(_error) {
Expand Down
12 changes: 4 additions & 8 deletions packages/connectors/src/metaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import {
type MetaMaskSDKOptions,
type SDKProvider,
} from '@metamask/sdk'
import {
ChainNotConfiguredError,
createConnector,
normalizeChainId,
} from '@wagmi/core'
import { ChainNotConfiguredError, createConnector } from '@wagmi/core'
import type { Evaluate, ExactPartial, Omit } from '@wagmi/core/internal'
import {
type Address,
Expand Down Expand Up @@ -169,7 +165,7 @@ export function metaMask(parameters: MetaMaskParameters = {}) {
const provider = await this.getProvider()
const chainId =
provider.chainId ?? (await provider?.request({ method: 'eth_chainId' }))
return normalizeChainId(chainId)
return Number(chainId)
},
async getProvider() {
if (!walletProvider) {
Expand Down Expand Up @@ -303,14 +299,14 @@ export function metaMask(parameters: MetaMaskParameters = {}) {
})
},
onChainChanged(chain) {
const chainId = normalizeChainId(chain)
const chainId = Number(chain)
config.emitter.emit('change', { chainId })
},
async onConnect(connectInfo) {
const accounts = await this.getAccounts()
if (accounts.length === 0) return

const chainId = normalizeChainId(connectInfo.chainId)
const chainId = Number(connectInfo.chainId)
config.emitter.emit('connect', { accounts, chainId })

const provider = await this.getProvider()
Expand Down
8 changes: 2 additions & 6 deletions packages/connectors/src/safe.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { type SafeAppProvider } from '@safe-global/safe-apps-provider'
import { type Opts } from '@safe-global/safe-apps-sdk'
import {
ProviderNotFoundError,
createConnector,
normalizeChainId,
} from '@wagmi/core'
import { ProviderNotFoundError, createConnector } from '@wagmi/core'
import type { Evaluate } from '@wagmi/core/internal'
import { getAddress } from 'viem'

Expand Down Expand Up @@ -98,7 +94,7 @@ export function safe(parameters: SafeParameters = {}) {
async getChainId() {
const provider = await this.getProvider()
if (!provider) throw new ProviderNotFoundError()
return normalizeChainId(provider.chainId)
return Number(provider.chainId)
},
async isAuthorized() {
try {
Expand Down
5 changes: 2 additions & 3 deletions packages/connectors/src/walletConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
ChainNotConfiguredError,
ProviderNotFoundError,
createConnector,
normalizeChainId,
} from '@wagmi/core'
import {
type Evaluate,
Expand Down Expand Up @@ -305,11 +304,11 @@ export function walletConnect(parameters: WalletConnectParameters) {
})
},
onChainChanged(chain) {
const chainId = normalizeChainId(chain)
const chainId = Number(chain)
config.emitter.emit('change', { chainId })
},
async onConnect(connectInfo) {
const chainId = normalizeChainId(connectInfo.chainId)
const chainId = Number(connectInfo.chainId)
const accounts = await this.getAccounts()
config.emitter.emit('connect', { accounts, chainId })
},
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/connectors/injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import { ChainNotConfiguredError } from '../errors/config.js'
import { ProviderNotFoundError } from '../errors/connector.js'
import { type Evaluate } from '../types/utils.js'
import { normalizeChainId } from '../utils/normalizeChainId.js'
import { createConnector } from './createConnector.js'

export type InjectedParameters = {
Expand Down Expand Up @@ -241,7 +240,7 @@ export function injected(parameters: InjectedParameters = {}) {
const provider = await this.getProvider()
if (!provider) throw new ProviderNotFoundError()
const hexChainId = await provider.request({ method: 'eth_chainId' })
return normalizeChainId(hexChainId)
return Number(hexChainId)
},
async getProvider() {
if (typeof window === 'undefined') return undefined
Expand Down Expand Up @@ -427,14 +426,14 @@ export function injected(parameters: InjectedParameters = {}) {
})
},
onChainChanged(chain) {
const chainId = normalizeChainId(chain)
const chainId = Number(chain)
config.emitter.emit('change', { chainId })
},
async onConnect(connectInfo) {
const accounts = await this.getAccounts()
if (accounts.length === 0) return

const chainId = normalizeChainId(connectInfo.chainId)
const chainId = Number(connectInfo.chainId)
config.emitter.emit('connect', { accounts, chainId })

const provider = await this.getProvider()
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/connectors/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
ChainNotConfiguredError,
ConnectorNotConnectedError,
} from '../errors/config.js'
import { normalizeChainId } from '../utils/normalizeChainId.js'
import { createConnector } from './createConnector.js'

export type MockParameters = {
Expand Down Expand Up @@ -112,7 +111,7 @@ export function mock(parameters: MockParameters) {
})
},
onChainChanged(chain) {
const chainId = normalizeChainId(chain)
const chainId = Number(chain)
config.emitter.emit('change', { chainId })
},
async onDisconnect(_error) {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utils/normalizeChainId.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @deprecated use `Number` instead */
export function normalizeChainId(chainId: bigint | number | string | unknown) {
if (typeof chainId === 'string')
return Number.parseInt(
Expand Down

0 comments on commit e1ca4e6

Please sign in to comment.