Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/connect-evm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add `ConnectEvm.status` property which exposes the current `ConnectionStatus` ([#136](https://github.com/MetaMask/connect-monorepo/pull/136))

### Fixed

- Fix `eth_chainId` requests not being resolved from local cached state when using the EIP-1193 Provider `request()` method over the `MwpTransport` ([#124](https://github.com/MetaMask/connect-monorepo/pull/124))

## [0.2.0]

### Added
Expand Down
5 changes: 5 additions & 0 deletions packages/connect-evm/src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { getPermittedEthChainIds } from './utils/caip';
import {
isAccountsRequest,
isAddChainRequest,
isChainIdRequest,
isConnectRequest,
isSwitchChainRequest,
validSupportedChainsUrls,
Expand Down Expand Up @@ -633,6 +634,10 @@ export class MetamaskConnectEVM {
return this.#provider.accounts;
}

if (isChainIdRequest(request)) {
return this.#provider.selectedChainId;
}

logger('Request not intercepted, forwarding to default handler', request);
return Promise.resolve();
}
Expand Down
3 changes: 3 additions & 0 deletions packages/connect-evm/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ export const CONNECT_METHODS = [

export const ACCOUNTS_METHODS = ['eth_accounts', 'eth_coinbase'];

export const CHAIN_METHODS = ['eth_chainId'];

export const INTERCEPTABLE_METHODS = [
...ACCOUNTS_METHODS,
...IGNORED_METHODS,
...CONNECT_METHODS,
...CHAIN_METHODS,
// These have bespoke handlers
'wallet_revokePermissions',
'wallet_switchEthereumChain',
Expand Down
12 changes: 12 additions & 0 deletions packages/connect-evm/src/utils/type-guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ export function isAccountsRequest(
return req.method === 'eth_accounts' || req.method === 'eth_coinbase';
}

/**
* Type guard for generic eth_chainId request.
*
* @param req - The request object to check
* @returns True if the request is a eth_chainId request, false otherwise
*/
export function isChainIdRequest(
req: ProviderRequest,
): req is Extract<ProviderRequest, { method: 'eth_chainId' }> {
return req.method === 'eth_chainId';
}

/**
* Validates that all values in a Record are valid URLs.
*
Expand Down
Loading