From bef52f1f62d9f7b37eedab05a54751a28d2a988d Mon Sep 17 00:00:00 2001 From: audsssy Date: Mon, 20 Feb 2023 12:47:04 -0500 Subject: [PATCH] add delegate components & logic still need to resolve ENS names, which is a new function in #308 that we can recycle --- components/dao-dashboard/members/Delegate.tsx | 91 +++++++++++++++++++ .../dao-dashboard/members/MemberProfile.tsx | 79 ++++++++-------- pages/daos/[chainId]/[dao]/members.tsx | 10 +- 3 files changed, 141 insertions(+), 39 deletions(-) create mode 100644 components/dao-dashboard/members/Delegate.tsx diff --git a/components/dao-dashboard/members/Delegate.tsx b/components/dao-dashboard/members/Delegate.tsx new file mode 100644 index 00000000..45c414ce --- /dev/null +++ b/components/dao-dashboard/members/Delegate.tsx @@ -0,0 +1,91 @@ +import { Stack, Button, Box, Text } from '@kalidao/reality' +import { Select } from '@design/Select' +import getExplorerLink, { ExplorerType } from '@utils/getExplorerLink' +import { useRouter } from 'next/router' +import { truncateAddress } from '@utils/truncateAddress' +import { useContract, useSigner, useAccount, useContractRead } from 'wagmi' +import KALIDAO_ABI from '@abi/KaliDAO.json' +import { useState } from 'react' + +export default function Delegate({ members }: any) { + const router = useRouter() + const daoAddress = router.query.dao as string + const { chainId } = router.query + const { data: signer } = useSigner() + const { address } = useAccount() + + const { data: currentDelegatee } = useContractRead({ + address: daoAddress as `0xstring`, + abi: KALIDAO_ABI, + functionName: 'delegates', + args: [address], + chainId: Number(chainId), + }) + + const kalidao = useContract({ + address: daoAddress as `0xstring`, + abi: KALIDAO_ABI, + signerOrProvider: signer, + }) + + const [delegatee, setDelegatee] = useState('') + const [status, setStatus] = useState('Delegate') + + const handleDelegation = async () => { + setStatus('Delegating...') + console.log(delegatee) + try { + const tx = await kalidao?.delegate(delegatee) + console.log(tx) + setStatus('Submitted!') + } catch (e) { + console.log(e) + } + } + + let daoMembers = [] + daoMembers.push({ + value: 'select', + label: 'Select', + }) + for (let i = 0; i < members.length; i++) { + daoMembers.push({ + value: members[i].address, + label: members[i].address, + }) + } + + return ( + + + + + + Current Delegate:{' '} + {currentDelegatee ? ( + + {truncateAddress(currentDelegatee as string)} + + ) : ( + 'None' + )} + + +