Skip to content

Commit

Permalink
feat(wallet): add generic type to IWallet interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsdls committed Jan 18, 2024
1 parent f914454 commit 400ba8a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions packages/thirdweb/src/wallets/interfaces/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import type {
TypedDataDefinition,
} from "viem";

export interface IWallet {
export interface IWallet<connectOpts> {
address: Address | null;
connect: (_opts: any) => Promise<IWallet>;
connect:
| ((opts: connectOpts) => Promise<IWallet<connectOpts>>)
| ((opts?: connectOpts) => Promise<IWallet<connectOpts>>);
disconnect: () => Promise<void>;
//
signMessage?: (_message: SignableMessage) => Promise<Hex>;
Expand Down
6 changes: 3 additions & 3 deletions packages/thirdweb/src/wallets/metamask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type MetamaskWalletConnectOptions = {
chainId?: number;
};

class MetamaskWallet implements IWallet {
class MetamaskWallet implements IWallet<MetamaskWalletConnectOptions> {
private provider?: Ethereum;
private connectedChainId?: number;
private connectdAddress?: Address | null;
Expand Down Expand Up @@ -94,7 +94,7 @@ class MetamaskWallet implements IWallet {
// this.client = client;
}

public async connect(options: MetamaskWalletConnectOptions) {
public async connect(options?: MetamaskWalletConnectOptions) {
if (hasInjectedProvider(globalThis.window)) {
this.provider = globalThis.window.ethereum;
} else {
Expand All @@ -116,7 +116,7 @@ class MetamaskWallet implements IWallet {
this.connectedChainId = chainId;

// if chainId is provided, switch to that chain
if (options.chainId && this.connectedChainId !== options.chainId) {
if (options?.chainId && this.connectedChainId !== options.chainId) {
await this.switchChain(options.chainId);
this.connectedChainId = options.chainId;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/thirdweb/src/wallets/private-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type PrivateKeyWalletConnectOptions = {
pkey: string;
};

class PrivateKeyWallet implements IWallet {
class PrivateKeyWallet implements IWallet<PrivateKeyWalletConnectOptions> {
private account: PrivateKeyAccount | null = null;

get address() {
Expand Down

0 comments on commit 400ba8a

Please sign in to comment.