feat: emit signals on saving profile identity

This commit is contained in:
MishkaRogachev 2024-03-14 16:56:38 +01:00 committed by Noelia
parent 8a5164db68
commit b37f0f0fd8
8 changed files with 60 additions and 36 deletions

View File

@ -80,32 +80,32 @@ proc init*(self: Controller) =
let args = CommunitiesArgs(e) let args = CommunitiesArgs(e)
self.delegate.onCommunitiesUpdated(args.communities) self.delegate.onCommunitiesUpdated(args.communities)
proc storeIdentityImage*(self: Controller, address: string, image: string, aX: int, aY: int, bX: int, bY: int) = proc storeIdentityImage*(self: Controller, address: string, image: string, aX: int, aY: int, bX: int, bY: int): bool =
discard self.profileService.storeIdentityImage(address, image, aX, aY, bX, bY) len(self.profileService.storeIdentityImage(address, image, aX, aY, bX, bY)) > 0
proc deleteIdentityImage*(self: Controller, address: string) = proc deleteIdentityImage*(self: Controller, address: string): bool =
self.profileService.deleteIdentityImage(address) self.profileService.deleteIdentityImage(address)
proc setDisplayName*(self: Controller, displayName: string) = proc setDisplayName*(self: Controller, displayName: string): bool =
self.profileService.setDisplayName(displayName) self.profileService.setDisplayName(displayName)
proc getSocialLinks*(self: Controller): SocialLinks = proc getSocialLinks*(self: Controller): SocialLinks =
return self.settingsService.getSocialLinks() self.settingsService.getSocialLinks()
proc getCommunityById*(self: Controller, id: string): CommunityDto = proc getCommunityById*(self: Controller, id: string): CommunityDto =
return self.communityService.getCommunityById(id) self.communityService.getCommunityById(id)
proc getAccountByAddress*(self: Controller, address: string): WalletAccountDto = proc getAccountByAddress*(self: Controller, address: string): WalletAccountDto =
return self.walletAccountService.getAccountByAddress(address) self.walletAccountService.getAccountByAddress(address)
proc getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAccountDto] = proc getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAccountDto] =
return self.walletAccountService.getWalletAccounts(true) self.walletAccountService.getWalletAccounts(true)
proc getChainIds*(self: Controller): seq[int] = proc getChainIds*(self: Controller): seq[int] =
return self.networkService.getNetworks().map(n => n.chainId) self.networkService.getNetworks().map(n => n.chainId)
proc getEnabledChainIds*(self: Controller): seq[int] = proc getEnabledChainIds*(self: Controller): seq[int] =
return self.networkService.getNetworks().filter(n => n.enabled).map(n => n.chainId) self.networkService.getNetworks().filter(n => n.enabled).map(n => n.chainId)
proc setSocialLinks*(self: Controller, links: SocialLinks) = proc setSocialLinks*(self: Controller, links: SocialLinks) =
self.settingsService.setSocialLinks(links) self.settingsService.setSocialLinks(links)
@ -139,4 +139,4 @@ proc requestCommunityInfo*(self: Controller, communityId: string, shard: Shard)
self.communityService.requestCommunityInfo(communityId, shard) self.communityService.requestCommunityInfo(communityId, shard)
proc getTokenBySymbolList*(self: Controller): var seq[TokenBySymbolItem] = proc getTokenBySymbolList*(self: Controller): var seq[TokenBySymbolItem] =
return self.tokenService.getTokenBySymbolList() self.tokenService.getTokenBySymbolList()

View File

@ -55,7 +55,7 @@ method onProfileShowcasePreferencesSaveSucceeded*(self: AccessInterface) {.base.
method onProfileShowcasePreferencesSaveFailed*(self: AccessInterface) {.base.} = method onProfileShowcasePreferencesSaveFailed*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method saveProfileIdentityInfo*(self: AccessInterface, identity: IdentitySaveData) {.base.} = method saveProfileIdentity*(self: AccessInterface, identity: IdentitySaveData) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method saveProfileShowcasePreferences*(self: AccessInterface, showcase: ShowcaseSaveData) {.base.} = method saveProfileShowcasePreferences*(self: AccessInterface, showcase: ShowcaseSaveData) {.base.} =

View File

@ -127,7 +127,7 @@ method getProfileShowcaseEntriesLimit*(self: Module): int =
method setIsFirstShowcaseInteraction(self: Module) = method setIsFirstShowcaseInteraction(self: Module) =
singletonInstance.localAccountSettings.setIsFirstShowcaseInteraction(false) singletonInstance.localAccountSettings.setIsFirstShowcaseInteraction(false)
proc storeIdentityImage*(self: Module, identityImage: IdentityImage) = proc storeIdentityImage*(self: Module, identityImage: IdentityImage): bool =
let keyUid = singletonInstance.userProfile.getKeyUid() let keyUid = singletonInstance.userProfile.getKeyUid()
let image = singletonInstance.utils.formatImagePath(identityImage.source) let image = singletonInstance.utils.formatImagePath(identityImage.source)
# FIXME the function to get the file size is messed up # FIXME the function to get the file size is messed up
@ -136,17 +136,21 @@ proc storeIdentityImage*(self: Module, identityImage: IdentityImage) =
# return "Max file size is 20MB" # return "Max file size is 20MB"
self.controller.storeIdentityImage(keyUid, image, identityImage.aX, identityImage.aY, identityImage.bX, identityImage.bY) self.controller.storeIdentityImage(keyUid, image, identityImage.aX, identityImage.aY, identityImage.bX, identityImage.bY)
proc deleteIdentityImage*(self: Module) = proc deleteIdentityImage*(self: Module): bool =
let keyUid = singletonInstance.userProfile.getKeyUid() let keyUid = singletonInstance.userProfile.getKeyUid()
self.controller.deleteIdentityImage(keyUid) self.controller.deleteIdentityImage(keyUid)
method saveProfileIdentityInfo*(self: Module, identity: IdentitySaveData) = method saveProfileIdentity*(self: Module, identity: IdentitySaveData) =
self.controller.setDisplayName(identity.displayName) var ok = self.controller.setDisplayName(identity.displayName)
discard self.controller.setBio(identity.bio) ok = ok and self.controller.setBio(identity.bio)
if identity.image != nil: if identity.image != nil:
self.storeIdentityImage(identity.image) ok = ok and self.storeIdentityImage(identity.image)
else: else:
self.deleteIdentityImage() ok = ok and self.deleteIdentityImage()
if ok:
self.view.emitProfileIdentitySaveSucceededSignal()
else:
self.view.emitProfileIdentitySaveFailedSignal()
method saveProfileShowcasePreferences*(self: Module, showcase: ShowcaseSaveData) = method saveProfileShowcasePreferences*(self: Module, showcase: ShowcaseSaveData) =
# TODO: remove this check within old api # TODO: remove this check within old api

View File

@ -197,6 +197,14 @@ QtObject:
proc emitBioChangedSignal*(self: View) = proc emitBioChangedSignal*(self: View) =
self.bioChanged() self.bioChanged()
proc profileIdentitySaveSucceeded*(self: View) {.signal.}
proc emitProfileIdentitySaveSucceededSignal*(self: View) =
self.profileIdentitySaveSucceeded()
proc profileIdentitySaveFailed*(self: View) {.signal.}
proc emitProfileIdentitySaveFailedSignal*(self: View) =
self.profileIdentitySaveFailed()
proc profileShowcasePreferencesSaveSucceeded*(self: View) {.signal.} proc profileShowcasePreferencesSaveSucceeded*(self: View) {.signal.}
proc emitProfileShowcasePreferencesSaveSucceededSignal*(self: View) = proc emitProfileShowcasePreferencesSaveSucceededSignal*(self: View) =
self.profileShowcasePreferencesSaveSucceeded() self.profileShowcasePreferencesSaveSucceeded()
@ -272,10 +280,10 @@ QtObject:
self.profileShowcaseCollectiblesModel.clear() self.profileShowcaseCollectiblesModel.clear()
self.profileShowcaseAssetsModel.clear() self.profileShowcaseAssetsModel.clear()
proc saveIdentityInfo(self: View, profileData: string) {.slot.} = proc saveProfileIdentity(self: View, profileData: string) {.slot.} =
let profileDataObj = profileData.parseJson let profileDataObj = profileData.parseJson
let identityInfo = profileDataObj.toIdentitySaveData() let identityInfo = profileDataObj.toIdentitySaveData()
self.delegate.saveProfileIdentityInfo(identityInfo) self.delegate.saveProfileIdentity(identityInfo)
proc saveProfileShowcasePreferences(self: View, profileData: string) {.slot.} = proc saveProfileShowcasePreferences(self: View, profileData: string) {.slot.} =
let profileDataObj = profileData.parseJson let profileDataObj = profileData.parseJson

View File

@ -198,7 +198,7 @@ proc shouldStartWithOnboardingScreen*(self: Controller): bool =
proc storeProfileDataAndProceedWithAppLoading*(self: Controller) = proc storeProfileDataAndProceedWithAppLoading*(self: Controller) =
self.delegate.removeAllKeycardUidPairsForCheckingForAChangeAfterLogin() # reason for this is in the table in AppController.nim file self.delegate.removeAllKeycardUidPairsForCheckingForAChangeAfterLogin() # reason for this is in the table in AppController.nim file
self.profileService.setDisplayName(self.tmpDisplayName) discard self.profileService.setDisplayName(self.tmpDisplayName)
let images = self.storeIdentityImage() let images = self.storeIdentityImage()
self.accountsService.updateLoggedInAccount(self.tmpDisplayName, images) self.accountsService.updateLoggedInAccount(self.tmpDisplayName, images)
self.delegate.finishAppLoading() self.delegate.finishAppLoading()

View File

@ -86,29 +86,33 @@ QtObject:
except Exception as e: except Exception as e:
error "error: ", procName="storeIdentityImage", errName = e.name, errDesription = e.msg error "error: ", procName="storeIdentityImage", errName = e.name, errDesription = e.msg
proc deleteIdentityImage*(self: Service, address: string) = proc deleteIdentityImage*(self: Service, address: string): bool =
try: try:
let response = status_accounts.deleteIdentityImage(address) let response = status_accounts.deleteIdentityImage(address)
if(not response.error.isNil): if(not response.error.isNil):
error "could not delete identity images" error "could not delete identity images"
return return false
singletonInstance.userProfile.setLargeImage("") singletonInstance.userProfile.setLargeImage("")
singletonInstance.userProfile.setThumbnailImage("") singletonInstance.userProfile.setThumbnailImage("")
return true
except Exception as e: except Exception as e:
error "error: ", procName="deleteIdentityImage", errName = e.name, errDesription = e.msg error "error: ", procName="deleteIdentityImage", errName = e.name, errDesription = e.msg
return false
proc setDisplayName*(self: Service, displayName: string) = proc setDisplayName*(self: Service, displayName: string): bool =
try: try:
let response = status_accounts.setDisplayName(displayName) let response = status_accounts.setDisplayName(displayName)
if(not response.error.isNil): if(not response.error.isNil):
error "could not set display name" error "could not set display name"
return return false
if(not self.settingsService.saveDisplayName(displayName)): if(not self.settingsService.saveDisplayName(displayName)):
error "could save display name to the settings" error "could save display name to the settings"
return return false
return true
except Exception as e: except Exception as e:
error "error: ", procName="setDisplayName", errName = e.name, errDesription = e.msg error "error: ", procName="setDisplayName", errName = e.name, errDesription = e.msg
return false
proc requestProfileShowcaseForContact*(self: Service, contactId: string) = proc requestProfileShowcaseForContact*(self: Service, contactId: string) =
let arg = AsyncGetProfileShowcaseForContactTaskArg( let arg = AsyncGetProfileShowcaseForContactTaskArg(

View File

@ -62,7 +62,7 @@ QtObject {
} }
// Identity related: // Identity related:
function saveIdentityInfo(displayName, bio, source, aX, aY, bX, bY) { function saveProfileIdentity(displayName, bio, source, aX, aY, bX, bY) {
var identityInfo = { var identityInfo = {
"displayName": displayName, "displayName": displayName,
"bio": bio, "bio": bio,
@ -75,7 +75,7 @@ QtObject {
} : null } : null
} }
let json = JSON.stringify(identityInfo) let json = JSON.stringify(identityInfo)
root.profileModule.saveIdentityInfo(json) root.profileModule.saveProfileIdentity(json)
} }
function getProfileShowcaseEntriesLimit() { function getProfileShowcaseEntriesLimit() {
@ -102,12 +102,20 @@ QtObject {
root.profileModule.setIsFirstShowcaseInteraction() root.profileModule.setIsFirstShowcaseInteraction()
} }
signal profileIdentitySaveSucceeded()
signal profileIdentitySaveFailed()
signal profileShowcasePreferencesSaveSucceeded() signal profileShowcasePreferencesSaveSucceeded()
signal profileShowcasePreferencesSaveFailed() signal profileShowcasePreferencesSaveFailed()
readonly property Connections profileModuleConnections: Connections { readonly property Connections profileModuleConnections: Connections {
target: root.profileModule target: root.profileModule
function onProfileIdentitySaveSucceeded() {
root.profileIdentitySaveSucceeded()
}
function onProfileIdentitySaveFailed() {
root.profileIdentitySaveFailed()
}
function onProfileShowcasePreferencesSaveSucceeded() { function onProfileShowcasePreferencesSaveSucceeded() {
root.profileShowcasePreferencesSaveSucceeded() root.profileShowcasePreferencesSaveSucceeded()
} }

View File

@ -165,7 +165,7 @@ SettingsContentBase {
// Identity info // Identity info
if (isIdentityTabDirty) { if (isIdentityTabDirty) {
root.profileStore.saveIdentityInfo(descriptionPanel.displayName.text, root.profileStore.saveProfileIdentity(descriptionPanel.displayName.text,
descriptionPanel.bio.text.trim(), descriptionPanel.bio.text.trim(),
profileHeader.icon, profileHeader.icon,
profileHeader.cropRect.x, profileHeader.cropRect.x,