11import { MetaMaskSDK } from "@metamask/sdk" ;
2+ import { getAddress } from "ethers/address" ;
23import { createStore } from "mipd" ;
34import {
45 ExternalPlatform ,
@@ -31,14 +32,20 @@ export class MetaMaskWallet implements WalletAdapter {
3132 } )
3233 . then ( ( accounts : any ) => {
3334 if ( accounts && accounts . length > 0 ) {
34- this . account = accounts [ 0 ] ;
35- this . connectedAccounts = accounts ;
35+ this . account = getAddress ( accounts [ 0 ] ) ;
36+ this . connectedAccounts = accounts . map ( ( account : string ) =>
37+ getAddress ( account ) ,
38+ ) ;
3639 }
3740 } ) ;
3841 this . MMSDK . getProvider ( ) ?. on ( "accountsChanged" , ( accounts : any ) => {
3942 if ( Array . isArray ( accounts ) ) {
40- this . account = accounts ?. [ 0 ] ;
41- this . connectedAccounts = accounts ;
43+ if ( accounts . length > 0 ) {
44+ this . account = getAddress ( accounts ?. [ 0 ] ) ;
45+ }
46+ this . connectedAccounts = accounts . map ( ( account : string ) =>
47+ getAddress ( account ) ,
48+ ) ;
4249 }
4350 } ) ;
4451 } ) ;
@@ -69,8 +76,8 @@ export class MetaMaskWallet implements WalletAdapter {
6976 }
7077
7178 async connect ( address ?: string ) : Promise < ExternalWalletResponse < any > > {
72- if ( address && this . connectedAccounts . includes ( address ) ) {
73- this . account = address ;
79+ if ( address && this . connectedAccounts . includes ( getAddress ( address ) ) ) {
80+ this . account = getAddress ( address ) ;
7481 }
7582
7683 if ( this . account ) {
@@ -84,8 +91,10 @@ export class MetaMaskWallet implements WalletAdapter {
8491
8592 const accounts = await this . MMSDK . connect ( ) ;
8693 if ( accounts && accounts . length > 0 ) {
87- this . account = accounts [ 0 ] ;
88- this . connectedAccounts = accounts ;
94+ this . account = getAddress ( accounts [ 0 ] ) ;
95+ this . connectedAccounts = accounts . map ( ( account : string ) =>
96+ getAddress ( account ) ,
97+ ) ;
8998 return { success : true , wallet : this . type , account : this . account } ;
9099 }
91100
@@ -141,7 +150,7 @@ export class MetaMaskWallet implements WalletAdapter {
141150
142151 const result = await this . MMSDK . getProvider ( ) ?. request ( {
143152 method : "personal_sign" ,
144- params : [ this . account ! , message ] ,
153+ params : [ this . account , message ] ,
145154 } ) ;
146155
147156 return { success : true , wallet : this . type , result } ;
0 commit comments