Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
refactor: remove dependency to @metamask/providers + use local BasePr…
Browse files Browse the repository at this point in the history
…ovider type
  • Loading branch information
ccharly committed Mar 18, 2024
1 parent 36ae5cd commit 260b8e7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"test:watch": "jest --watch"
},
"dependencies": {
"@metamask/providers": "^16.0.0",
"@metamask/snaps-sdk": "^3.1.1",
"@metamask/utils": "^8.3.0",
"@types/uuid": "^9.0.1",
Expand Down
12 changes: 6 additions & 6 deletions src/KeyringSnapRpcClient.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { MetaMaskInpageProvider } from '@metamask/providers';
import type { Json } from '@metamask/utils';

import type { JsonRpcRequest } from './JsonRpcRequest';
import type { Sender } from './KeyringClient';
import { KeyringClient } from './KeyringClient';
import type { BaseProvider } from './providers';

/**
* Implementation of the `Sender` interface that can be used to send requests
Expand All @@ -12,15 +12,15 @@ import { KeyringClient } from './KeyringClient';
export class SnapRpcSender implements Sender {
#origin: string;

#provider: MetaMaskInpageProvider;
#provider: BaseProvider;

/**
* Create a new instance of `SnapRpcSender`.
*
* @param origin - The caller's origin.
* @param provider - The `MetaMaskInpageProvider` instance to use.
* @param provider - The provider instance to use.
*/
constructor(origin: string, provider: MetaMaskInpageProvider) {
constructor(origin: string, provider: BaseProvider) {
this.#origin = origin;
this.#provider = provider;
}
Expand Down Expand Up @@ -51,9 +51,9 @@ export class KeyringSnapRpcClient extends KeyringClient {
* Create a new instance of `KeyringSnapRpcClient`.
*
* @param origin - Caller's origin.
* @param provider - The `MetaMaskInpageProvider` instance to use.
* @param provider - The provider instance to use.
*/
constructor(origin: string, provider: MetaMaskInpageProvider) {
constructor(origin: string, provider: BaseProvider) {
super(new SnapRpcSender(origin, provider));
}
}
28 changes: 28 additions & 0 deletions src/providers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export type Maybe<Type> = Partial<Type> | null | undefined;

export type RequestArguments = {
/** The RPC method to request. */
method: string;

/** The params of the RPC method, if any. */
params?: unknown[] | Record<string, unknown>;
};

/**
* We do re-declare locally the minimum interface from @metamask/providers here. This way this avoid
* depending on it "globally" and thus ease incompatible versions (this generally clash with
* the @metamask/snaps-sdk and @metamask/keyring-api packages!
*/
export type BaseProvider = {
/**
* Submits an RPC request for the given method, with the given params.
* Resolves with the result of the method call, or rejects on error.
*
* @param args - The RPC request arguments.
* @param args.method - The RPC method name.
* @param args.params - The parameters for the RPC method.
* @returns A Promise that resolves with the result of the RPC method,
* or rejects if an error is encountered.
*/
request<Type>(args: RequestArguments): Promise<Maybe<Type>>;
};
21 changes: 0 additions & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,6 @@ __metadata:
"@metamask/eslint-config-jest": ^12.1.0
"@metamask/eslint-config-nodejs": ^12.1.0
"@metamask/eslint-config-typescript": ^12.1.0
"@metamask/providers": ^16.0.0
"@metamask/snaps-sdk": ^3.1.1
"@metamask/utils": ^8.3.0
"@types/jest": ^28.1.6
Expand Down Expand Up @@ -1121,26 +1120,6 @@ __metadata:
languageName: node
linkType: hard

"@metamask/providers@npm:^16.0.0":
version: 16.0.0
resolution: "@metamask/providers@npm:16.0.0"
dependencies:
"@metamask/json-rpc-engine": ^7.3.2
"@metamask/json-rpc-middleware-stream": ^6.0.2
"@metamask/object-multiplex": ^2.0.0
"@metamask/rpc-errors": ^6.2.1
"@metamask/safe-event-emitter": ^3.0.0
"@metamask/utils": ^8.3.0
detect-browser: ^5.2.0
extension-port-stream: ^3.0.0
fast-deep-equal: ^3.1.3
is-stream: ^2.0.0
readable-stream: ^3.6.2
webextension-polyfill: ^0.10.0
checksum: cdc06796111edbf01e9aa8498170f7ffa3c68a4c0f66a629e3b0f7d37ee60eb32d83ee12f285c3d974d971c6af16a3fba531fb5733f5fa9412a18e1d3f648539
languageName: node
linkType: hard

"@metamask/rpc-errors@npm:^6.2.1":
version: 6.2.1
resolution: "@metamask/rpc-errors@npm:6.2.1"
Expand Down

0 comments on commit 260b8e7

Please sign in to comment.