From 3d163cfa337ad112a9adcb534498d76869a286cd Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Tue, 8 Nov 2022 14:37:52 +0100 Subject: [PATCH] fix(@desktop/keycard): keystore file for a keypair is not removed once that keypair is migrated to a Keycard When we're migrating profile or any other keypair to a Keycard corresponding locally stored keystore files are removed. Fixes: #8067 --- src/app/boot/app_controller.nim | 3 ++- src/app/modules/shared_modules/keycard_popup/controller.nim | 5 ++++- .../internal/seed_phrase_enter_words_state.nim | 1 + src/app_service/service/accounts/service.nim | 3 +++ src/app_service/service/wallet_account/service.nim | 6 ++++-- src/backend/backend.nim | 1 + vendor/status-go | 2 +- 7 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/app/boot/app_controller.nim b/src/app/boot/app_controller.nim index b64f652179..56e6d5ebd4 100644 --- a/src/app/boot/app_controller.nim +++ b/src/app/boot/app_controller.nim @@ -423,7 +423,8 @@ proc buildAndRegisterUserProfile(self: AppController) = keycardLocked: false, accountsAddresses: @[defaultWalletAddress], keyUid: loggedInAccount.keyUid) - discard self.walletAccountService.addMigratedKeyPair(keyPair) + let keystoreDir = self.accountsService.getKeyStoreDir() + discard self.walletAccountService.addMigratedKeyPair(keyPair, keystoreDir) proc storeKeyPairForNewKeycardUser*(self: AppController) = self.storeKeyPair = true \ No newline at end of file diff --git a/src/app/modules/shared_modules/keycard_popup/controller.nim b/src/app/modules/shared_modules/keycard_popup/controller.nim index f0b02c9093..1e34c9bd81 100644 --- a/src/app/modules/shared_modules/keycard_popup/controller.nim +++ b/src/app/modules/shared_modules/keycard_popup/controller.nim @@ -445,7 +445,10 @@ proc getBalanceForAddress*(self: Controller, address: string): float64 = proc addMigratedKeyPair*(self: Controller, keyPair: KeyPairDto): bool = if not serviceApplicable(self.walletAccountService): return - return self.walletAccountService.addMigratedKeyPair(keyPair) + if not serviceApplicable(self.accountsService): + return + let keystoreDir = self.accountsService.getKeyStoreDir() + return self.walletAccountService.addMigratedKeyPair(keyPair, keystoreDir) proc getAllMigratedKeyPairs*(self: Controller): seq[KeyPairDto] = if not serviceApplicable(self.walletAccountService): diff --git a/src/app/modules/shared_modules/keycard_popup/internal/seed_phrase_enter_words_state.nim b/src/app/modules/shared_modules/keycard_popup/internal/seed_phrase_enter_words_state.nim index eea33cb3cf..c18968e9e8 100644 --- a/src/app/modules/shared_modules/keycard_popup/internal/seed_phrase_enter_words_state.nim +++ b/src/app/modules/shared_modules/keycard_popup/internal/seed_phrase_enter_words_state.nim @@ -12,6 +12,7 @@ proc delete*(self: SeedPhraseEnterWordsState) = method executePrimaryCommand*(self: SeedPhraseEnterWordsState, controller: Controller) = let mnemonic = controller.getMnemonic() + controller.setSeedPhrase(mnemonic) controller.storeSeedPhraseToKeycard(mnemonic.split(" ").len, mnemonic) method executeTertiaryCommand*(self: SeedPhraseEnterWordsState, controller: Controller) = diff --git a/src/app_service/service/accounts/service.nim b/src/app_service/service/accounts/service.nim index 6efd9be632..f3c4814401 100644 --- a/src/app_service/service/accounts/service.nim +++ b/src/app_service/service/accounts/service.nim @@ -67,6 +67,9 @@ proc setKeyStoreDir(self: Service, key: string) = self.keyStoreDir = joinPath(main_constants.ROOTKEYSTOREDIR, key) & main_constants.sep discard status_general.initKeystore(self.keyStoreDir) +proc getKeyStoreDir*(self: Service): string = + return self.keyStoreDir + proc setDefaultWalletEmoji*(self: Service, emoji: string) = self.defaultWalletEmoji = emoji diff --git a/src/app_service/service/wallet_account/service.nim b/src/app_service/service/wallet_account/service.nim index 54ea852ec5..14bc7662c4 100644 --- a/src/app_service/service/wallet_account/service.nim +++ b/src/app_service/service/wallet_account/service.nim @@ -547,13 +547,15 @@ QtObject: error "error: ", procName=procName, errDesription = errMsg return false - proc addMigratedKeyPair*(self: Service, keyPair: KeyPairDto): bool = + proc addMigratedKeyPair*(self: Service, keyPair: KeyPairDto, keyStoreDir: string): bool = try: let response = backend.addMigratedKeyPair( keyPair.keycardUid, keyPair.keycardName, keyPair.keyUid, - keyPair.accountsAddresses) + keyPair.accountsAddresses, + keyStoreDir + ) result = self.responseHasNoErrors("addMigratedKeyPair", response) if result: self.events.emit(SIGNAL_NEW_KEYCARD_SET, KeycardActivityArgs(keyPair: keyPair)) diff --git a/src/backend/backend.nim b/src/backend/backend.nim index 3c211c17c5..7cd169fbc4 100644 --- a/src/backend/backend.nim +++ b/src/backend/backend.nim @@ -241,6 +241,7 @@ rpc(addMigratedKeyPair, "accounts"): keyPairName: string keyUid: string accountAddresses: seq[string] + keyStoreDir: string rpc(getAllMigratedKeyPairs, "accounts"): discard diff --git a/vendor/status-go b/vendor/status-go index f33c1cec38..77b7ce5a09 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit f33c1cec383d8cd7e14af2832b8017d1e204d9cf +Subproject commit 77b7ce5a09502d9f3f8fa9789ce4cf62efa0e96c