From 2fae4cdaf1d7a38b21440f5e36e3dab10e5fb1c6 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Thu, 13 Apr 2023 12:25:54 +0200 Subject: [PATCH] fix(@desktop/wallet): a few wallet account related issues fixed - index was not returned properly because of case sensitive address comparison - delete account was not done properly for keycard accounts - after login the app was asking for store to keychain even it was a test environment --- src/app/boot/app_controller.nim | 2 ++ .../wallet_section/accounts/controller.nim | 4 ++-- .../main/wallet_section/accounts/module.nim | 20 ++++++------------- .../main/wallet_section/assets/controller.nim | 3 +++ .../service/wallet_account/service.nim | 12 +++++------ 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/app/boot/app_controller.nim b/src/app/boot/app_controller.nim index a94b6962c5..0780e7f296 100644 --- a/src/app/boot/app_controller.nim +++ b/src/app/boot/app_controller.nim @@ -349,6 +349,8 @@ proc connectKeychain(self: AppController) = self.keychainConnectionIds.add(handlerId) proc checkForStoringPasswordToKeychain(self: AppController) = + if singletonInstance.localAppSettings.getTestEnvironment(): + return ## This proc is used to store pass/pin depends on user's selection during onboarding flow. let account = self.accountsService.getLoggedInAccount() let value = singletonInstance.localAccountSettings.getStoreToKeychainValue() diff --git a/src/app/modules/main/wallet_section/accounts/controller.nim b/src/app/modules/main/wallet_section/accounts/controller.nim index 55eb8a1d53..0765906b12 100644 --- a/src/app/modules/main/wallet_section/accounts/controller.nim +++ b/src/app/modules/main/wallet_section/accounts/controller.nim @@ -47,8 +47,8 @@ proc init*(self: Controller) = proc getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAccountDto] = return self.walletAccountService.getWalletAccounts() -proc deleteAccount*(self: Controller, address: string, password = "") = - self.walletAccountService.deleteAccount(address, password) +proc deleteAccount*(self: Controller, address: string, password = "", doPasswordHashing = false) = + self.walletAccountService.deleteAccount(address, password, doPasswordHashing) proc authenticateKeyPair*(self: Controller, keyUid = "") = let data = SharedKeycarModuleAuthenticationArgs(uniqueIdentifier: UNIQUE_WALLET_SECTION_ACCOUNTS_MODULE_AUTH_IDENTIFIER, diff --git a/src/app/modules/main/wallet_section/accounts/module.nim b/src/app/modules/main/wallet_section/accounts/module.nim index 4635707b46..ec106d1a8d 100644 --- a/src/app/modules/main/wallet_section/accounts/module.nim +++ b/src/app/modules/main/wallet_section/accounts/module.nim @@ -149,13 +149,8 @@ proc authenticateActivityForKeyUid(self: Module, keyUid: string, reason: Authent if keyPairMigratedToKeycard: self.controller.authenticateKeyPair(keyUid) else: - if singletonInstance.userProfile.getIsKeycardUser(): - ## We're here in case the keypair we're conducting an action for is not migrated to a keycard, but - ## profile keypair is migrated, then we're authenticating profile keypair (logged in user). - self.processingWalletAccount.keyUid = singletonInstance.userProfile.getKeyUid() - self.controller.authenticateKeyPair(singletonInstance.userProfile.getKeyUid()) - else: - self.controller.authenticateKeyPair() + self.processingWalletAccount.keyUid = singletonInstance.userProfile.getKeyUid() + self.controller.authenticateKeyPair() method deleteAccount*(self: Module, keyUid: string, address: string) = let accountDto = self.controller.getWalletAccount(address) @@ -170,10 +165,7 @@ method onUserAuthenticated*(self: Module, pin: string, password: string, keyUid: if self.processingWalletAccount.keyUid != keyUid: error "cannot resolve key uid of an account being deleted", keyUid=keyUid return - if pin.len == PINLengthForStatusApp: - # keycard keypair authentication - self.controller.deleteAccount(self.processingWalletAccount.address) - self.tryKeycardSync(keyUid, pin) - elif password.len > 0: - # regular keypair authentication - self.controller.deleteAccount(self.processingWalletAccount.address, password) \ No newline at end of file + if password.len == 0: + return + let doPasswordHashing = pin.len != PINLengthForStatusApp + self.controller.deleteAccount(self.processingWalletAccount.address, password, doPasswordHashing) \ No newline at end of file diff --git a/src/app/modules/main/wallet_section/assets/controller.nim b/src/app/modules/main/wallet_section/assets/controller.nim index 1af8218c2a..cf5037b8d2 100644 --- a/src/app/modules/main/wallet_section/assets/controller.nim +++ b/src/app/modules/main/wallet_section/assets/controller.nim @@ -37,6 +37,9 @@ proc delete*(self: Controller) = proc init*(self: Controller) = discard +proc getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAccountDto] = + return self.walletAccountService.getWalletAccounts() + proc getWalletAccount*(self: Controller, accountIndex: int): wallet_account_service.WalletAccountDto = return self.walletAccountService.getWalletAccount(accountIndex) diff --git a/src/app_service/service/wallet_account/service.nim b/src/app_service/service/wallet_account/service.nim index d5208ea349..43b57139c3 100644 --- a/src/app_service/service/wallet_account/service.nim +++ b/src/app_service/service/wallet_account/service.nim @@ -308,7 +308,7 @@ QtObject: proc getIndex*(self: Service, address: string): int = let accounts = self.getWalletAccounts() for i in 0 ..< accounts.len: - if(accounts[i].address == address): + if cmpIgnoreCase(accounts[i].address, address) == 0: return i proc startWallet(self: Service) = @@ -423,12 +423,12 @@ QtObject: error "error: ", procName="getRandomMnemonic", errName=e.name, errDesription=e.msg return "" - proc deleteAccount*(self: Service, address: string, password = "") = + proc deleteAccount*(self: Service, address: string, password: string, doPasswordHashing: bool) = try: - var hashedPassword = "" - if password.len > 0: - hashedPassword = utils.hashPassword(password) - discard status_go_accounts.deleteAccount(address, hashedPassword) + var finalPassword = password + if doPasswordHashing: + finalPassword = utils.hashPassword(password) + discard status_go_accounts.deleteAccount(address, finalPassword) let accountDeleted = self.removeAccount(address) self.events.emit(SIGNAL_WALLET_ACCOUNT_DELETED, AccountDeleted(account: accountDeleted)) except Exception as e: