@@ -109,49 +109,63 @@ try {
109
109
contextBridge . exposeInMainWorld ( '__WALLET__API__' , {
110
110
...methods ,
111
111
async createSecretManager ( options ) {
112
- const manager = new IotaSdk . SecretManager ( options )
112
+ const manager = IotaSdk . SecretManager . create ( options )
113
113
bindMethodsAcrossContextBridge ( IotaSdk . SecretManager . prototype , manager )
114
114
return manager
115
115
} ,
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
+ }
122
134
return wallet
123
135
} ,
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 ) {
126
138
if ( id && id in wallets ) {
127
139
const wallet = wallets [ id ]
128
- wallet . destroy ( )
140
+ await wallet . stopBackgroundSync ( )
141
+ await wallet . destroy ( )
129
142
delete wallets [ id ]
130
143
}
131
144
} ,
132
145
// TODO(2.0): Rename this to getWallet and fix all usages
133
146
async getWallet ( id , walletOptions ) {
134
147
let wallet = wallets [ id ]
135
148
if ( ! wallet ) {
136
- wallet = new IotaSdk . Wallet ( walletOptions )
149
+ wallet = await IotaSdk . Wallet . create ( walletOptions )
150
+ wallet . id = id
137
151
wallets [ id ] = wallet
138
- bindMethodsAcrossContextBridge ( IotaSdk . Account . prototype , wallet )
152
+ bindMethodsAcrossContextBridge ( IotaSdk . Wallet . prototype , wallet )
139
153
}
140
154
return wallet
141
155
} ,
142
156
// TODO(2.0): remove this method from here and move to new profile
143
157
async recoverAccounts ( managerId , payload ) {
144
158
const manager = wallets [ managerId ]
145
159
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 ) )
147
161
return accounts
148
162
} ,
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 ( )
153
167
delete wallets [ id ]
154
- } )
168
+ }
155
169
} ,
156
170
async migrateStrongholdSnapshotV2ToV3 ( currentPath , newPath , currentPassword , newPassword ) {
157
171
const snapshotSaltV2 = 'wallet.rs'
0 commit comments