Skip to content

Fix provider type errors in NetworkController and its downstream packages #1823

Closed

Description

@MajorLift

Explanation

Tasks

Provider type alignment

  • ProxyWithAccessibleTarget<SafeEventEmitterProvider> (@metamask/network-controller) vs. Provider (@metamask/eth-query)
 error TS2345: Argument of type 'ProxyWithAccessibleTarget<SafeEventEmitterProvider>' is not assignable to parameter of type 'Provider<JsonRpcParams, Json>'.
  Types of property 'sendAsync' are incompatible.
    Type '(req: JsonRpcRequest<JsonRpcParams>, callback: (error: unknown, providerRes?: any) => void) => void' is not assignable to type '<Params, Result>(payload: SendAsyncPayload<Params>, callback: ProviderSendAsyncCallback<Result>) => void'.
      Types of parameters 'req' and 'payload' are incompatible.
        Type 'SendAsyncPayload<Params>' is not assignable to type 'JsonRpcRequest<JsonRpcParams>'.
  • SafeEventEmitterProvider
  • ProviderProxy
  • FakeProvider

References

Activity

  1. self-assigned this
    on Oct 11, 2023
  2. added
    bugSomething isn't working
    team-wallet-frameworkDeprecated: Please use `team-core-platform` instead.
    on Oct 11, 2023
  3. changed the title [-]Fix provider, middleware type errors in NetworkController and downstream packages[/-] [+]Fix provider type errors in `NetworkController` and its downstream packages[/+] on Nov 8, 2023
  4. self-assigned this
    on Nov 9, 2023
  5. mcmire commented on Nov 20, 2023

    @mcmire
    Collaborator

    What's left on this ticket?

  6. MajorLift commented on Nov 20, 2023

    @MajorLift
    ContributorAuthor

    @mcmire I'm still seeing the following error in this PR MetaMask/smart-transactions-controller#237, even after updating @metamask/eth-query and @metamask/network-controller to the latest versions.

    src/SmartTransactionsController.ts:334:31 - error TS2345: Argument of type 'ProxyWithAccessibleTarget<SafeEventEmitterProvider>' is not assignable to parameter of type 'Provider'.
      Types of property 'sendAsync' are incompatible.
        Type '(req: JsonRpcRequest<JsonRpcParams>, callback: (error: unknown, providerRes?: any) => void) => void' is not assignable to type '<Params, Result>(payload: SendAsyncPayload<Params>, callback: ProviderSendAsyncCallback<Result>) => void'.
          Types of parameters 'req' and 'payload' are incompatible.
            Type 'SendAsyncPayload<Params>' is not assignable to type 'JsonRpcRequest<JsonRpcParams>'.
              Type 'SendAsyncPayload<Params>' is not assignable to type '{ params?: ((Record<string, Json> | Json[]) & ExactOptionalGuard) | undefined; id: string | number | null; method: string; jsonrpc: "2.0"; }'.
                Types of property 'params' are incompatible.
                  Type 'Params' is not assignable to type '((Record<string, Json> | Json[]) & ExactOptionalGuard) | undefined'.
                    Type 'Params' is not assignable to type 'Json[] & ExactOptionalGuard'.
                      Type 'Params' is not assignable to type 'Json[]'.
    
    334       ethQuery = new EthQuery(networkClient.provider);

    I think we need to make the following updates to SafeEventEmitterProvider in @metamask/eth-json-rpc-provider to make it align with the @metamask/utils updates.

    diff --git a/packages/eth-json-rpc-provider/src/safe-event-emitter-provider.ts b/packages/eth-json-rpc-provider/src/safe-event-emitter-provider.ts
    index fbf2db3ae..db9298cf0 100644
    --- a/packages/eth-json-rpc-provider/src/safe-event-emitter-provider.ts
    +++ b/packages/eth-json-rpc-provider/src/safe-event-emitter-provider.ts
    @@ -1,6 +1,11 @@
     import type { JsonRpcEngine } from '@metamask/json-rpc-engine';
     import SafeEventEmitter from '@metamask/safe-event-emitter';
    -import type { JsonRpcRequest } from '@metamask/utils';
    +import type {
    +  Json,
    +  JsonRpcParams,
    +  JsonRpcRequest,
    +  JsonRpcResponse,
    +} from '@metamask/utils';
     
     /**
      * An Ethereum provider.
    @@ -34,9 +39,12 @@ export class SafeEventEmitterProvider extends SafeEventEmitter {
        * @param req - The request to send.
        * @param callback - A function that is called upon the success or failure of the request.
        */
    -  sendAsync = (
    -    req: JsonRpcRequest,
    -    callback: (error: unknown, providerRes?: any) => void,
    +  sendAsync = <
    +    Params extends JsonRpcParams = JsonRpcParams,
    +    Result extends Json = Json,
    +  >(
    +    req: JsonRpcRequest<Params>,
    +    callback: (error: unknown, providerRes?: JsonRpcResponse<Result>) => void,
       ) => {
         this.#engine.handle(req, callback);
       };
    @@ -51,9 +59,12 @@ export class SafeEventEmitterProvider extends SafeEventEmitter {
        * @param req - The request to send.
        * @param callback - A function that is called upon the success or failure of the request.
        */
    -  send = (
    -    req: JsonRpcRequest,
    -    callback: (error: unknown, providerRes?: any) => void,
    +  send = <
    +    Params extends JsonRpcParams = JsonRpcParams,
    +    Result extends Json = Json,
    +  >(
    +    req: JsonRpcRequest<Params>,
    +    callback: (error: unknown, providerRes?: JsonRpcResponse<Result>) => void,
       ) => {
         if (typeof callback !== 'function') {
           throw new Error('Must provide callback to "send" method.');
  7. MajorLift commented on Nov 22, 2023

    @MajorLift
    ContributorAuthor

    The above is caused by the @metamask/eth-query version bump in controller-utils (#2028) not being released yet. The issue will be resolved by the next release that includes the unreleased changes in all of @metamask/eth-query's downstream packages in core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workingteam-wallet-frameworkDeprecated: Please use `team-core-platform` instead.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions