feat(onboarding): remove mnemonic as early as possible

Closes: #13260
This commit is contained in:
Sale Djenic 2024-01-22 15:53:07 +01:00 committed by saledjenic
parent e51667911d
commit daecb836ac
3 changed files with 11 additions and 19 deletions

View File

@ -485,12 +485,6 @@ proc appReady*(self: AppController) =
proc finishAppLoading*(self: AppController) =
self.load()
# Once user is logged in and main module is loaded we need to check if it gets here importing mnemonic or not
# and delete mnemonic in the first case.
let importedAccount = self.accountsService.getImportedAccount()
if(importedAccount.isValid()):
self.privacyService.removeMnemonic()
if not self.startupModule.isNil:
self.startupModule.onAppLoaded()
self.startupModule = nil

View File

@ -380,9 +380,9 @@ proc setupKeychain(self: Controller, store: bool) =
else:
singletonInstance.localAccountSettings.setStoreToKeychainValue(LS_VALUE_NEVER)
proc setupAccount(self: Controller, accountId: string, storeToKeychain: bool, recoverAccount: bool = false) =
proc setupAccount(self: Controller, accountId: string, removeMnemonic: bool, storeToKeychain: bool, recoverAccount: bool = false) =
self.delegate.moveToLoadingAppState()
let error = self.accountsService.setupAccount(accountId, self.tmpPassword, self.tmpDisplayName, recoverAccount)
let error = self.accountsService.setupAccount(accountId, self.tmpPassword, self.tmpDisplayName, removeMnemonic, recoverAccount)
if error != "":
self.delegate.emitStartupError(error, StartupErrorType.SetupAccError)
else:
@ -394,11 +394,11 @@ proc storeGeneratedAccountAndLogin*(self: Controller, storeToKeychain: bool) =
error "list of generated accounts is empty"
return
let accountId = accounts[0].id
self.setupAccount(accountId, storeToKeychain)
self.setupAccount(accountId, removeMnemonic=false, storeToKeychain)
proc storeImportedAccountAndLogin*(self: Controller, storeToKeychain: bool, recoverAccount: bool = false) =
let accountId = self.getImportedAccount().id
self.setupAccount(accountId, storeToKeychain, recoverAccount)
self.setupAccount(accountId, removeMnemonic=true, storeToKeychain, recoverAccount)
proc storeKeycardAccountAndLogin*(self: Controller, storeToKeychain: bool, newKeycard: bool) =
if self.importMnemonic():

View File

@ -269,10 +269,10 @@ QtObject:
return logLevel
proc prepareAccountSettingsJsonObject(self: Service, account: GeneratedAccountDto,
installationId: string, displayName: string): JsonNode =
installationId: string, displayName: string, withoutMnemonic: bool): JsonNode =
result = %* {
"key-uid": account.keyUid,
"mnemonic": account.mnemonic,
"mnemonic": if withoutMnemonic: "" else: account.mnemonic,
"public-key": account.derivedAccounts.whisper.publicKey,
"name": account.alias,
"display-name": displayName,
@ -302,16 +302,14 @@ QtObject:
"url-unfurling-mode": int(settings.UrlUnfurlingMode.AlwaysAsk),
}
proc getAccountSettings(self: Service, accountId: string,
installationId: string,
displayName: string): JsonNode =
proc getAccountSettings(self: Service, accountId: string, installationId: string, displayName: string, withoutMnemonic: bool): JsonNode =
for acc in self.generatedAccounts:
if(acc.id == accountId):
return self.prepareAccountSettingsJsonObject(acc, installationId, displayName)
return self.prepareAccountSettingsJsonObject(acc, installationId, displayName, withoutMnemonic)
if(self.importedAccount.isValid()):
if(self.importedAccount.id == accountId):
return self.prepareAccountSettingsJsonObject(self.importedAccount, installationId, displayName)
return self.prepareAccountSettingsJsonObject(self.importedAccount, installationId, displayName, withoutMnemonic)
proc getDefaultNodeConfig*(self: Service, installationId: string, recoverAccount: bool): JsonNode =
let fleet = Fleet.ShardsTest
@ -430,13 +428,13 @@ QtObject:
if not accountData.isNil:
accountData["keycard-pairing"] = kcDataObj{"key"}
proc setupAccount*(self: Service, accountId, password, displayName: string, recoverAccount: bool = false): string =
proc setupAccount*(self: Service, accountId, password, displayName: string, removeMnemonic: bool, recoverAccount: bool = false): string =
try:
let installationId = $genUUID()
var accountDataJson = self.getAccountDataForAccountId(accountId, displayName)
self.setKeyStoreDir(accountDataJson{"key-uid"}.getStr) # must be called before `getDefaultNodeConfig`
let subaccountDataJson = self.getSubaccountDataForAccountId(accountId, displayName)
var settingsJson = self.getAccountSettings(accountId, installationId, displayName)
var settingsJson = self.getAccountSettings(accountId, installationId, displayName, removeMnemonic)
let nodeConfigJson = self.getDefaultNodeConfig(installationId, recoverAccount)
if(accountDataJson.isNil or subaccountDataJson.isNil or settingsJson.isNil or