@@ -109,7 +109,7 @@ try {
109
109
contextBridge . exposeInMainWorld ( '__WALLET__API__' , {
110
110
...methods ,
111
111
async createSecretManager ( options ) {
112
- const manager = await IotaSdk . SecretManager . create ( options )
112
+ const manager = IotaSdk . SecretManager . create ( options )
113
113
bindMethodsAcrossContextBridge ( IotaSdk . SecretManager . prototype , manager )
114
114
return manager
115
115
} ,
@@ -122,19 +122,23 @@ try {
122
122
bindMethodsAcrossContextBridge ( IotaSdk . Client . prototype , client )
123
123
return client
124
124
} ,
125
- // TODO(2.0): rename to createWallet
126
- async createWallet ( id , options ) {
127
- const wallet = await IotaSdk . Wallet . create ( options )
128
- wallet . id = id
129
- wallets [ id ] = wallet
130
- bindMethodsAcrossContextBridge ( IotaSdk . Wallet . prototype , wallet )
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
+ }
131
134
return wallet
132
135
} ,
133
136
// TODO(2.0): also remove from file system? Does it make sense? file system != memoery
134
- deleteWallet ( id ) {
137
+ async deleteWallet ( id ) {
135
138
if ( id && id in wallets ) {
136
139
const wallet = wallets [ id ]
137
- wallet . destroy ( )
140
+ await wallet . stopBackgroundSync ( )
141
+ await wallet . destroy ( )
138
142
delete wallets [ id ]
139
143
}
140
144
} ,
@@ -143,6 +147,7 @@ try {
143
147
let wallet = wallets [ id ]
144
148
if ( ! wallet ) {
145
149
wallet = await IotaSdk . Wallet . create ( walletOptions )
150
+ wallet . id = id
146
151
wallets [ id ] = wallet
147
152
bindMethodsAcrossContextBridge ( IotaSdk . Wallet . prototype , wallet )
148
153
}
@@ -155,12 +160,12 @@ try {
155
160
accounts . forEach ( ( account ) => bindMethodsAcrossContextBridge ( IotaSdk . Wallet . prototype , account ) )
156
161
return accounts
157
162
} ,
158
- clearWalletsFromMemory ( ) {
159
- Object . keys ( wallets ) . forEach ( ( id ) => {
160
- const wallet = wallets [ id ]
161
- wallet . destroy ( )
163
+ async clearWalletsFromMemory ( ) {
164
+ for ( const [ id , wallet ] of Object . entries ( wallets ) ) {
165
+ await wallet . stopBackgroundSync ( )
166
+ await wallet . destroy ( )
162
167
delete wallets [ id ]
163
- } )
168
+ }
164
169
} ,
165
170
async migrateStrongholdSnapshotV2ToV3 ( currentPath , newPath , currentPassword , newPassword ) {
166
171
const snapshotSaltV2 = 'wallet.rs'
0 commit comments