From c3c0eb0b13101ca72cf35c364031dec15e84b3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Vincent-Genod?= <37535451+VGLoic@users.noreply.github.com> Date: Fri, 16 Dec 2022 17:34:34 +0100 Subject: [PATCH] feat: add coinbase provider, update verbose type (#59) --- src/providers/coinbase.ts | 19 +++++++++++++++++++ src/providers/index.ts | 1 + src/providers/provider.ts | 6 +++--- src/setup.ts | 16 ++++++++++++---- 4 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 src/providers/coinbase.ts diff --git a/src/providers/coinbase.ts b/src/providers/coinbase.ts new file mode 100644 index 0000000..6ec7d44 --- /dev/null +++ b/src/providers/coinbase.ts @@ -0,0 +1,19 @@ +import { Provider } from "./provider"; + +export class CoinbaseProvider extends Provider { + public isCoinbaseWallet = true; + + public send( + methodOrPayload: string | { method: string; params: unknown[] }, + params?: unknown[] + ) { + if (typeof methodOrPayload === "string") { + return this.request({ method: methodOrPayload, params }); + } else { + return this.request({ + method: methodOrPayload.method, + params: methodOrPayload.params, + }); + } + } +} diff --git a/src/providers/index.ts b/src/providers/index.ts index 4536715..1f4fd42 100644 --- a/src/providers/index.ts +++ b/src/providers/index.ts @@ -1,3 +1,4 @@ export * from "./metamask"; export * from "./provider"; export * from "./wallet-connect"; +export * from "./coinbase"; diff --git a/src/providers/provider.ts b/src/providers/provider.ts index d7070bd..b25cb46 100644 --- a/src/providers/provider.ts +++ b/src/providers/provider.ts @@ -7,15 +7,15 @@ type VerboseConfiguration = { dismissMocked?: boolean; dismissNotMocked?: boolean; }; -type Verbose = VerboseConfiguration; +export type VerboseArgs = boolean | VerboseConfiguration; type ProviderConstructorArgs = { - verbose?: boolean | Verbose; + verbose?: VerboseArgs; }; export class Provider extends EventEmitter { public requestMocks: Record = {}; - public verbose: Verbose; + public verbose: VerboseConfiguration; constructor({ verbose }: ProviderConstructorArgs) { super(); diff --git a/src/setup.ts b/src/setup.ts index 99253bd..31ae993 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -1,9 +1,15 @@ -import { MetaMaskProvider, WalletConnectProvider, Provider } from "./providers"; +import { + MetaMaskProvider, + WalletConnectProvider, + Provider, + CoinbaseProvider, + VerboseArgs, +} from "./providers"; import { TestingUtils } from "./testing-utils"; type GenerateOptions = { - providerType?: "MetaMask" | "WalletConnect" | "default"; - verbose?: boolean; + providerType?: "MetaMask" | "WalletConnect" | "Coinbase" | "default"; + verbose?: VerboseArgs; }; const defaultGenerationOptions: GenerateOptions = { @@ -14,7 +20,7 @@ const defaultGenerationOptions: GenerateOptions = { /** * Generate the testing utils associated with a mock provider * @param options.providerType Type of the provider to mock, default to `default` - * @param options.verbose If true, the JSON-RPC request will be logged + * @param options.verbose Verbose configuration * @returns The testing utils for one provider */ export function generateTestingUtils({ @@ -24,6 +30,8 @@ export function generateTestingUtils({ const provider = providerType === "MetaMask" ? new MetaMaskProvider({ verbose }) + : providerType === "Coinbase" + ? new CoinbaseProvider({ verbose }) : providerType === "WalletConnect" ? new WalletConnectProvider({ verbose }) : new Provider({ verbose });