Skip to content

Commit

Permalink
chore: update Evm base class
Browse files Browse the repository at this point in the history
  • Loading branch information
wainola committed Oct 4, 2023
1 parent 08e7d70 commit 5149995
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/wallet-manager/src/WalletManagerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class WalletManagerController implements IWalletManagerController {
*/
public async connectEvmWallet(): Promise<void> {
await this.evmWallet?.connect();
this.account = this.evmWallet?.account;
this.account = this.evmWallet?.address;
this.host.requestUpdate();
}

Expand Down
17 changes: 10 additions & 7 deletions packages/wallet-manager/src/wallets/Evm/Evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { IEvmWallet } from '../interfaces';
import { AddChain } from '../../types';

class EvmWallet extends events.EventEmitter implements IEvmWallet {
public account: string | undefined;
public web3Provider!: Web3Provider;
public windowConnector: ExternalProvider;
address?: string;
signer?: ethers.Signer;
web3Provider!: Web3Provider;
windowConnector: ExternalProvider;

constructor(provider?: Web3Provider) {
super();
Expand Down Expand Up @@ -57,7 +58,7 @@ class EvmWallet extends events.EventEmitter implements IEvmWallet {
*/
private async calculateAccountData(accounts?: string[]): Promise<void> {
if (accounts?.length) {
this.account = accounts[0];
this.address = accounts[0];
}

const _accounts = await this.web3Provider.listAccounts();
Expand All @@ -66,7 +67,8 @@ class EvmWallet extends events.EventEmitter implements IEvmWallet {
return;
}

this.account = _accounts![0];
this.address = _accounts![0];
this.signer = this.web3Provider.getSigner();
}

/**
Expand Down Expand Up @@ -117,7 +119,7 @@ class EvmWallet extends events.EventEmitter implements IEvmWallet {
this.reConnectToProvider();
await this.calculateAccountData(accounts);

this.emit('walletAccountChanged', this.account);
this.emit('walletAccountChanged', this.address);
}
);
}
Expand All @@ -141,7 +143,8 @@ class EvmWallet extends events.EventEmitter implements IEvmWallet {
.request!({
method: 'eth_requestAccounts'
});
this.account = accounts[0];
this.address = accounts[0];
this.signer = this.web3Provider.getSigner();
} catch (e) {
throw e;
}
Expand Down
6 changes: 4 additions & 2 deletions packages/wallet-manager/src/wallets/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Web3Provider, ExternalProvider } from '@ethersproject/providers';
import { ApiPromise, WsProvider } from '@polkadot/api';
import { ReactiveController } from 'lit';
import { AddChain } from '../../types';
import { Signer } from '@ethersproject/abstract-signer';

export interface SupportedWallet {
id: string;
Expand All @@ -13,7 +14,8 @@ export interface SupportedWallet {
export interface IEvmWallet {
web3Provider: Web3Provider;
windowConnector: ExternalProvider;
account?: string;
address?: string;
signer?: Signer;
connect(): Promise<void>;
addChain({
chainId,
Expand Down Expand Up @@ -53,4 +55,4 @@ export interface IWalletManagerController extends ReactiveController {
addChain(addChainParameters: AddChain): Promise<void>;
connectoToSubstrate(): Promise<void>;
connectEvmWallet(): Promise<void>;
}
}

0 comments on commit 5149995

Please sign in to comment.