ens: Fix ens name inconsistency across app

This commit is contained in:
Igor Sirotin 2022-12-13 12:37:27 +03:00 committed by Igor Sirotin
parent 3f01af4446
commit 50427390dd
24 changed files with 86 additions and 54 deletions

View File

@ -382,8 +382,8 @@ proc buildAndRegisterLocalAccountSensitiveSettings(self: AppController) =
proc buildAndRegisterUserProfile(self: AppController) =
let pubKey = self.settingsService.getPublicKey()
let alias = self.settingsService.getName()
let preferredName = self.settingsService.getPreferredName()
var displayName = self.settingsService.getDisplayName()
var preferredName = self.settingsService.getPreferredName()
let displayName = self.settingsService.getDisplayName()
let ensUsernames = self.settingsService.getEnsUsernames()
let firstEnsName = if (ensUsernames.len > 0): ensUsernames[0] else: ""
let currentUserStatus = self.settingsService.getCurrentUserStatus()
@ -399,7 +399,6 @@ proc buildAndRegisterUserProfile(self: AppController) =
singletonInstance.userProfile.setFixedData(alias, loggedInAccount.keyUid, pubKey, loggedInAccount.keycardPairing.len > 0)
singletonInstance.userProfile.setDisplayName(displayName)
singletonInstance.userProfile.setPreferredName(preferredName)
singletonInstance.userProfile.setEnsName(firstEnsName)
singletonInstance.userProfile.setThumbnailImage(thumbnail)
singletonInstance.userProfile.setLargeImage(large)
singletonInstance.userProfile.setCurrentUserStatus(currentUserStatus.statusType.int)

View File

@ -11,7 +11,6 @@ QtObject:
pubKey: string
isKeycardUser: bool
# fields which may change during runtime
ensName: string
displayName: string
preferredName: string
thumbnailImage: string
@ -68,20 +67,6 @@ QtObject:
read = getUsername
notify = nameChanged
# this is not a slot
proc setEnsName*(self: UserProfile, name: string) =
if(self.ensName == name):
return
self.ensName = name
self.nameChanged()
proc getEnsName*(self: UserProfile): string {.slot.} =
self.ensName
QtProperty[string] ensName:
read = getEnsName
notify = nameChanged
# this is not a slot
proc setPreferredName*(self: UserProfile, name: string) =
if(self.preferredName == name):
@ -91,16 +76,11 @@ QtObject:
proc getPreferredName*(self: UserProfile): string {.slot.} =
self.preferredName
QtProperty[string] preferredName:
read = getPreferredName
notify = nameChanged
proc getPrettyPreferredName*(self: UserProfile): string {.slot.} =
self.preferredName
QtProperty[string] prettyPreferredName:
read = getPrettyPreferredName
notify = nameChanged
proc setDisplayName*(self: UserProfile, displayName: string) = # Not a slot
if(self.displayName == displayName):
return
@ -116,9 +96,7 @@ QtObject:
proc getName*(self: UserProfile): string {.slot.} =
if(self.preferredName.len > 0):
return self.getPrettyPreferredName()
elif(self.ensName.len > 0):
return self.ensName
return self.getPreferredName()
elif(self.displayName.len > 0):
return self.getDisplayName()
return self.username

View File

@ -69,7 +69,7 @@ method sendChatMessage*(
replyTo: string,
contentType: int) =
self.controller.sendChatMessage(msg, replyTo, contentType,
singletonInstance.userProfile.getEnsName())
singletonInstance.userProfile.getPreferredName())
method requestAddressForTransaction*(self: Module, fromAddress: string, amount: string, tokenAddress: string) =
self.controller.requestAddressForTransaction(fromAddress, amount, tokenAddress)

View File

@ -153,6 +153,9 @@ proc init*(self: Controller) =
var args = ContactArgs(e)
self.delegate.updateContactDetails(args.contactId)
self.events.on(SIGNAL_LOGGEDIN_USER_NAME_CHANGED) do(e: Args):
self.delegate.updateContactDetails(singletonInstance.userProfile.getPubKey())
self.events.on(SIGNAL_LOGGEDIN_USER_IMAGE_CHANGED) do(e: Args):
self.delegate.updateContactDetails(singletonInstance.userProfile.getPubKey())

View File

@ -452,6 +452,7 @@ method updateContactDetails*(self: Module, contactId: string) =
item.senderIcon = updatedContact.icon
item.senderIsAdded = updatedContact.details.added
item.senderTrustStatus = updatedContact.details.trustStatus
item.senderEnsVerified = updatedContact.details.ensVerified
if(item.messageContainsMentions):
let (m, _, err) = self.controller.getMessageDetails(item.id)
if(err.len == 0):

View File

@ -75,6 +75,9 @@ proc init*(self: Controller) =
let args = ContactArgs(e)
self.delegate.contactUpdated(args.contactId)
self.events.on(SIGNAL_LOGGEDIN_USER_NAME_CHANGED) do(e: Args):
self.delegate.userProfileUpdated()
self.events.on(SIGNAL_LOGGEDIN_USER_IMAGE_CHANGED) do(e: Args):
self.delegate.loggedInUserImageChanged()

View File

@ -31,6 +31,9 @@ method contactsStatusUpdated*(self: AccessInterface, statusUpdates: seq[StatusUp
method contactUpdated*(self: AccessInterface, publicKey: string) {.base.} =
raise newException(ValueError, "No implementation available")
method userProfileUpdated*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method loggedInUserImageChanged*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -116,6 +116,9 @@ method contactUpdated*(self: Module, publicKey: string) =
isUntrustworthy = contactDetails.details.trustStatus == TrustStatus.Untrustworthy,
)
method userProfileUpdated*(self: Module) =
self.contactUpdated(singletonInstance.userProfile.getPubKey())
method loggedInUserImageChanged*(self: Module) =
self.view.model().setIcon(singletonInstance.userProfile.getPubKey(), singletonInstance.userProfile.getIcon())

View File

@ -108,6 +108,13 @@ proc setPreferredName*(self: Controller, preferredName: string) =
else:
info "an error occurred saving prefered ens username", methodName="setPreferredName"
proc fixPreferredName*(self: Controller, ignoreCurrentValue: bool = false) =
if (not ignoreCurrentValue and singletonInstance.userProfile.getPreferredName().len > 0):
return
let ensUsernames = self.settingsService.getEnsUsernames()
let firstEnsName = if (ensUsernames.len > 0): ensUsernames[0] else: ""
self.setPreferredName(firstEnsName)
proc getEnsRegisteredAddress*(self: Controller): string =
return self.ensService.getEnsRegisteredAddress()

View File

@ -182,7 +182,7 @@ method removeEnsUsername*(self: Module, ensUsername: string): bool =
info "an error occurred removing ens username", methodName="removeEnsUsername"
return false
if (self.controller.getPreferredEnsUsername() == ensUsername):
self.controller.setPreferredName("")
self.controller.fixPreferredName(true)
self.view.model().removeItemByEnsUsername(ensUsername)
return true
@ -228,14 +228,14 @@ method connectOwnedUsername*(self: Module, ensUsername: string, isStatus: bool)
info "an error occurred saving ens username", methodName="connectOwnedUsername"
return
self.controller.setPreferredName(ensUsername)
self.controller.fixPreferredName()
self.view.model().addItem(Item(ensUsername: ensUsername, isPending: false))
method ensTransactionConfirmed*(self: Module, trxType: string, ensUsername: string, transactionHash: string) =
if(not self.controller.saveNewEnsUsername(ensUsername)):
info "an error occurred saving ens username", methodName="ensTransactionConfirmed"
return
self.controller.fixPreferredName()
if(self.view.model().containsEnsUsername(ensUsername)):
self.view.model().updatePendingStatus(ensUsername, false)
else:
@ -312,6 +312,7 @@ method registerEns(self: Module, password: string) =
var respResult: string
if(responseObj.getProp("result", respResult) and responseObj{"success"}.getBool == true):
self.controller.fixPreferredName()
self.view.model().addItem(Item(ensUsername: self.formatUsername(self.tmpSendEnsTransactionDetails.ensUsername, true), isPending: true))
self.view.emitTransactionWasSentSignal(response)

View File

@ -150,7 +150,7 @@ method sendSticker*(self: Module, channelId: string, replyTo: string, sticker: I
channelId,
replyTo,
stickerDto,
singletonInstance.userProfile.getEnsName())
singletonInstance.userProfile.getPreferredName())
method estimate*(self: Module, packId: string, address: string, price: string, uuid: string) =
self.controller.estimate(packId, address, price, uuid)

View File

@ -57,6 +57,7 @@ const SIGNAL_CONTACT_REJECTION_REMOVED* = "contactRejectionRemoved"
const SIGNAL_CONTACT_NICKNAME_CHANGED* = "contactNicknameChanged"
const SIGNAL_CONTACTS_STATUS_UPDATED* = "contactsStatusUpdated"
const SIGNAL_CONTACT_UPDATED* = "contactUpdated"
const SIGNAL_LOGGEDIN_USER_NAME_CHANGED* = "loggedInUserNameChanged"
const SIGNAL_LOGGEDIN_USER_IMAGE_CHANGED* = "loggedInUserImageChanged"
const SIGNAL_REMOVED_TRUST_STATUS* = "removedTrustStatus"
const SIGNAL_CONTACT_UNTRUSTWORTHY* = "contactUntrustworthy"
@ -217,8 +218,13 @@ QtObject:
self.fetchContacts()
self.doConnect()
signalConnect(singletonInstance.userProfile, "nameChanged()", self, "onLoggedInUserNameChange()", 2)
signalConnect(singletonInstance.userProfile, "imageChanged()", self, "onLoggedInUserImageChange()", 2)
proc onLoggedInUserNameChange*(self: Service) {.slot.} =
let data = Args()
self.events.emit(SIGNAL_LOGGEDIN_USER_NAME_CHANGED, data)
proc onLoggedInUserImageChange*(self: Service) {.slot.} =
let data = Args()
self.events.emit(SIGNAL_LOGGEDIN_USER_IMAGE_CHANGED, data)
@ -307,9 +313,9 @@ QtObject:
return ContactsDto(
id: singletonInstance.userProfile.getPubKey(),
displayName: singletonInstance.userProfile.getDisplayName(),
name: singletonInstance.userProfile.getEnsName(),
name: singletonInstance.userProfile.getPreferredName(),
alias: singletonInstance.userProfile.getUsername(),
ensVerified: singletonInstance.userProfile.getEnsName().len > 0,
ensVerified: singletonInstance.userProfile.getPreferredName().len > 0,
added: true,
image: Images(
thumbnail: singletonInstance.userProfile.getThumbnailImage(),
@ -364,11 +370,10 @@ QtObject:
return self.contactsStatus[publicKey]
proc getContactNameAndImageInternal(self: Service, publicKey: string):
proc getContactNameAndImageInternal(self: Service, contactDto: ContactsDto):
tuple[name: string, optionalName: string, image: string, largeImage: string] =
## This proc should be used accross the app in order to have for the same contact
## same image and name displayed everywhere in the app.
let contactDto = self.getContactById(publicKey)
result.name = contactDto.userDefaultDisplayName()
result.optionalName = contactDto.userOptionalName()
if(contactDto.image.thumbnail.len > 0):
@ -378,7 +383,8 @@ QtObject:
proc getContactNameAndImage*(self: Service, publicKey: string):
tuple[name: string, image: string, largeImage: string] =
let tempRes = self.getContactNameAndImageInternal(publicKey)
let contactDto = self.getContactById(publicKey)
let tempRes = self.getContactNameAndImageInternal(contactDto)
return (tempRes.name, tempRes.image, tempRes.largeImage)
proc saveContact(self: Service, contact: ContactsDto) =
@ -538,13 +544,14 @@ QtObject:
proc getContactDetails*(self: Service, pubKey: string): ContactDetails =
result = ContactDetails()
let (name, optionalName, icon, _) = self.getContactNameAndImageInternal(pubKey)
let contactDto = self.getContactById(pubKey)
let (name, optionalName, icon, _) = self.getContactNameAndImageInternal(contactDto)
result.defaultDisplayName = name
result.optionalName = optionalName
result.icon = icon
result.colorId = procs_from_visual_identity_service.colorIdOf(pubKey)
result.isCurrentUser = pubKey == singletonInstance.userProfile.getPubKey()
result.details = self.getContactById(pubKey)
result.details = contactDto
proc markUntrustworthy*(self: Service, publicKey: string) =
let response = status_contacts.markUntrustworthy(publicKey)

View File

@ -258,7 +258,7 @@ Item {
This function validates the text input's text.
*/
function validate(force) {
function validate(force = false) {
if (!force && !statusBaseInput.dirty && validationMode === StatusInput.ValidationMode.OnlyWhenDirty) {
return
}
@ -367,6 +367,14 @@ Item {
validate()
}
onValidatorsChanged: {
validate()
}
onValidationModeChanged: {
validate()
}
ColumnLayout {
id: inputLayout
anchors.fill: parent

View File

@ -194,7 +194,7 @@ StatusModal {
// text = qsTr("Pending")
// }
} else {
error = root.store.communitiesModuleInst.requestToJoinCommunity(root.communityId, root.store.userProfileInst.ensName)
error = root.store.communitiesModuleInst.requestToJoinCommunity(root.communityId, root.store.userProfileInst.preferredName)
}
if (error) {

View File

@ -421,7 +421,7 @@ QtObject {
const userCanJoin = userCanJoin(communityId)
// TODO find what to do when you can't join
if (userCanJoin) {
requestToJoinCommunity(communityId, userProfileInst.ensName)
requestToJoinCommunity(communityId, userProfileInst.preferredName)
}
}
return result

View File

@ -27,10 +27,22 @@ StatusDialog {
close();
}
footer: StatusDialogFooter {
rightButtons: ObjectModel {
StatusButton {
enabled: d.newUsername !== root.ensUsernamesStore.preferredUsername
text: qsTr("Apply")
onClicked: {
root.applied()
}
}
}
}
QtObject {
id: d
property string newUsername: ""
property string newUsername: root.ensUsernamesStore.preferredUsername
}
ColumnLayout {

View File

@ -7,10 +7,10 @@ QtObject {
property var profileModule
property string pubkey: userProfile.pubKey
property string name: userProfile.name // in case of ens returns pretty ens form
property string name: userProfile.name
property string username: userProfile.username
property string displayName: userProfile.displayName
property string ensName: userProfile.preferredName || userProfile.ensName
property string preferredName: userProfile.preferredName
property string profileLargeImage: userProfile.largeImage
property string icon: userProfile.icon
property bool userDeclinedBackupBanner: localAccountSensitiveSettings.userDeclinedBackupBanner

View File

@ -123,7 +123,7 @@ ColumnLayout {
ProfileDescriptionPanel {
id: descriptionPanel
readonly property bool isEnsName: profileStore.ensName
readonly property bool isEnsName: profileStore.preferredName
function reevaluateSocialLinkInputs() {
socialLinksModel = null
@ -134,8 +134,8 @@ ColumnLayout {
displayName.focus: !isEnsName
displayName.input.edit.readOnly: isEnsName
displayName.text: profileStore.ensName || profileStore.displayName
displayName.validationMode: isEnsName ? StatusInput.ValidationMode.None : StatusInput.ValidationMode.Always
displayName.text: profileStore.name
displayName.validationMode: StatusInput.ValidationMode.Always
displayName.validators: isEnsName ? [] : Constants.validators.displayName
bio.text: profileStore.bio
socialLinksModel: staticSocialLinksSubsetModel

View File

@ -443,7 +443,7 @@ Item {
identicon.asset.charactersLen: 2
identicon.asset.color: Utils.colorForPubkey(appMain.rootStore.userProfileInst.pubKey)
identicon.ringSettings.ringSpecModel: Utils.getColorHashAsJson(appMain.rootStore.userProfileInst.pubKey,
appMain.rootStore.userProfileInst.ensName)
appMain.rootStore.userProfileInst.preferredName)
badge.visible: true
badge.anchors {

View File

@ -98,7 +98,7 @@ StatusModal {
messageTimestamp: root.responseTimestamp
senderId: userProfile.pubKey
senderDisplayName: userProfile.displayName
senderIsEnsVerified: !!userProfile.ensName
senderIsEnsVerified: !!userProfile.preferredName
senderIcon: userProfile.icon
messageText: root.responseText
messageContentType: Constants.messageContentType.messageType

View File

@ -75,7 +75,7 @@ StatusDialog {
senderId: userProfile.pubKey
senderDisplayName: userProfile.name
senderIcon: userProfile.icon
senderIsEnsVerified: !!userProfile.ensName
senderIsEnsVerified: !!userProfile.preferredName
messageText: root.verificationChallenge
messageContentType: Constants.messageContentType.messageType
placeholderMessage: true

View File

@ -23,7 +23,7 @@ StatusMenu {
displayName: root.store.userProfileInst.name
pubkey: root.store.userProfileInst.pubKey
icon: root.store.userProfileInst.icon
userIsEnsVerified: !!root.store.userProfileInst.ensName
userIsEnsVerified: !!root.store.userProfileInst.preferredName
}
StatusMenuSeparator {

View File

@ -77,7 +77,7 @@ Pane {
readonly property string linkToProfile: {
let user = ""
if (d.isCurrentUser)
user = root.profileStore.ensName
user = root.profileStore.preferredName
else
user = contactDetails.name
if (!user)

View File

@ -395,6 +395,7 @@ Loader {
StatusMessage {
id: delegate
Layout.fillWidth: true
function convertContentType(value) {
switch (value) {
case Constants.messageContentType.messageType:
@ -468,7 +469,13 @@ Loader {
isEdited: root.isEdited
hasMention: root.hasMention
isPinned: root.pinnedMessage
pinnedBy: root.pinnedMessage && !root.isDiscordMessage ? Utils.getContactDetailsAsJson(root.messagePinnedBy, false).displayName : ""
pinnedBy: {
if (!root.pinnedMessage || root.isDiscordMessage)
return ""
const contact = Utils.getContactDetailsAsJson(root.messagePinnedBy, false)
const ensName = contact.ensVerified ? contact.name : ""
return ProfileUtils.displayName(contact.localNickname, ensName, contact.displayName, contact.alias)
}
hasExpired: root.isExpired
isSending: root.isSending
resendError: root.resendError