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(); + const modal = document.getElementById(modalId) as HTMLDialogElement; + if (modal) modal.close(); + }, + }); + } catch (error) { + console.error('Error leaving group:', error); + } finally { + setIsSigning(false); + } + }; + return (
@@ -112,16 +141,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} /> )}