feat(shared_addresses): get old shared addresses for the edit popup
Fixes #11973
This commit is contained in:
parent
7ae28ec386
commit
bc4a150afa
|
@ -34,6 +34,7 @@ type
|
|||
chatService: chat_service.Service
|
||||
tmpCommunityId: string
|
||||
tmpCommunityIdForChannelsPermisisons: string
|
||||
tmpCommunityIdForRevealedAccounts: string
|
||||
tmpAuthenticationAction: AuthenticationAction
|
||||
tmpRequestToJoinEnsName: string
|
||||
tmpAddressesToShare: seq[string]
|
||||
|
@ -61,6 +62,7 @@ proc newController*(
|
|||
result.chatService = chatService
|
||||
result.tmpCommunityId = ""
|
||||
result.tmpCommunityIdForChannelsPermisisons = ""
|
||||
result.tmpCommunityIdForRevealedAccounts = ""
|
||||
result.tmpRequestToJoinEnsName = ""
|
||||
result.tmpAirdropAddress = ""
|
||||
result.tmpAddressesToShare = @[]
|
||||
|
@ -179,6 +181,16 @@ proc init*(self: Controller) =
|
|||
)
|
||||
self.tmpCommunityIdForChannelsPermisisons = ""
|
||||
|
||||
self.events.on(SIGNAL_COMMUNITY_MEMBER_REVEALED_ACCOUNTS_LOADED) do(e: Args):
|
||||
let args = CommunityMemberRevealedAccountsArgs(e)
|
||||
if self.tmpCommunityIdForRevealedAccounts == args.communityId:
|
||||
self.delegate.onCommunityMemberRevealedAccountsLoaded(
|
||||
args.communityId,
|
||||
args.memberPubkey,
|
||||
args.memberRevealedAccounts,
|
||||
)
|
||||
self.tmpCommunityIdForRevealedAccounts = ""
|
||||
|
||||
self.events.on(SignalType.Wallet.event, proc(e: Args) =
|
||||
var data = WalletSignal(e)
|
||||
if data.eventType == backend_collectibles.eventCollectiblesOwnershipUpdateFinished:
|
||||
|
@ -432,3 +444,7 @@ proc asyncCheckPermissionsToJoin*(self: Controller, communityId: string, address
|
|||
proc asyncCheckAllChannelsPermissions*(self: Controller, communityId: string, sharedAddresses: seq[string]) =
|
||||
self.tmpCommunityIdForChannelsPermisisons = communityId
|
||||
self.chatService.asyncCheckAllChannelsPermissions(communityId, sharedAddresses)
|
||||
|
||||
proc asyncGetRevealedAccountsForMember*(self: Controller, communityId, memberPubkey: string) =
|
||||
self.tmpCommunityIdForRevealedAccounts = communityId
|
||||
self.communityService.asyncGetRevealedAccountsForMember(communityId, memberPubkey)
|
||||
|
|
|
@ -223,3 +223,7 @@ method onCommunityCheckPermissionsToJoinFailed*(self: AccessInterface, community
|
|||
|
||||
method onCommunityCheckAllChannelPermissionsFailed*(self: AccessInterface, communityId: string, ValueErrorerror: string) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method onCommunityMemberRevealedAccountsLoaded*(self: AccessInterface, communityId: string, memberPubkey: string,
|
||||
revealedAccounts: seq[RevealedAccount]) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import NimQml, sequtils, tables, stint, chronicles
|
||||
import NimQml, sequtils, tables, stint, chronicles, json
|
||||
|
||||
import ./io_interface
|
||||
import ../io_interface as delegate_interface
|
||||
|
@ -548,6 +548,8 @@ method checkPermissions*(self: Module, communityId: string, sharedAddresses: seq
|
|||
self.view.setCheckingPermissionsInProgress(inProgress = true)
|
||||
|
||||
method prepareTokenModelForCommunity*(self: Module, communityId: string) =
|
||||
self.controller.asyncGetRevealedAccountsForMember(communityId, singletonInstance.userProfile.getPubKey())
|
||||
|
||||
let community = self.controller.getCommunityById(communityId)
|
||||
var tokenPermissionsItems: seq[TokenPermissionItem] = @[]
|
||||
|
||||
|
@ -635,3 +637,15 @@ method onCommunityCheckAllChannelsPermissionsResponse*(self: Module, communityId
|
|||
communityId,
|
||||
channelPermissionResponse.viewAndPostPermissions.permissions,
|
||||
)
|
||||
|
||||
method onCommunityMemberRevealedAccountsLoaded*(self: Module, communityId, memberPubkey: string,
|
||||
revealedAccounts: seq[RevealedAccount]) =
|
||||
if memberPubkey == singletonInstance.userProfile.getPubKey():
|
||||
var addresses: seq[string] = @[]
|
||||
var airdropAddress = ""
|
||||
for revealedAccount in revealedAccounts:
|
||||
addresses.add(revealedAccount.address)
|
||||
if revealedAccount.isAirdropAddress:
|
||||
airdropAddress = revealedAccount.address
|
||||
|
||||
self.view.setMyRevealedAddressesForCurrentCommunity($(%*addresses), airdropAddress)
|
||||
|
|
|
@ -51,6 +51,8 @@ QtObject:
|
|||
discordImportHasCommunityImage: bool
|
||||
downloadingCommunityHistoryArchives: bool
|
||||
checkingPermissionsInProgress: bool
|
||||
myRevealedAddressesStringForCurrentCommunity: string
|
||||
myRevealedAirdropAddressForCurrentCommunity: string
|
||||
|
||||
proc delete*(self: View) =
|
||||
self.model.delete
|
||||
|
@ -671,6 +673,28 @@ QtObject:
|
|||
proc getCommunityPublicKeyFromPrivateKey*(self: View, communityPrivateKey: string): string {.slot.} =
|
||||
result = self.delegate.getCommunityPublicKeyFromPrivateKey(communityPrivateKey)
|
||||
|
||||
proc myRevealedAirdropAddressesForCurrentCommunityChanged*(self: View) {.signal.}
|
||||
|
||||
proc setMyRevealedAddressesForCurrentCommunity*(self: View, revealedAddress, airdropAddress: string) =
|
||||
self.myRevealedAddressesStringForCurrentCommunity = revealedAddress
|
||||
self.myRevealedAirdropAddressForCurrentCommunity = airdropAddress
|
||||
self.myRevealedAirdropAddressesForCurrentCommunityChanged()
|
||||
|
||||
proc getMyRevealedAddressesStringForCurrentCommunity*(self: View): string {.slot.} =
|
||||
return self.myRevealedAddressesStringForCurrentCommunity
|
||||
|
||||
QtProperty[string] myRevealedAddressesStringForCurrentCommunity:
|
||||
read = getMyRevealedAddressesStringForCurrentCommunity
|
||||
notify = myRevealedAirdropAddressesForCurrentCommunityChanged
|
||||
|
||||
|
||||
proc getMyRevealedAirdropAddressStringForCurrentCommunity*(self: View): string {.slot.} =
|
||||
return self.myRevealedAirdropAddressForCurrentCommunity
|
||||
|
||||
QtProperty[string] myRevealedAirdropAddressForCurrentCommunity:
|
||||
read = getMyRevealedAirdropAddressStringForCurrentCommunity
|
||||
notify = myRevealedAirdropAddressesForCurrentCommunityChanged
|
||||
|
||||
proc checkingPermissionsInProgressChanged*(self: View) {.signal.}
|
||||
|
||||
proc setCheckingPermissionsInProgress*(self: View, inProgress: bool) =
|
||||
|
|
|
@ -188,11 +188,29 @@ const asyncImportCommunityTask: Task = proc(argEncoded: string) {.gcsafe, nimcal
|
|||
})
|
||||
|
||||
type
|
||||
AsyncGetRevealedAccountsForAllMembersArg = ref object of QObjectTaskArg
|
||||
AsyncGetRevealedAccountsArg = ref object of QObjectTaskArg
|
||||
communityId: string
|
||||
memberPubkey: string
|
||||
|
||||
const asyncGetRevealedAccountsForMemberTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
||||
let arg = decode[AsyncGetRevealedAccountsArg](argEncoded)
|
||||
try:
|
||||
let response = status_go.getRevealedAccountsForMember(arg.communityId, arg.memberPubkey)
|
||||
arg.finish(%* {
|
||||
"communityId": arg.communityId,
|
||||
"memberPubkey": arg.memberPubkey,
|
||||
"response": response,
|
||||
"error": "",
|
||||
})
|
||||
except Exception as e:
|
||||
arg.finish(%* {
|
||||
"communityId": arg.communityId,
|
||||
"memberPubkey": arg.memberPubkey,
|
||||
"error": e.msg,
|
||||
})
|
||||
|
||||
const asyncGetRevealedAccountsForAllMembersTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
||||
let arg = decode[AsyncGetRevealedAccountsForAllMembersArg](argEncoded)
|
||||
let arg = decode[AsyncGetRevealedAccountsArg](argEncoded)
|
||||
try:
|
||||
let response = status_go.getRevealedAccountsForAllMembers(arg.communityId)
|
||||
arg.finish(%* {
|
||||
|
|
|
@ -129,6 +129,11 @@ type
|
|||
communityId*: string
|
||||
metricsType*: CommunityMetricsType
|
||||
|
||||
CommunityMemberRevealedAccountsArgs* = ref object of Args
|
||||
communityId*: string
|
||||
memberPubkey*: string
|
||||
memberRevealedAccounts*: seq[RevealedAccount]
|
||||
|
||||
CommunityMembersRevealedAccountsArgs* = ref object of Args
|
||||
communityId*: string
|
||||
membersRevealedAccounts*: MembersRevealedAccounts
|
||||
|
@ -141,6 +146,7 @@ const SIGNAL_COMMUNITY_MY_REQUEST_ADDED* = "communityMyRequestAdded"
|
|||
const SIGNAL_COMMUNITY_MY_REQUEST_FAILED* = "communityMyRequestFailed"
|
||||
const SIGNAL_COMMUNITY_EDIT_SHARED_ADDRESSES_SUCCEEDED* = "communityEditSharedAddressesSucceded"
|
||||
const SIGNAL_COMMUNITY_EDIT_SHARED_ADDRESSES_FAILED* = "communityEditSharedAddressesFailed"
|
||||
const SIGNAL_COMMUNITY_MEMBER_REVEALED_ACCOUNTS_LOADED* = "communityMemberRevealedAccountsLoaded"
|
||||
const SIGNAL_COMMUNITY_MEMBERS_REVEALED_ACCOUNTS_LOADED* = "communityMembersRevealedAccountsLoaded"
|
||||
const SIGNAL_COMMUNITY_LEFT* = "communityLeft"
|
||||
const SIGNAL_COMMUNITY_CREATED* = "communityCreated"
|
||||
|
@ -2052,8 +2058,39 @@ QtObject:
|
|||
except Exception as e:
|
||||
error "error while getting community public key", msg = e.msg
|
||||
|
||||
proc asyncGetRevealedAccountsForMember*(self: Service, communityId, memberPubkey: string) =
|
||||
let arg = AsyncGetRevealedAccountsArg(
|
||||
tptr: cast[ByteAddress](asyncGetRevealedAccountsForMemberTask),
|
||||
vptr: cast[ByteAddress](self.vptr),
|
||||
slot: "onAsyncGetRevealedAccountsForMemberCompleted",
|
||||
communityId: communityId,
|
||||
memberPubkey: memberPubkey,
|
||||
)
|
||||
self.threadpool.start(arg)
|
||||
|
||||
proc onAsyncGetRevealedAccountsForMemberCompleted*(self: Service, response: string) {.slot.} =
|
||||
try:
|
||||
let rpcResponseObj = response.parseJson
|
||||
|
||||
if rpcResponseObj{"error"}.kind != JNull and rpcResponseObj{"error"}.getStr != "":
|
||||
raise newException(RpcException, rpcResponseObj["error"].getStr)
|
||||
|
||||
if rpcResponseObj["response"]{"error"}.kind != JNull:
|
||||
let error = Json.decode(rpcResponseObj["response"]["error"].getStr, RpcError)
|
||||
raise newException(RpcException, error.message)
|
||||
|
||||
let revealedAccounts = rpcResponseObj["response"]["result"].toRevealedAccounts()
|
||||
|
||||
self.events.emit(SIGNAL_COMMUNITY_MEMBER_REVEALED_ACCOUNTS_LOADED, CommunityMemberRevealedAccountsArgs(
|
||||
communityId: rpcResponseObj["communityId"].getStr,
|
||||
memberPubkey: rpcResponseObj["memberPubkey"].getStr,
|
||||
memberRevealedAccounts: revealedAccounts,
|
||||
))
|
||||
except Exception as e:
|
||||
error "error while getting the community members' revealed addressesses", msg = e.msg
|
||||
|
||||
proc asyncGetRevealedAccountsForAllMembers*(self: Service, communityId: string) =
|
||||
let arg = AsyncGetRevealedAccountsForAllMembersArg(
|
||||
let arg = AsyncGetRevealedAccountsArg(
|
||||
tptr: cast[ByteAddress](asyncGetRevealedAccountsForAllMembersTask),
|
||||
vptr: cast[ByteAddress](self.vptr),
|
||||
slot: "onAsyncGetRevealedAccountsForAllMembersCompleted",
|
||||
|
@ -2082,7 +2119,7 @@ QtObject:
|
|||
error "error while getting the community members' revealed addressesses", msg = e.msg
|
||||
|
||||
proc asyncReevaluateCommunityMembersPermissions*(self: Service, communityId: string) =
|
||||
let arg = AsyncGetRevealedAccountsForAllMembersArg(
|
||||
let arg = AsyncGetRevealedAccountsArg(
|
||||
tptr: cast[ByteAddress](asyncReevaluateCommunityMembersPermissionsTask),
|
||||
vptr: cast[ByteAddress](self.vptr),
|
||||
slot: "onAsyncReevaluateCommunityMembersPermissionsCompleted",
|
||||
|
|
|
@ -49,6 +49,9 @@ StatusListView {
|
|||
|
||||
spacing: Style.current.halfPadding
|
||||
delegate: StatusListItem {
|
||||
readonly property string address: model.address.toLowerCase()
|
||||
|
||||
id: listItem
|
||||
width: ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin
|
||||
statusListItemTitle.font.weight: Font.Medium
|
||||
title: model.name
|
||||
|
@ -102,11 +105,11 @@ StatusListView {
|
|||
icon.color: hovered ? Theme.palette.primaryColor3 :
|
||||
checked ? Theme.palette.primaryColor1 : disabledTextColor
|
||||
checkable: true
|
||||
checked: model.address === root.selectedAirdropAddress
|
||||
checked: listItem.address === root.selectedAirdropAddress
|
||||
enabled: shareAddressCheckbox.checked && root.selectedSharedAddresses.length > 1 // last cannot be unchecked
|
||||
visible: shareAddressCheckbox.checked
|
||||
opacity: enabled ? 1.0 : 0.3
|
||||
onCheckedChanged: if (checked) root.selectedAirdropAddress = model.address
|
||||
onCheckedChanged: if (checked) root.selectedAirdropAddress = listItem.address
|
||||
onToggled: root.addressesChanged()
|
||||
|
||||
StatusToolTip {
|
||||
|
@ -120,21 +123,21 @@ StatusListView {
|
|||
ButtonGroup.group: d.addressesGroup
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
checkable: true
|
||||
checked: root.selectedSharedAddresses.includes(model.address)
|
||||
checked: root.selectedSharedAddresses.includes(listItem.address)
|
||||
enabled: !(root.selectedSharedAddresses.length === 1 && checked) // last cannot be unchecked
|
||||
onToggled: {
|
||||
// handle selected addresses
|
||||
const index = root.selectedSharedAddresses.indexOf(model.address)
|
||||
const index = root.selectedSharedAddresses.indexOf(listItem.address)
|
||||
const selectedSharedAddressesCopy = Object.assign([], root.selectedSharedAddresses) // deep copy
|
||||
if (index === -1) {
|
||||
selectedSharedAddressesCopy.push(model.address)
|
||||
selectedSharedAddressesCopy.push(listItem.address)
|
||||
} else {
|
||||
selectedSharedAddressesCopy.splice(index, 1)
|
||||
}
|
||||
root.selectedSharedAddresses = selectedSharedAddressesCopy
|
||||
|
||||
// switch to next available airdrop address when unchecking
|
||||
if (!checked && model.address === root.selectedAirdropAddress) {
|
||||
if (!checked && listItem.address === root.selectedAirdropAddress) {
|
||||
d.selectFirstAvailableAirdropAddress()
|
||||
}
|
||||
|
||||
|
|
|
@ -116,6 +116,15 @@ Control {
|
|||
root.selectedAirdropAddress = accountSelector.selectedAirdropAddress
|
||||
}
|
||||
|
||||
function setOldSharedAddresses(oldSharedAddresses) {
|
||||
d.initialSelectedSharedAddresses = oldSharedAddresses
|
||||
}
|
||||
|
||||
function setOldAirdropAddress(oldAirdropAddress) {
|
||||
d.initialSelectedAirdropAddress = oldAirdropAddress
|
||||
accountSelector.selectedAirdropAddress = oldAirdropAddress
|
||||
}
|
||||
|
||||
SortFilterProxyModel {
|
||||
id: filteredAccountsModel
|
||||
sourceModel: root.walletAccountsModel
|
||||
|
|
|
@ -29,6 +29,14 @@ StatusDialog {
|
|||
signal saveSelectedAddressesClicked(string airdropAddress, var sharedAddresses)
|
||||
signal sharedAddressesChanged(string airdropAddress, var sharedAddresses)
|
||||
|
||||
function setOldSharedAddresses(oldSharedAddresses) {
|
||||
panel.setOldSharedAddresses(oldSharedAddresses)
|
||||
}
|
||||
|
||||
function setOldAirdropAddress(oldAirdropAddress) {
|
||||
panel.setOldAirdropAddress(oldAirdropAddress)
|
||||
}
|
||||
|
||||
title: panel.title
|
||||
implicitWidth: 640 // by design
|
||||
padding: 0
|
||||
|
|
|
@ -43,6 +43,20 @@ QtObject {
|
|||
|
||||
readonly property var permissionsModel: !!root.communitiesModuleInst.spectatedCommunityPermissionModel ?
|
||||
root.communitiesModuleInst.spectatedCommunityPermissionModel : null
|
||||
|
||||
readonly property var myRevealedAddressesForCurrentCommunity: {
|
||||
try {
|
||||
let revealedAddresses = root.communitiesModuleInst.myRevealedAddressesStringForCurrentCommunity
|
||||
let revealedAddressArray = JSON.parse(revealedAddresses)
|
||||
return revealedAddressArray.map(addr => addr.toLowerCase())
|
||||
} catch (e) {
|
||||
console.error("Error parsing my revealed addresses", e)
|
||||
}
|
||||
return []
|
||||
}
|
||||
readonly property string myRevealedAirdropAddressForCurrentCommunity:
|
||||
root.communitiesModuleInst.myRevealedAirdropAddressForCurrentCommunity.toLowerCase()
|
||||
|
||||
property var walletAccountsModel: WalletStore.RootStore.nonWatchAccounts
|
||||
property var assetsModel: SortFilterProxyModel {
|
||||
sourceModel: communitiesModuleInst.tokenList
|
||||
|
|
|
@ -697,6 +697,21 @@ QtObject {
|
|||
SharedAddressesPopup {
|
||||
id: editSharedAddressesPopup
|
||||
|
||||
readonly property var oldSharedAddresses: root.rootStore.myRevealedAddressesForCurrentCommunity
|
||||
readonly property string oldAirdropAddress: root.rootStore.myRevealedAirdropAddressForCurrentCommunity
|
||||
|
||||
onOldSharedAddressesChanged: {
|
||||
editSharedAddressesPopup.setOldSharedAddresses(
|
||||
editSharedAddressesPopup.oldSharedAddresses
|
||||
)
|
||||
}
|
||||
|
||||
onOldAirdropAddressChanged: {
|
||||
editSharedAddressesPopup.setOldAirdropAddress(
|
||||
editSharedAddressesPopup.oldAirdropAddress
|
||||
)
|
||||
}
|
||||
|
||||
property string communityId
|
||||
|
||||
readonly property var chatStore: ChatStore.RootStore {
|
||||
|
@ -710,9 +725,6 @@ QtObject {
|
|||
communityName: chatStore.sectionDetails.name
|
||||
communityIcon: chatStore.sectionDetails.image
|
||||
requirementsCheckPending: root.rootStore.requirementsCheckPending
|
||||
// FIXME get these from the community settings (from the initial "join" call)
|
||||
//selectedSharedAddresses: [???]
|
||||
//selectedAirdropAddress: "???"
|
||||
loginType: chatStore.loginType
|
||||
walletAccountsModel: root.rootStore.walletAccountsModel
|
||||
permissionsModel: {
|
||||
|
|
Loading…
Reference in New Issue