fix: set display name in accountsDB

This commit is contained in:
Richard Ramos 2022-03-16 15:28:02 -04:00 committed by Iuri Matias
parent 3d6b7aba80
commit 45deb4072e
1 changed files with 12 additions and 12 deletions

View File

@ -133,25 +133,25 @@ proc saveAccountAndLogin(self: Service, hashedPassword: string, account,
except Exception as e: except Exception as e:
error "error: ", methodName="saveAccountAndLogin", errName = e.name, errDesription = e.msg error "error: ", methodName="saveAccountAndLogin", errName = e.name, errDesription = e.msg
proc prepareAccountJsonObject(self: Service, account: GeneratedAccountDto): JsonNode = proc prepareAccountJsonObject(self: Service, account: GeneratedAccountDto, displayName: string): JsonNode =
result = %* { result = %* {
"name": account.alias, "name": if displayName == "": account.alias else: displayName,
"address": account.address, "address": account.address,
"identicon": account.identicon, "identicon": account.identicon,
"key-uid": account.keyUid, "key-uid": account.keyUid,
"keycard-pairing": nil "keycard-pairing": nil
} }
proc getAccountDataForAccountId(self: Service, accountId: string): JsonNode = proc getAccountDataForAccountId(self: Service, accountId: string, displayName: string): JsonNode =
for acc in self.generatedAccounts: for acc in self.generatedAccounts:
if(acc.id == accountId): if(acc.id == accountId):
return self.prepareAccountJsonObject(acc) return self.prepareAccountJsonObject(acc, displayName)
if(self.importedAccount.isValid()): if(self.importedAccount.isValid()):
if(self.importedAccount.id == accountId): if(self.importedAccount.id == accountId):
return self.prepareAccountJsonObject(self.importedAccount) return self.prepareAccountJsonObject(self.importedAccount, displayName)
proc prepareSubaccountJsonObject(self: Service, account: GeneratedAccountDto): proc prepareSubaccountJsonObject(self: Service, account: GeneratedAccountDto, displayName: string):
JsonNode = JsonNode =
result = %* [ result = %* [
{ {
@ -165,21 +165,21 @@ proc prepareSubaccountJsonObject(self: Service, account: GeneratedAccountDto):
{ {
"public-key": account.derivedAccounts.whisper.publicKey, "public-key": account.derivedAccounts.whisper.publicKey,
"address": account.derivedAccounts.whisper.address, "address": account.derivedAccounts.whisper.address,
"name": account.alias, "name": if displayName == "": account.alias else: displayName,
"identicon": account.identicon, "identicon": account.identicon,
"path": PATH_WHISPER, "path": PATH_WHISPER,
"chat": true "chat": true
} }
] ]
proc getSubaccountDataForAccountId(self: Service, accountId: string): JsonNode = proc getSubaccountDataForAccountId(self: Service, accountId: string, displayName: string): JsonNode =
for acc in self.generatedAccounts: for acc in self.generatedAccounts:
if(acc.id == accountId): if(acc.id == accountId):
return self.prepareSubaccountJsonObject(acc) return self.prepareSubaccountJsonObject(acc, displayName)
if(self.importedAccount.isValid()): if(self.importedAccount.isValid()):
if(self.importedAccount.id == accountId): if(self.importedAccount.id == accountId):
return self.prepareSubaccountJsonObject(self.importedAccount) return self.prepareSubaccountJsonObject(self.importedAccount, displayName)
proc prepareAccountSettingsJsonObject(self: Service, account: GeneratedAccountDto, proc prepareAccountSettingsJsonObject(self: Service, account: GeneratedAccountDto,
installationId: string, displayName: string): JsonNode = installationId: string, displayName: string): JsonNode =
@ -252,8 +252,8 @@ proc getDefaultNodeConfig*(self: Service, installationId: string): JsonNode =
method setupAccount*(self: Service, accountId, password, displayName: string): bool = method setupAccount*(self: Service, accountId, password, displayName: string): bool =
try: try:
let installationId = $genUUID() let installationId = $genUUID()
let accountDataJson = self.getAccountDataForAccountId(accountId) let accountDataJson = self.getAccountDataForAccountId(accountId, displayName)
let subaccountDataJson = self.getSubaccountDataForAccountId(accountId) let subaccountDataJson = self.getSubaccountDataForAccountId(accountId, displayName)
let settingsJson = self.getAccountSettings(accountId, installationId, displayName) let settingsJson = self.getAccountSettings(accountId, installationId, displayName)
let nodeConfigJson = self.getDefaultNodeConfig(installationId) let nodeConfigJson = self.getDefaultNodeConfig(installationId)