@@ -403,7 +403,7 @@ final class EthWalletService: WalletCoreProtocol, WalletStaticCoreProtocol, Smar
403403
404404// MARK: - WalletInitiatedWithPassphrase
405405extension EthWalletService {
406- func initWallet( withPassphrase passphrase: String , withPassword password: String ) async throws -> WalletAccount {
406+ func initWallet( withPassphrase passphrase: String , withPassword password: String , storeInKVC : Bool ) async throws -> WalletAccount {
407407 guard let adamant = accountService? . account else {
408408 throw WalletServiceError . notLogged
409409 }
@@ -429,7 +429,6 @@ extension EthWalletService {
429429
430430 // MARK: 3. Update
431431 ethWallet = eWallet
432- let kvsAddressModel = makeKVSAddressModel ( wallet: eWallet)
433432
434433 NotificationCenter . default. post (
435434 name: walletUpdatedNotification,
@@ -444,7 +443,16 @@ extension EthWalletService {
444443 NotificationCenter . default. post ( name: serviceEnabledChanged, object: self )
445444 }
446445
446+ self . setState ( . upToDate)
447+
448+ Task {
449+ await self . update ( )
450+ }
451+
452+ guard storeInKVC else { return eWallet }
453+
447454 // MARK: 4. Save into KVS
455+ let kvsAddressModel = makeKVSAddressModel ( wallet: eWallet)
448456 let service = self
449457 do {
450458 let address = try await getWalletAddress ( byAdamantAddress: adamant. address)
@@ -454,24 +462,13 @@ extension EthWalletService {
454462 }
455463 }
456464
457- service. setState ( . upToDate)
458-
459- Task {
460- await service. update ( )
461- }
462-
463465 return eWallet
464466 } catch let error as WalletServiceError {
465467 switch error {
466468 case . walletNotInitiated:
467469 /// The ADM Wallet is not initialized. Check the balance of the current wallet
468470 /// and save the wallet address to kvs when dropshipping ADM
469- service. setState ( . upToDate)
470-
471- Task {
472- await service. update ( )
473- }
474-
471+
475472 if let kvsAddressModel {
476473 service. save ( kvsAddressModel) { result in
477474 service. kvsSaveCompletionRecursion ( kvsAddressModel, result: result)
@@ -481,7 +478,6 @@ extension EthWalletService {
481478 return eWallet
482479
483480 default :
484- service. setState ( . upToDate)
485481 throw error
486482 }
487483 }
0 commit comments