From 66e1d4aaca0c9331b638071f5cc9684207f6d675 Mon Sep 17 00:00:00 2001 From: Joseph Chalabi Date: Tue, 26 Nov 2024 16:09:31 -0700 Subject: [PATCH 1/3] feat: allow user to leave a group --- components/groups/components/myGroups.tsx | 35 ++----------- components/groups/modals/groupInfo.tsx | 64 ++++++++++++++++++----- pages/groups/index.tsx | 6 ++- 3 files changed, 58 insertions(+), 47 deletions(-) diff --git a/components/groups/components/myGroups.tsx b/components/groups/components/myGroups.tsx index cc356609..93cd7a3c 100644 --- a/components/groups/components/myGroups.tsx +++ b/components/groups/components/myGroups.tsx @@ -18,17 +18,17 @@ import { PiInfo } from 'react-icons/pi'; import { GroupInfo } from '../modals/groupInfo'; import { MemberManagementModal } from '../modals/memberManagementModal'; import { useChain } from '@cosmos-kit/react'; -import { useGroupsByMember } from '@/hooks/useQueries'; -import { MemberSDKType } from '@liftedinit/manifestjs/dist/codegen/cosmos/group/v1/types'; export function YourGroups({ groups, proposals, isLoading, + refetch, }: { groups: ExtendedQueryGroupsByMemberResponseSDKType; proposals: { [policyAddress: string]: ProposalSDKType[] }; isLoading: boolean; + refetch: () => void; }) { const [searchTerm, setSearchTerm] = useState(''); const [selectedGroup, setSelectedGroup] = useState<{ @@ -36,13 +36,9 @@ export function YourGroups({ name: string; threshold: string; } | null>(null); - const [members, setMembers] = useState([]); - const [groupId, setGroupId] = useState(''); - const [groupAdmin, setGroupAdmin] = useState(''); const router = useRouter(); const { address } = useChain('manifest'); - const { groupByMemberData } = useGroupsByMember(address ?? ''); const filteredGroups = groups.groups.filter(group => (group.ipfsMetadata?.title || 'Untitled Group').toLowerCase().includes(searchTerm.toLowerCase()) @@ -74,31 +70,6 @@ export function YourGroups({ } }, [selectedGroup]); - useEffect(() => { - if (groupByMemberData && selectedGroup?.policyAddress) { - const group = groupByMemberData?.groups?.find( - g => g?.policies?.length > 0 && g.policies[0]?.address === selectedGroup.policyAddress - ); - if (group) { - setMembers( - group.members.map(member => ({ - ...member.member, - address: member?.member?.address || '', - weight: member?.member?.weight || '0', - metadata: member?.member?.metadata || '', - added_at: member?.member?.added_at || new Date(), - isCoreMember: true, - isActive: true, - isAdmin: member?.member?.address === group.admin, - isPolicyAdmin: member?.member?.address === group.policies[0]?.admin, - })) - ); - setGroupId(group.id.toString()); - setGroupAdmin(group.admin); - } - } - }, [groupByMemberData, selectedGroup?.policyAddress]); - const handleSelectGroup = (policyAddress: string, groupName: string, threshold: string) => { setSelectedGroup({ policyAddress, name: groupName || 'Untitled Group', threshold }); router.push(`/groups?policyAddress=${policyAddress}`, undefined, { shallow: true }); @@ -253,7 +224,7 @@ export function YourGroups({ group={group} address={address ?? ''} policyAddress={group.policies[0]?.address ?? ''} - onUpdate={() => {}} + onUpdate={refetch} /> ; } + const handleLeave = async () => { + setIsSigning(true); + + try { + const msg = leaveGroup({ + address: address, + groupId: group?.id, + }); + + const fee = await estimateFee(address, [msg]); + await tx([msg], { + fee, + onSuccess: () => { + setIsSigning(false); + onUpdate(); + }, + }); + } catch (error) { + console.error('Error submitting proposal:', error); + } finally { + setIsSigning(false); + } + }; + return (
@@ -112,16 +139,27 @@ export function GroupInfo({ modalId, group, policyAddress, address, onUpdate }:
Info - +
+ + + +
diff --git a/pages/groups/index.tsx b/pages/groups/index.tsx index 76f1a429..a19d6e2e 100644 --- a/pages/groups/index.tsx +++ b/pages/groups/index.tsx @@ -19,7 +19,7 @@ export default function Groups() { const groupPolicyAddresses = groupByMemberData?.groups?.map(group => group.policies[0].address) ?? []; - const { proposalsByPolicyAccount, isProposalsError, isProposalsLoading } = + const { proposalsByPolicyAccount, isProposalsError, isProposalsLoading, refetchProposals } = useProposalsByPolicyAccountAll(groupPolicyAddresses ?? []); const isLoading = isGroupByMemberLoading || isProposalsLoading; @@ -82,6 +82,7 @@ export default function Groups() { groups={groupByMemberData ?? { groups: [] }} proposals={proposalsByPolicyAccount} isLoading={isLoading} + refetch={refetchGroupByMember} /> ) : isError ? (
Error loading groups or proposals
@@ -93,6 +94,7 @@ export default function Groups() { groups={groupByMemberData ?? { groups: [] }} proposals={proposalsByPolicyAccount} isLoading={isLoading} + refetch={refetchGroupByMember} /> {selectedPolicyAddress && ( {}} + onUpdate={refetchGroupByMember} /> )} From e66971ffc683391f8c45fae9df7683c6a594f43c Mon Sep 17 00:00:00 2001 From: "Felix C. Morency" <1102868+fmorency@users.noreply.github.com> Date: Wed, 27 Nov 2024 09:29:55 -0500 Subject: [PATCH 2/3] fix: duplicate aria-label --- components/groups/modals/groupInfo.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/groups/modals/groupInfo.tsx b/components/groups/modals/groupInfo.tsx index b1488072..97c3a8f4 100644 --- a/components/groups/modals/groupInfo.tsx +++ b/components/groups/modals/groupInfo.tsx @@ -141,7 +141,7 @@ export function GroupInfo({ modalId, group, policyAddress, address, onUpdate }: Info