feat(Communities): changes in import popup for public keys

Also: refactor(communities), moved request to join funcs to communities module
This is needed because we can now request to join from the Import popup

Closes #11242
This commit is contained in:
Jonathan Rainville 2023-07-21 13:21:11 -04:00 committed by Alexandra Betouni
parent bb2bbfb5b6
commit 6e346d2c0d
20 changed files with 368 additions and 251 deletions

View File

@ -14,7 +14,6 @@ import ../../../../app_service/service/wallet_account/service as wallet_account_
import ../../../../app_service/service/token/service as token_service
import ../../../../app_service/service/community_tokens/service as community_tokens_service
import ../../../../app_service/service/visual_identity/service as procs_from_visual_identity_service
import ../../shared_modules/keycard_popup/io_interface as keycard_shared_module
import backend/collectibles as backend_collectibles
import ../../../core/signals/types
@ -22,8 +21,6 @@ import ../../../global/app_signals
import ../../../core/eventemitter
import ../../../core/unique_event_emitter
const UNIQUE_MAIN_MODULE_AUTH_IDENTIFIER* = "MainModule-Action-Authentication"
type
Controller* = ref object of RootObj
delegate: io_interface.AccessInterface
@ -43,12 +40,7 @@ type
walletAccountService: wallet_account_service.Service
tokenService: token_service.Service
communityTokensService: community_tokens_service.Service
tmpAuthenticationForJoinInProgress: bool
tmpAuthenticationForEditSharedAddresses: bool
tmpRequestToJoinEnsName: string
tmpAddressesToShare: seq[string]
tmpAirdropAddress: string
tmpAuthenticationWithCallbackInProgress: bool
proc newController*(delegate: io_interface.AccessInterface, sectionId: string, isCommunity: bool, events: EventEmitter,
settingsService: settings_service.Service, nodeConfigurationService: node_configuration_service.Service,
@ -75,13 +67,7 @@ proc newController*(delegate: io_interface.AccessInterface, sectionId: string, i
result.walletAccountService = walletAccountService
result.tokenService = tokenService
result.communityTokensService = communityTokensService
result.tmpAuthenticationForJoinInProgress = false
result.tmpAuthenticationForEditSharedAddresses = false
result.tmpRequestToJoinEnsName = ""
result.tmpAirdropAddress = ""
result.tmpAddressesToShare = @[]
result.tmpAuthenticationWithCallbackInProgress = true
proc delete*(self: Controller) =
self.events.disconnect()
@ -94,56 +80,6 @@ proc getIsCurrentSectionActive*(self: Controller): bool =
proc setIsCurrentSectionActive*(self: Controller, active: bool) =
self.isCurrentSectionActive = active
proc userAuthenticationCanceled*(self: Controller) =
self.tmpAuthenticationForJoinInProgress = false
self.tmpAuthenticationForEditSharedAddresses = false
self.tmpRequestToJoinEnsName = ""
self.tmpAirdropAddress = ""
self.tmpAddressesToShare = @[]
proc requestToJoinCommunityAuthenticated*(self: Controller, password: string) =
self.communityService.asyncRequestToJoinCommunity(self.sectionId, self.tmpRequestToJoinEnsName,
password, self.tmpAddressesToShare, self.tmpAirdropAddress)
self.tmpAuthenticationForJoinInProgress = false
self.tmpRequestToJoinEnsName = ""
self.tmpAirdropAddress = ""
self.tmpAddressesToShare = @[]
proc editSharedAddressesAuthenticated*(self: Controller, password: string) =
self.communityService.asyncEditSharedAddresses(
self.sectionId,
password,
self.tmpAddressesToShare,
self.tmpAirdropAddress,
)
self.tmpAuthenticationForEditSharedAddresses = false
self.tmpAirdropAddress = ""
self.tmpAddressesToShare = @[]
proc userAuthenticated*(self: Controller, password: string) =
if self.tmpAuthenticationForJoinInProgress:
self.requestToJoinCommunityAuthenticated(password)
elif self.tmpAuthenticationForEditSharedAddresses:
self.editSharedAddressesAuthenticated(password)
proc authenticate*(self: Controller, keyUid = "") =
let data = SharedKeycarModuleAuthenticationArgs(uniqueIdentifier: UNIQUE_MAIN_MODULE_AUTH_IDENTIFIER,
keyUid: keyUid)
self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_AUTHENTICATE_USER, data)
proc authenticateToRequestToJoinCommunity*(self: Controller, ensName: string, addressesToShare: seq[string], airdropAddress: string) =
self.tmpAuthenticationForJoinInProgress = true
self.tmpRequestToJoinEnsName = ensName
self.tmpAirdropAddress = airdropAddress
self.tmpAddressesToShare = addressesToShare
self.authenticate()
proc authenticateToEditSharedAddresses*(self: Controller, addressesToShare: seq[string], airdropAddress: string) =
self.tmpAuthenticationForEditSharedAddresses = true
self.tmpAirdropAddress = airdropAddress
self.tmpAddressesToShare = addressesToShare
self.authenticate()
proc getMySectionId*(self: Controller): string =
return self.sectionId
@ -225,17 +161,6 @@ proc init*(self: Controller) =
self.contactService, self.chatService, self.communityService, self.messageService, self.gifService,
self.mailserversService, setChatAsActive = true)
self.events.on(SIGNAL_SHARED_KEYCARD_MODULE_USER_AUTHENTICATED) do(e: Args):
let args = SharedKeycarModuleArgs(e)
if args.uniqueIdentifier != UNIQUE_MAIN_MODULE_AUTH_IDENTIFIER:
return
if self.tmpAuthenticationForJoinInProgress or self.tmpAuthenticationForEditSharedAddresses:
self.delegate.onUserAuthenticated(args.pin, args.password, args.keyUid)
if self.tmpAuthenticationWithCallbackInProgress:
let authenticated = not (args.password == "" and args.pin == "")
self.delegate.callbackFromAuthentication(authenticated)
self.tmpAuthenticationWithCallbackInProgress = false
if (self.isCommunitySection):
self.events.on(SIGNAL_COMMUNITY_CHANNEL_CREATED) do(e:Args):
let args = CommunityChatArgs(e)
@ -727,7 +652,3 @@ proc getContractAddressesForToken*(self: Controller, symbol: string): Table[int,
proc getCommunityTokenList*(self: Controller): seq[CommunityTokenDto] =
return self.communityTokensService.getCommunityTokens(self.getMySectionId())
proc authenticateWithCallback*(self: Controller) =
self.tmpAuthenticationWithCallbackInProgress = true
self.authenticate()

View File

@ -376,23 +376,10 @@ method onJoinedCommunity*(self: AccessInterface) {.base.} =
method onAcceptRequestToJoinFailedNoPermission*(self: AccessInterface, communityId: string, memberKey: string, requestId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method onUserAuthenticated*(self: AccessInterface, pin: string, password: string, keyUid: string) {.base.} =
raise newException(ValueError, "No implementation available")
method onDeactivateChatLoader*(self: AccessInterface, chatId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method requestToJoinCommunityWithAuthentication*(self: AccessInterface, ensName: string, addressesToShare: seq[string],
airdropAddress: string) {.base.} =
raise newException(ValueError, "No implementation available")
method editSharedAddressesWithAuthentication*(self: AccessInterface, addressesToShare: seq[string], airdropAddress: string)
{.base.} =
raise newException(ValueError, "No implementation available")
method onCommunityCheckPermissionsToJoinResponse*(self: AccessInterface, checkPermissionsToJoinResponse: CheckPermissionsToJoinResponseDto) {.base.} =
raise newException(ValueError, "No implementation available")
method onCommunityCheckChannelPermissionsResponse*(self: AccessInterface, chatId: string, checkChannelPermissionsResponse: CheckChannelPermissionsResponseDto) {.base.} =
@ -400,9 +387,3 @@ method onCommunityCheckChannelPermissionsResponse*(self: AccessInterface, chatId
method onCommunityCheckAllChannelsPermissionsResponse*(self: AccessInterface, checkAllChannelsPermissionsResponse: CheckAllChannelsPermissionsResponseDto) {.base.} =
raise newException(ValueError, "No implementation available")
method authenticateWithCallback*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method callbackFromAuthentication*(self: AccessInterface, authenticated: bool) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -895,14 +895,6 @@ method onKickedFromCommunity*(self: Module) =
method onJoinedCommunity*(self: Module) =
self.view.setAmIMember(true)
method onUserAuthenticated*(self: Module, pin: string, password: string, keyUid: string) =
if password == "" and pin == "":
self.view.userAuthenticationCanceled()
self.controller.userAuthenticationCanceled()
return
self.controller.userAuthenticated(password)
method onMarkAllMessagesRead*(self: Module, chat: ChatDto) =
self.updateBadgeNotifications(chat, hasUnreadMessages=false, unviewedMentionsCount=0)
@ -1328,18 +1320,5 @@ method createOrEditCommunityTokenPermission*(self: Module, communityId: string,
method deleteCommunityTokenPermission*(self: Module, communityId: string, permissionId: string) =
self.controller.deleteCommunityTokenPermission(communityId, permissionId)
method requestToJoinCommunityWithAuthentication*(self: Module, ensName: string, addressesToShare: seq[string],
airdropAddress: string) =
self.controller.authenticateToRequestToJoinCommunity(ensName, addressesToShare, airdropAddress)
method editSharedAddressesWithAuthentication*(self: Module, addressesToShare: seq[string], airdropAddress: string) =
self.controller.authenticateToEditSharedAddresses(addressesToShare, airdropAddress)
method onDeactivateChatLoader*(self: Module, chatId: string) =
self.view.chatsModel().disableChatLoader(chatId)
method authenticateWithCallback*(self: Module) =
self.controller.authenticateWithCallback()
method callbackFromAuthentication*(self: Module, authenticated: bool) =
self.view.callbackFromAuthentication(authenticated)

View File

@ -240,24 +240,6 @@ QtObject:
proc createGroupChat*(self: View, communityID: string, groupName: string, pubKeys: string) {.slot.} =
self.delegate.createGroupChat(communityID, groupName, pubKeys)
proc requestToJoinCommunityWithAuthentication*(self: View, ensName: string) {.slot.} =
self.delegate.requestToJoinCommunityWithAuthentication(ensName, @[], "")
proc requestToJoinCommunityWithAuthenticationWithSharedAddresses*(self: View, ensName: string,
addressesToShare: string, airdropAddress: string) {.slot.} =
try:
let addressesArray = map(parseJson(addressesToShare).getElems(), proc(x:JsonNode):string = x.getStr())
self.delegate.requestToJoinCommunityWithAuthentication(ensName, addressesArray, airdropAddress)
except Exception as e:
echo "Error requesting to join community with authentication and shared addresses: ", e.msg
proc editSharedAddressesWithAuthentication*(self: View, addressesToShare: string, airdropAddress: string) {.slot.} =
try:
let addressesArray = map(parseJson(addressesToShare).getElems(), proc(x:JsonNode):string = x.getStr())
self.delegate.editSharedAddressesWithAuthentication(addressesArray, airdropAddress)
except Exception as e:
echo "Error editing shared addresses with authentication: ", e.msg
proc joinGroupChatFromInvitation*(self: View, groupName: string, chatId: string, adminPK: string) {.slot.} =
self.delegate.joinGroupChatFromInvitation(groupName, chatId, adminPK)
@ -427,10 +409,3 @@ QtObject:
QtProperty[bool] allTokenRequirementsMet:
read = getAllTokenRequirementsMet
notify = allTokenRequirementsMetChanged
proc userAuthenticationCanceled*(self: View) {.signal.}
proc authenticateWithCallback*(self: View) {.slot.} =
self.delegate.authenticateWithCallback()
proc callbackFromAuthentication*(self: View, authenticated: bool) {.signal.}

View File

@ -12,6 +12,15 @@ import ../../../../app_service/service/community_tokens/service as community_tok
import ../../../../app_service/service/token/service as token_service
import ../../../../app_service/service/wallet_account/service as wallet_account_service
import backend/collectibles as backend_collectibles
import ../../shared_modules/keycard_popup/io_interface as keycard_shared_module
const UNIQUE_COMMUNITIES_MODULE_AUTH_IDENTIFIER* = "CommunitiesModule-Action-Authentication"
type
AuthenticationAction* {.pure.} = enum
None = 0,
CommunityJoin = 1,
CommunitySharedAddressesJoin = 2,
type
Controller* = ref object of RootObj
@ -23,6 +32,12 @@ type
networksService: networks_service.Service
tokenService: token_service.Service
chatService: chat_service.Service
tmpCommunityId: string
tmpAuthenticationAction: AuthenticationAction
tmpRequestToJoinEnsName: string
tmpAddressesToShare: seq[string]
tmpAirdropAddress: string
tmpAuthenticationWithCallbackInProgress: bool
proc newController*(
delegate: io_interface.AccessInterface,
@ -43,6 +58,11 @@ proc newController*(
result.networksService = networksService
result.tokenService = tokenService
result.chatService = chatService
result.tmpCommunityId = ""
result.tmpRequestToJoinEnsName = ""
result.tmpAirdropAddress = ""
result.tmpAddressesToShare = @[]
result.tmpAuthenticationWithCallbackInProgress = false
proc delete*(self: Controller) =
discard
@ -151,6 +171,16 @@ proc init*(self: Controller) =
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e: Args):
self.delegate.onWalletAccountTokensRebuilt()
self.events.on(SIGNAL_SHARED_KEYCARD_MODULE_USER_AUTHENTICATED) do(e: Args):
let args = SharedKeycarModuleArgs(e)
if args.uniqueIdentifier != UNIQUE_COMMUNITIES_MODULE_AUTH_IDENTIFIER:
return
self.delegate.onUserAuthenticated(args.pin, args.password, args.keyUid)
if self.tmpAuthenticationWithCallbackInProgress:
let authenticated = not (args.password == "" and args.pin == "")
self.delegate.callbackFromAuthentication(authenticated)
self.tmpAuthenticationWithCallbackInProgress = false
proc getCommunityTags*(self: Controller): string =
result = self.communityService.getCommunityTags()
@ -298,4 +328,67 @@ proc shareCommunityChannelUrlWithChatKey*(self: Controller, communityId: string,
return self.communityService.shareCommunityChannelUrlWithChatKey(communityId, chatId)
proc shareCommunityChannelUrlWithData*(self: Controller, communityId: string, chatId: string): string =
return self.communityService.shareCommunityChannelUrlWithData(communityId, chatId)
return self.communityService.shareCommunityChannelUrlWithData(communityId, chatId)
proc userAuthenticationCanceled*(self: Controller) =
self.tmpAuthenticationAction = AuthenticationAction.None
self.tmpCommunityId = ""
self.tmpRequestToJoinEnsName = ""
self.tmpAirdropAddress = ""
self.tmpAddressesToShare = @[]
proc requestToJoinCommunityAuthenticated*(self: Controller, password: string) =
self.communityService.asyncRequestToJoinCommunity(
self.tmpCommunityId,
self.tmpRequestToJoinEnsName,
password,
self.tmpAddressesToShare,
self.tmpAirdropAddress
)
self.tmpAuthenticationAction = AuthenticationAction.None
self.tmpCommunityId = ""
self.tmpRequestToJoinEnsName = ""
self.tmpAirdropAddress = ""
self.tmpAddressesToShare = @[]
proc editSharedAddressesAuthenticated*(self: Controller, password: string) =
self.communityService.asyncEditSharedAddresses(
self.tmpCommunityId,
password,
self.tmpAddressesToShare,
self.tmpAirdropAddress,
)
self.tmpAuthenticationAction = AuthenticationAction.None
self.tmpCommunityId = ""
self.tmpAirdropAddress = ""
self.tmpAddressesToShare = @[]
proc userAuthenticated*(self: Controller, password: string) =
if self.tmpAuthenticationAction == AuthenticationAction.CommunityJoin:
self.requestToJoinCommunityAuthenticated(password)
elif self.tmpAuthenticationAction == AuthenticationAction.CommunitySharedAddressesJoin:
self.editSharedAddressesAuthenticated(password)
proc authenticate*(self: Controller, keyUid = "") =
let data = SharedKeycarModuleAuthenticationArgs(uniqueIdentifier: UNIQUE_COMMUNITIES_MODULE_AUTH_IDENTIFIER,
keyUid: keyUid)
self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_AUTHENTICATE_USER, data)
proc authenticateToRequestToJoinCommunity*(self: Controller, communityId: string, ensName: string, addressesToShare: seq[string], airdropAddress: string) =
self.tmpCommunityId = communityId
self.tmpAuthenticationAction = AuthenticationAction.CommunityJoin
self.tmpRequestToJoinEnsName = ensName
self.tmpAirdropAddress = airdropAddress
self.tmpAddressesToShare = addressesToShare
self.authenticate()
proc authenticateToEditSharedAddresses*(self: Controller, communityId: string, addressesToShare: seq[string], airdropAddress: string) =
self.tmpCommunityId = communityId
self.tmpAuthenticationAction = AuthenticationAction.CommunitySharedAddressesJoin
self.tmpAirdropAddress = airdropAddress
self.tmpAddressesToShare = addressesToShare
self.authenticate()
proc authenticateWithCallback*(self: Controller) =
self.tmpAuthenticationWithCallbackInProgress = true
self.authenticate()

View File

@ -183,3 +183,20 @@ method shareCommunityChannelUrlWithChatKey*(self: AccessInterface, communityId:
method shareCommunityChannelUrlWithData*(self: AccessInterface, communityId: string, chatId: string): string {.base.} =
raise newException(ValueError, "No implementation available")
method onUserAuthenticated*(self: AccessInterface, pin: string, password: string, keyUid: string) {.base.} =
raise newException(ValueError, "No implementation available")
method requestToJoinCommunityWithAuthentication*(self: AccessInterface, communityId, ensName: string, addressesToShare: seq[string],
airdropAddress: string) {.base.} =
raise newException(ValueError, "No implementation available")
method editSharedAddressesWithAuthentication*(self: AccessInterface, communityId: string, addressesToShare: seq[string], airdropAddress: string)
{.base.} =
raise newException(ValueError, "No implementation available")
method authenticateWithCallback*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method callbackFromAuthentication*(self: AccessInterface, authenticated: bool) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -478,4 +478,25 @@ method shareCommunityChannelUrlWithChatKey*(self: Module, communityId: string, c
return self.controller.shareCommunityChannelUrlWithChatKey(communityId, chatId)
method shareCommunityChannelUrlWithData*(self: Module, communityId: string, chatId: string): string =
return self.controller.shareCommunityChannelUrlWithData(communityId, chatId)
return self.controller.shareCommunityChannelUrlWithData(communityId, chatId)
method onUserAuthenticated*(self: Module, pin: string, password: string, keyUid: string) =
if password == "" and pin == "":
self.view.userAuthenticationCanceled()
self.controller.userAuthenticationCanceled()
return
self.controller.userAuthenticated(password)
method requestToJoinCommunityWithAuthentication*(self: Module, communityId, ensName: string, addressesToShare: seq[string],
airdropAddress: string) =
self.controller.authenticateToRequestToJoinCommunity(communityId, ensName, addressesToShare, airdropAddress)
method editSharedAddressesWithAuthentication*(self: Module, communityId: string, addressesToShare: seq[string], airdropAddress: string) =
self.controller.authenticateToEditSharedAddresses(communityId, addressesToShare, airdropAddress)
method authenticateWithCallback*(self: Module) =
self.controller.authenticateWithCallback()
method callbackFromAuthentication*(self: Module, authenticated: bool) =
self.view.callbackFromAuthentication(authenticated)

View File

@ -615,3 +615,28 @@ QtObject:
proc shareCommunityChannelUrlWithData*(self: View, communityId: string, chatId: string): string {.slot.} =
return self.delegate.shareCommunityChannelUrlWithData(communityId, chatId)
proc userAuthenticationCanceled*(self: View) {.signal.}
proc authenticateWithCallback*(self: View) {.slot.} =
self.delegate.authenticateWithCallback()
proc callbackFromAuthentication*(self: View, authenticated: bool) {.signal.}
proc requestToJoinCommunityWithAuthentication*(self: View, communityId: string, ensName: string) {.slot.} =
self.delegate.requestToJoinCommunityWithAuthentication(communityId, ensName, @[], "")
proc requestToJoinCommunityWithAuthenticationWithSharedAddresses*(self: View, communityId: string, ensName: string,
addressesToShare: string, airdropAddress: string) {.slot.} =
try:
let addressesArray = map(parseJson(addressesToShare).getElems(), proc(x:JsonNode):string = x.getStr())
self.delegate.requestToJoinCommunityWithAuthentication(communityId, ensName, addressesArray, airdropAddress)
except Exception as e:
echo "Error requesting to join community with authentication and shared addresses: ", e.msg
proc editSharedAddressesWithAuthentication*(self: View, communityId: string, addressesToShare: string, airdropAddress: string) {.slot.} =
try:
let addressesArray = map(parseJson(addressesToShare).getElems(), proc(x:JsonNode):string = x.getStr())
self.delegate.editSharedAddressesWithAuthentication(communityId, addressesArray, airdropAddress)
except Exception as e:
echo "Error editing shared addresses with authentication: ", e.msg

View File

@ -176,7 +176,7 @@
<file>assets/img/icons/delete.svg</file>
<file>assets/img/icons/desktop.svg</file>
<file>assets/img/icons/discord.svg</file>
<file>assets/img/icons/dots-icon.svg</file>
<file>assets/img/icons/dots-icon.svg</file>
<file>assets/img/icons/double-checkmark.svg</file>
<file>assets/img/icons/download.svg</file>
<file>assets/img/icons/edit.svg</file>

View File

@ -187,7 +187,7 @@ StackLayout {
collectiblesModel: root.rootStore.collectiblesModel
onJoined: {
root.rootStore.requestToJoinCommunityWithAuthentication(root.rootStore.userProfileInst.name, sharedAddresses, airdropAddress)
root.rootStore.requestToJoinCommunityWithAuthentication(communityIntroDialog.communityId, root.rootStore.userProfileInst.name, sharedAddresses, airdropAddress)
}
onCancelMembershipRequest: {

View File

@ -380,8 +380,8 @@ QtObject {
return communitiesModuleInst.spectateCommunity(id, ensName)
}
function requestToJoinCommunityWithAuthentication(ensName, addressesToShare = [], airdropAddress = "") {
chatCommunitySectionModule.requestToJoinCommunityWithAuthenticationWithSharedAddresses(ensName, JSON.stringify(addressesToShare), airdropAddress)
function requestToJoinCommunityWithAuthentication(communityId, ensName, addressesToShare = [], airdropAddress = "") {
communitiesModuleInst.requestToJoinCommunityWithAuthenticationWithSharedAddresses(communityId, ensName, JSON.stringify(addressesToShare), airdropAddress)
}
function userCanJoin(id) {
@ -479,7 +479,7 @@ QtObject {
const userCanJoin = userCanJoin(result.communityData.communityId)
// TODO find what to do when you can't join
if (userCanJoin) {
requestToJoinCommunityWithAuthentication(userProfileInst.preferredName) // FIXME what addresses to share?
requestToJoinCommunityWithAuthentication(result.communityData.communityId, userProfileInst.preferredName) // FIXME what addresses to share?
}
}
return result
@ -619,7 +619,7 @@ QtObject {
function authenticateWithCallback(callback) {
_d.authenticationCallbacks.push(callback)
chatCommunitySectionModule.authenticateWithCallback()
communitiesModuleInst.authenticateWithCallback()
}
function removePrivateKey(communityId) {

View File

@ -125,7 +125,7 @@ StatusSectionLayout {
StatusButton {
id: importBtn
Layout.preferredHeight: 38
text: qsTr("Import using key")
text: qsTr("Import community")
verticalPadding: 0
onClicked: Global.importCommunityPopupRequested()
}

View File

@ -100,10 +100,47 @@ QtObject {
const publicKey = Utils.isCompressedPubKey(communityKey)
? Utils.changeCommunityKeyCompression(communityKey)
: communityKey
root.mainModuleInst.setCommunityIdToSpectate(publicKey)
if (importing)
root.mainModuleInst.setCommunityIdToSpectate(publicKey)
root.communitiesModuleInst.requestCommunityInfo(publicKey, importing)
}
property var communitiesList: communitiesModuleInst.model
function spectateCommunity(publicKey) {
root.communitiesModuleInst.spectateCommunity(publicKey, "");
}
function getCommunityDetails(communityId, importing = false) {
const publicKey = Utils.isCompressedPubKey(communityId)
? Utils.changeCommunityKeyCompression(communityId)
: communityId
try {
const communityJson = root.communitiesList.getSectionByIdJson(publicKey)
if (!communityJson) {
root.requestCommunityInfo(publicKey, importing)
return null
}
return JSON.parse(communityJson);
} catch (e) {
console.error("Error parsing community", e)
}
return null
}
function getCommunityDetailsAsJson(communityId) {
const jsonObj = root.communitiesModuleInst.getCommunityDetails(communityId)
try {
return JSON.parse(jsonObj)
}
catch (e) {
console.warn("error parsing community by id: ", communityId, " error: ", e.message)
return {}
}
}
function setActiveCommunity(communityId) {
root.mainModuleInst.setActiveSectionById(communityId);
}
@ -147,17 +184,6 @@ QtObject {
root.communitiesModuleInst.resetDiscordImport(false)
}
function getCommunityDetailsAsJson(id) {
const jsonObj = communitiesModuleInst.getCommunityDetails(id)
try {
return JSON.parse(jsonObj)
}
catch (e) {
console.warn("error parsing community by id: ", id, " error: ", e.message)
return {}
}
}
function requestImportDiscordCommunity(args = {
name: "",
description: "",

View File

@ -108,16 +108,12 @@ Item {
"")
}
}
}
Connections {
enabled: joinCommunityButton.loading
target: communitySectionModule
function onUserAuthenticationCanceled() {
joinCommunityButton.invitationPending = false
joinCommunityButton.loading = false
}
}
Component {
id: communityIntroDialog
CommunityIntroDialog {
@ -135,7 +131,7 @@ Item {
onJoined: {
joinCommunityButton.loading = true
root.store.requestToJoinCommunityWithAuthentication(root.store.userProfileInst.name, sharedAddresses, airdropAddress)
root.store.requestToJoinCommunityWithAuthentication(communityData.id, root.store.userProfileInst.name, sharedAddresses, airdropAddress)
}
onCancelMembershipRequest: {
root.store.cancelPendingRequest(communityData.id)

View File

@ -238,7 +238,7 @@ SettingsContentBase {
assetsModel: chatStore.assetsModel
collectiblesModel: chatStore.collectiblesModel
onJoined: chatStore.requestToJoinCommunityWithAuthentication(root.rootStore.userProfileInst.name, JSON.stringify(sharedAddresses), airdropAddress)
onJoined: chatStore.requestToJoinCommunityWithAuthentication(communityIntroDialog.communityId, root.rootStore.userProfileInst.name, JSON.stringify(sharedAddresses), airdropAddress)
onCancelMembershipRequest: root.rootStore.cancelPendingRequest(communityIntroDialog.communityId)
onClosed: destroy()

View File

@ -2,6 +2,9 @@ import QtQuick 2.13
import utils 1.0
import SortFilterProxyModel 0.2
import AppLayouts.Wallet.stores 1.0 as WalletStore
import AppLayouts.Chat.stores 1.0 as ChatStore
import "../Profile/stores"
QtObject {
@ -10,11 +13,46 @@ QtObject {
property var mainModuleInst: mainModule
property var aboutModuleInst: aboutModule
property var communitiesModuleInst: communitiesModule
property bool newVersionAvailable: false
property string latestVersion
property string downloadURL
readonly property int loginType: getLoginType()
function getLoginType() {
if(!userProfileInst)
return Constants.LoginType.Password
if(userProfileInst.usingBiometricLogin)
return Constants.LoginType.Biometrics
if(userProfileInst.isKeycardUser)
return Constants.LoginType.Keycard
return Constants.LoginType.Password
}
//TODO see how these values can be retrieved from the community the user attempts to join
property var permissionsModel: ChatStore.RootStore.permissionsStore.permissionsModel
property var walletAccountsModel: WalletStore.RootStore.receiveAccounts
property var assetsModel: SortFilterProxyModel {
sourceModel: communitiesModuleInst.tokenList
proxyRoles: ExpressionRole {
function tokenIcon(symbol) {
return Constants.tokenIcon(symbol)
}
name: "iconSource"
expression: !!model.icon ? model.icon : tokenIcon(model.symbol)
}
}
property var collectiblesModel: SortFilterProxyModel {
sourceModel: communitiesModuleInst.collectiblesModel
proxyRoles: ExpressionRole {
function collectibleIcon(icon) {
return !!icon ? icon : Style.png("tokens/DEFAULT-TOKEN")
}
name: "iconSource"
expression: collectibleIcon(model.icon)
}
}
function setLatestVersionInfo(newVersionAvailable, latestVersion, downloadURL) {
root.newVersionAvailable = newVersionAvailable;
root.latestVersion = latestVersion;
@ -164,4 +202,8 @@ QtObject {
function windowDeactivated() {
mainModuleInst.windowDeactivated()
}
function requestToJoinCommunityWithAuthentication(communityId, ensName, addressesToShare = [], airdropAddress = "") {
communitiesModuleInst.requestToJoinCommunityWithAuthenticationWithSharedAddresses(communityId, ensName, JSON.stringify(addressesToShare), airdropAddress)
}
}

View File

@ -50,6 +50,7 @@ QtObject {
Global.openCommunityProfilePopupRequested.connect(openCommunityProfilePopup)
Global.createCommunityPopupRequested.connect(openCreateCommunityPopup)
Global.importCommunityPopupRequested.connect(openImportCommunityPopup)
Global.communityIntroPopupRequested.connect(openCommunityIntroPopup)
Global.removeContactRequested.connect(openRemoveContactConfirmationPopup)
Global.openPopupRequested.connect(openPopup)
Global.closePopupRequested.connect(closePopup)
@ -226,6 +227,18 @@ QtObject {
openPopup(importCommunitiesPopupComponent)
}
function openCommunityIntroPopup(communityId, name, introMessage,
imageSrc, accessType, isInvitationPending) {
openPopup(communityIntroDialogPopup,
{communityId: communityId,
name: name,
introMessage: introMessage,
imageSrc: imageSrc,
accessType: accessType,
isInvitationPending: isInvitationPending
});
}
function openDiscordImportProgressPopup() {
openPopup(discordImportProgressDialog)
}
@ -486,9 +499,48 @@ QtObject {
id: importCommunitiesPopupComponent
ImportCommunityPopup {
store: root.communitiesStore
onClosed: {
destroy()
onJoinCommunity: {
Global.communityIntroPopupRequested(
communityId,
communityDetails.name,
communityDetails.introMessage,
communityDetails.image,
Constants.communityChatOnRequestAccess,
root.rootStore.isCommunityRequestPending(communityId));
close();
}
onClosed: {
destroy();
}
}
},
Component {
id: communityIntroDialogPopup
CommunityIntroDialog {
id: communityIntroDialog
property string communityId
loginType: root.rootStore.loginType
walletAccountsModel: root.rootStore.receiveAccounts
permissionsModel: root.rootStore.permissionsModel
assetsModel: root.rootStore.assetsModel
collectiblesModel: root.rootStore.collectiblesModel
onJoined: root.rootStore.requestToJoinCommunityWithAuthentication(communityIntroDialog.communityId, communityIntroDialog.name, JSON.stringify(sharedAddresses), airdropAddress)
onCancelMembershipRequest: root.rootStore.cancelPendingRequest(communityIntroDialog.communityId)
Connections {
target: root.communitiesStore.communitiesModuleInst
function onCommunityAccessRequested(communityId: string) {
root.communitiesStore.spectateCommunity(communityId);
communityIntroDialog.close();
}
function onCommunityAccessFailed(communityId: string) {
communityIntroDialog.close();
}
function onUserAuthenticationCanceled() {
communityIntroDialog.close();
}
}
onClosed: { destroy(); }
}
},

View File

@ -122,26 +122,24 @@ StatusStackModal {
stackItems: [
StatusScrollView {
id: scrollView
id: scrollView
contentWidth: availableWidth
ColumnLayout {
spacing: 24
width: scrollView.availableWidth
width: root.availableWidth
StatusRoundedImage {
id: roundImage
Layout.alignment: Qt.AlignCenter
Layout.preferredHeight: 64
Layout.preferredWidth: Layout.preferredHeight
visible: image.status == Image.Loading || image.status == Image.Ready
Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: 64
Layout.preferredHeight: Layout.preferredWidth
visible: ((image.status == Image.Loading) ||
(image.status == Image.Ready)) &&
!image.isError
image.source: root.imageSrc
}
StatusBaseText {
id: introText
Layout.fillWidth: true
text: root.introMessage || qsTr("Community <b>%1</b> has no intro message...").arg(root.name)
color: Theme.palette.directColor1

View File

@ -19,36 +19,42 @@ StatusDialog {
width: 640
title: qsTr("Import Community")
signal joinCommunity(string communityId, var communityDetails)
QtObject {
id: d
property string importErrorMessage
readonly property bool communityFound: (d.isPublicKey && !!d.communityDetails)
readonly property var communityDetails: {
return root.store.getCommunityDetails(Utils.getCompressedPk(publicKey));
}
readonly property string inputErrorMessage: isInputValid ? "" : qsTr("Invalid key")
readonly property string errorMessage: importErrorMessage || inputErrorMessage
readonly property string inputKey: keyInput.text.trim()
readonly property bool isPrivateKey: Utils.isPrivateKey(inputKey)
readonly property bool isPublicKey: publicKey !== ""
readonly property bool isPrivateKey: (Utils.isPrivateKey(inputKey))
readonly property bool isPublicKey: (publicKey !== "")
readonly property string publicKey: {
const key = Utils.dropCommunityLinkPrefix(inputKey)
if (!Utils.isCommunityPublicKey(key))
return ""
if (!Utils.isCompressedPubKey(key))
return key
return Utils.changeCommunityKeyCompression(key)
if (!Utils.isStatusDeepLink(inputKey)) {
const key = Utils.dropCommunityLinkPrefix(inputKey)
if (!Utils.isCommunityPublicKey(key))
return ""
if (!Utils.isCompressedPubKey(key))
return key
return Utils.changeCommunityKeyCompression(key)
} else {
return Utils.getCommunityDataFromSharedLink(inputKey).communityId;
}
}
readonly property bool isInputValid: isPrivateKey || isPublicKey
}
footer: StatusDialogFooter {
rightButtons: ObjectModel {
StatusFlatButton {
text: qsTr("Cancel")
onClicked: root.reject()
}
StatusButton {
id: importButton
enabled: d.isInputValid
text: d.isPrivateKey ? qsTr("Make this an Owner Node") : qsTr("Import")
loading: (d.isPublicKey && !d.communityFound)
text: d.isPrivateKey ? qsTr("Make this an Owner Node")
: qsTr("Import")
onClicked: {
if (d.isPrivateKey) {
const communityKey = d.inputKey
@ -57,11 +63,8 @@ StatusDialog {
}
root.store.importCommunity(communityKey);
root.close();
}
if (d.isPublicKey) {
importButton.loading = true
root.store.requestCommunityInfo(d.publicKey, true)
root.close();
} else if (d.communityFound) {
root.joinCommunity(d.publicKey, d.communityDetails);
}
}
}
@ -95,53 +98,39 @@ StatusDialog {
placeholderText: "0x0..."
wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere
onTextChanged: d.importErrorMessage = ""
}
StatusBaseText {
id: detectionLabel
}
RowLayout {
Layout.fillWidth: true
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
font.pixelSize: 13
visible: keyInput.text.trim() !== ""
text: {
if (d.errorMessage !== "") {
return d.errorMessage
}
if (d.isPrivateKey) {
return qsTr("Private key detected")
}
if (d.isPublicKey) {
return qsTr("Public key detected")
}
Layout.fillHeight: true
StatusChatInfoButton {
visible: (d.communityFound && d.isPublicKey)
title: !!d.communityDetails.name ? d.communityDetails.name : ""
subTitle: !!d.communityDetails.nbMembers ? qsTr("%n member(s)", "", d.communityDetails.nbMembers) : ""
asset.emoji: "1f918"
asset.emojiSize: "24x24"
asset.name: !!d.communityDetails.image ? d.communityDetails.image : ""
asset.isImage: (asset.name !== "")
asset.color: !!d.communityDetails.color ? d.communityDetails.color : ""
}
Item { Layout.fillWidth: true }
StatusBaseText {
id: detectionLabel
Layout.alignment: Qt.AlignRight
font.pixelSize: 13
visible: keyInput.text.trim() !== ""
text: {
if (d.errorMessage !== "") {
return d.errorMessage
}
if (d.isPrivateKey) {
return qsTr("Private key detected")
}
if (d.isPublicKey) {
return qsTr("Public key detected")
}
}
color: d.errorMessage === "" ? Theme.palette.successColor1 : Theme.palette.dangerColor1
}
color: d.errorMessage === "" ? Theme.palette.successColor1 : Theme.palette.dangerColor1
}
}
Connections {
target: root.store
function onImportingCommunityStateChanged(communityId, state, errorMsg) {
let communityKey = keyInput.text.trim();
if (d.isPublicKey) {
let currentCommunityKey = Utils.isCompressedPubKey(communityKey) ?
Utils.changeCommunityKeyCompression(communityKey) :
communityKey
if (communityId == currentCommunityKey) {
importButton.loading = false
if (state === Constants.communityImported && root.opened) {
root.close()
return
}
}
if (state === Constants.communityImportingError) {
d.importErrorMessage = errorMsg
importButton.loading = false
}
}
}
}
}

View File

@ -60,6 +60,8 @@ QtObject {
signal switchToCommunitySettings(string communityId)
signal createCommunityPopupRequested(bool isDiscordImport)
signal importCommunityPopupRequested()
signal communityIntroPopupRequested(string communityId, string name, string introMessage,
string imageSrc, int accessType, bool isInvitationPending)
signal leaveCommunityRequested(string community, string communityId, string outroMessage)
signal openEditSharedAddressesFlow(string communityId)