Skip to content

Commit

Permalink
feat: add coinbase provider, update verbose type (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
VGLoic authored Dec 16, 2022
1 parent 15e4d39 commit c3c0eb0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
19 changes: 19 additions & 0 deletions src/providers/coinbase.ts
Original file line number Diff line number Diff line change
@@ -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,
});
}
}
}
1 change: 1 addition & 0 deletions src/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./metamask";
export * from "./provider";
export * from "./wallet-connect";
export * from "./coinbase";
6 changes: 3 additions & 3 deletions src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, MockRequest[]> = {};

public verbose: Verbose;
public verbose: VerboseConfiguration;

constructor({ verbose }: ProviderConstructorArgs) {
super();
Expand Down
16 changes: 12 additions & 4 deletions src/setup.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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({
Expand All @@ -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 });
Expand Down

0 comments on commit c3c0eb0

Please sign in to comment.