-
-
Notifications
You must be signed in to change notification settings - Fork 254
Closed
Labels
team-wallet-frameworkDeprecated: Please use `team-core-platform` instead.Deprecated: Please use `team-core-platform` instead.
Description
Problem
Currently, when an instance of SafeEventEmitterProvider is passed to the Web3Provider constructor from Ethers v5 or the BrowserProvider constructor from Ethers v6, it produces a type error. Web3Provider produces:
Argument of type 'SafeEventEmitterProvider' is not assignable to parameter of type 'ExternalProvider | JsonRpcFetchFunc'.
Type 'SafeEventEmitterProvider' is not assignable to type 'ExternalProvider'.
Types of property 'sendAsync' are incompatible.
Type '(req: JsonRpcRequest<JsonRpcParams>, callback: (error: unknown, providerRes?: any) => void) => void' is not assignable to type '(request: { method: string; params?: any[]; }, callback: (error: any, response: any) => void) => void'.
Types of parameters 'req' and 'request' are incompatible.
Type '{ method: string; params?: any[]; }' is not assignable to type 'JsonRpcRequest<JsonRpcParams>'.
Type '{ method: string; params?: any[]; }' is missing the following properties from type '{ params?: (Record<string, Json> | Json[]) & ExactOptionalGuard; id: string | number | null; method: string; jsonrpc: "2.0"; }': id, jsonrpctypescript(2345)
and BrowserProvider produces:
Argument of type 'SafeEventEmitterProvider' is not assignable to parameter of type 'Eip1193Provider'.
Property 'request' is missing in type 'SafeEventEmitterProvider' but required in type 'Eip1193Provider'.typescript(2345)
The first error happens because Web3Provider allows jsonrpc and id to be missing from the request object, whereas JsonRpcRequest does not; the second error happens because BrowserProvider expects the provider to conform to EIP-1193, which specifies that it ought to have a request method.
Proposed Solution
We can address both of these issues by:
- Aligning SafeEventEmitterProvider to EIP-1193 by adding a
requestmethod and deprecatingsendandsendAsync(which aren't part of the spec) - Ensuring that
requestdoes not requireidandjsonrpcto be set, filling them in if they are missing
Acceptance Criteria
- We should be able to pass an instance of SafeEventEmitter to the constructor from each of these libraries without type errors:
Web3Providerconstructor from Ethers v5BrowserProviderconstructor from Ethers v6eth-queryconstructorethjs-queryconstructor
- Using
sendandsendAsyncshould produce deprecation warnings eth-json-rpc-providertests should not usesendandsendAsyncexcept where necessary to test the above
Metadata
Metadata
Assignees
Labels
team-wallet-frameworkDeprecated: Please use `team-core-platform` instead.Deprecated: Please use `team-core-platform` instead.