@@ -109,49 +109,63 @@ try {
109109 contextBridge . exposeInMainWorld ( '__WALLET__API__' , {
110110 ...methods ,
111111 async createSecretManager ( options ) {
112- const manager = new IotaSdk . SecretManager ( options )
112+ const manager = IotaSdk . SecretManager . create ( options )
113113 bindMethodsAcrossContextBridge ( IotaSdk . SecretManager . prototype , manager )
114114 return manager
115115 } ,
116- // TODO(2.0): rename to createWallet
117- async createWallet ( id , options ) {
118- const wallet = new IotaSdk . Wallet ( options )
119- wallet . id = id
120- wallets [ id ] = wallet
121- bindMethodsAcrossContextBridge ( IotaSdk . Wallet . prototype , wallet )
116+ async getClientFromWallet ( id ) {
117+ const wallet = wallets [ id ] ;
118+ // Why is this here?:
119+ // We cannot create classes from exposed functions
120+ // https://www.electronjs.org/docs/latest/api/context-bridge
121+ const client = await wallet . getClient ( ) ;
122+ bindMethodsAcrossContextBridge ( IotaSdk . Client . prototype , client )
123+ return client
124+ } ,
125+ // TODO(2.0): Is there a difference between this and getWallet? They both really make the same thing
126+ async createWallet ( id , walletOptions ) {
127+ let wallet = wallets [ id ]
128+ if ( ! wallet ) {
129+ wallet = await IotaSdk . Wallet . create ( walletOptions )
130+ wallet . id = id
131+ wallets [ id ] = wallet
132+ bindMethodsAcrossContextBridge ( IotaSdk . Wallet . prototype , wallet )
133+ }
122134 return wallet
123135 } ,
124- // TODO(2.0): also remove from file system
125- deleteWallet ( id ) {
136+ // TODO(2.0): also remove from file system? Does it make sense? file system != memoery
137+ async deleteWallet ( id ) {
126138 if ( id && id in wallets ) {
127139 const wallet = wallets [ id ]
128- wallet . destroy ( )
140+ await wallet . stopBackgroundSync ( )
141+ await wallet . destroy ( )
129142 delete wallets [ id ]
130143 }
131144 } ,
132145 // TODO(2.0): Rename this to getWallet and fix all usages
133146 async getWallet ( id , walletOptions ) {
134147 let wallet = wallets [ id ]
135148 if ( ! wallet ) {
136- wallet = new IotaSdk . Wallet ( walletOptions )
149+ wallet = await IotaSdk . Wallet . create ( walletOptions )
150+ wallet . id = id
137151 wallets [ id ] = wallet
138- bindMethodsAcrossContextBridge ( IotaSdk . Account . prototype , wallet )
152+ bindMethodsAcrossContextBridge ( IotaSdk . Wallet . prototype , wallet )
139153 }
140154 return wallet
141155 } ,
142156 // TODO(2.0): remove this method from here and move to new profile
143157 async recoverAccounts ( managerId , payload ) {
144158 const manager = wallets [ managerId ]
145159 const accounts = await manager . recoverAccounts ( ...Object . values ( payload ) )
146- accounts . forEach ( ( account ) => bindMethodsAcrossContextBridge ( IotaSdk . Account . prototype , account ) )
160+ accounts . forEach ( ( account ) => bindMethodsAcrossContextBridge ( IotaSdk . Wallet . prototype , account ) )
147161 return accounts
148162 } ,
149- clearWalletsFromMemory ( ) {
150- Object . keys ( wallets ) . forEach ( ( id ) => {
151- const wallet = wallets [ id ]
152- wallet . destroy ( )
163+ async clearWalletsFromMemory ( ) {
164+ for ( const [ id , wallet ] of Object . entries ( wallets ) ) {
165+ await wallet . stopBackgroundSync ( )
166+ await wallet . destroy ( )
153167 delete wallets [ id ]
154- } )
168+ }
155169 } ,
156170 async migrateStrongholdSnapshotV2ToV3 ( currentPath , newPath , currentPassword , newPassword ) {
157171 const snapshotSaltV2 = 'wallet.rs'
0 commit comments