Skip to content

Commit b759b1a

Browse files
committed
replace EthJsonRpcProvider with LegacyEthereumProvider
- Remove EthJsonRpcProvider - Add LegacyEthereumProvider defining sendAsync providers
1 parent 68f3aa0 commit b759b1a

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

src/json-rpc-provider-types.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type SafeEventEmitter from '@metamask/safe-event-emitter';
22

3-
import type { Hex } from './hex';
4-
import type { JsonRpcParams, Json } from './json';
3+
import type { JsonRpcParams, JsonRpcRequest, Json } from './json';
54
import type { PartialOrAbsent } from './misc';
65

76
/**
@@ -28,30 +27,37 @@ export type EIP1993Provider = SafeEventEmitter & {
2827
};
2928

3029
/**
31-
* An extension of the EIP-1193 specification for an Ethereum JavaScript Provider.
30+
* The interface for a legacy Ethereum provider.
3231
*
33-
* For details, see:
34-
* - [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193)
35-
* - [BaseProvider]{@link https://github.com/MetaMask/providers/blob/main/src/BaseProvider.ts} in package [@metamask/providers](https://www.npmjs.com/package/@metamask/providers)
36-
* - https://docs.metamask.io/wallet/reference/provider-api/
32+
* This provider follows conventions that pre-date
33+
* [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193). It is not compliant with
34+
* any Ethereum provider standard.
3735
*/
38-
export type EthJsonRpcProvider = EIP1993Provider & {
39-
/**
40-
* The chain ID of the currently connected Ethereum chain, represented as 0x-prefixed hexstring.
41-
* See [chainId.network]{@link https://chainid.network} for more information.
42-
*/
43-
chainId: Hex | null;
44-
36+
export type LegacyEthereumProvider = {
4537
/**
46-
* The user's currently selected Ethereum address as a 0x-prefixed hexstring.
47-
* If read-access is denied, null is returned.
48-
*/
49-
selectedAddress: Hex | null;
50-
51-
/**
52-
* Returns true if the provider has a connection to the network and is able to process requests for the active chain.
38+
* Send a provider request asynchronously.
5339
*
54-
* @returns Whether the provider can process RPC requests.
40+
* @param req - The request to send.
41+
* @param callback - A function that is called upon the success or failure of the request.
5542
*/
56-
isConnected(): boolean;
43+
sendAsync<Result extends Json = Json>(
44+
req: Partial<JsonRpcRequest>,
45+
callback: SendAsyncCallback<Result>,
46+
): void;
5747
};
48+
49+
type SendAsyncCallback<Result extends Json> = (
50+
...args:
51+
| [error: EverythingButNull, result: undefined]
52+
| [error: null, result: Result]
53+
) => void;
54+
55+
// What it says on the tin. We omit `null`, as that value is used for a
56+
// successful response to indicate a lack of an error.
57+
type EverythingButNull =
58+
| string
59+
| number
60+
| boolean
61+
| object
62+
| symbol
63+
| undefined;

0 commit comments

Comments
 (0)