diff --git a/components/dao-dashboard/layout/Profile.tsx b/components/dao-dashboard/layout/Profile.tsx index d3e7fd47..2499a008 100644 --- a/components/dao-dashboard/layout/Profile.tsx +++ b/components/dao-dashboard/layout/Profile.tsx @@ -21,6 +21,7 @@ import { getDaoInfo } from '@graph/queries' import { DashboardElementProps } from './types' import Link from 'next/link' import { useGetDaoMeta } from '@components/hooks/useGetDaoMeta' +import Tribute from '../newproposal/apps/Tribute' const Profile = ({ address, chainId }: DashboardElementProps) => { const router = useRouter() @@ -41,7 +42,6 @@ const Profile = ({ address, chainId }: DashboardElementProps) => { ) - console.log('meta', meta) return ( { {meta?.description} - + {meta?.socials?.twitter && ( @@ -81,6 +81,7 @@ const Profile = ({ address, chainId }: DashboardElementProps) => { )} + )} diff --git a/components/dao-dashboard/layout/Treasury.tsx b/components/dao-dashboard/layout/Treasury.tsx index 9ad7464b..e6a57bb4 100644 --- a/components/dao-dashboard/layout/Treasury.tsx +++ b/components/dao-dashboard/layout/Treasury.tsx @@ -79,13 +79,15 @@ const Treasury = ({ address, chainId }: DashboardElementProps) => { ))} - - - - - {lastUpdated} + + + + + + {lastUpdated} + diff --git a/components/dao-dashboard/layout/index.tsx b/components/dao-dashboard/layout/index.tsx index 894e9778..48462a01 100644 --- a/components/dao-dashboard/layout/index.tsx +++ b/components/dao-dashboard/layout/index.tsx @@ -8,6 +8,8 @@ import Profile from '@components/dao-dashboard/layout/Profile' import Treasury from '@components/dao-dashboard/layout/Treasury' import Header from '@components/layout/Header' import Nav from '@components/dao-dashboard/layout/Nav' +import { useEffect } from 'react' +import { useDaoStore } from '../useDaoStore' type Props = { title: string @@ -19,6 +21,13 @@ const DashboardLayout = ({ title, content, children }: Props) => { const router = useRouter() const { chainId, dao } = router.query const heading = `Kali | ${title}` + const setDAO = useDaoStore((state) => state.setDao) + + useEffect(() => { + if (chainId && dao) { + setDAO(dao as string, Number(chainId)) + } + }, [chainId, dao, setDAO]) return ( diff --git a/components/dao-dashboard/newproposal/apps/Tribute.tsx b/components/dao-dashboard/newproposal/apps/Tribute.tsx new file mode 100644 index 00000000..7811f069 --- /dev/null +++ b/components/dao-dashboard/newproposal/apps/Tribute.tsx @@ -0,0 +1,94 @@ +import { Button, Stack, IconSparkles, Input, IconBookOpen } from '@kalidao/reality' +import { Dialog } from '@design/Dialog' +import { useDaoStore } from '@components/dao-dashboard/useDaoStore' +import { useAccount, useContractRead, useContractWrite, usePrepareContractWrite } from 'wagmi' +import { addresses } from '@constants/addresses' +import TRIBUTE_ABI from '@abi/KaliDAOtribute.json' +import { useState } from 'react' +import { JSONContent } from '@tiptap/react' +import { ethers } from 'ethers' +import Editor from '@components/editor' +import ChainGuard from '@components/dao-dashboard/ChainGuard' + +export default function Tribute() { + const name = useDaoStore((state) => state.name) + const symbol = useDaoStore((state) => state.symbol) + const daoAddress = useDaoStore((state) => state.address) + const chainId = useDaoStore((state) => state.chainId) + const abi = useDaoStore((state) => state.abi) + const tributeAddress = addresses[chainId].extensions.tribute + const { + data: status, + isLoading: isLoadingStatus, + isError: isStatusError, + } = useContractRead({ + addressOrName: daoAddress, + contractInterface: abi, + chainId: chainId, + functionName: 'extensions', + args: [tributeAddress], + }) + const { address, isConnected } = useAccount() + const [description, setDescription] = useState() + const [amount, setAmount] = useState('0') + const [value, setValue] = useState('0') + + const { config } = usePrepareContractWrite({ + addressOrName: tributeAddress, + contractInterface: TRIBUTE_ABI, + functionName: 'submitTributeProposal', + chainId: chainId, + args: [ + daoAddress, + 0, + description, + [address], + [amount ? ethers.utils.parseEther(amount) : ethers.utils.parseEther('0')], + [ethers.constants.HashZero], + false, // nft + ethers.constants.AddressZero, + ethers.utils.parseEther('0'), + ], + overrides: { + value: value ? ethers.utils.parseEther(value) : ethers.utils.parseEther('0'), + }, + }) + const { write, isSuccess } = useContractWrite(config) + + if (isLoadingStatus || isStatusError || Boolean(status) === false) return null + + return ( + }> + Tribute + + } + > + + + setValue(e.target.value)} /> + setAmount(e.target.value)} + /> + }> + Give + + } + > + + + + + ) +} diff --git a/components/dao-dashboard/timeline/index.tsx b/components/dao-dashboard/timeline/index.tsx index 35a507fe..b7ef019b 100644 --- a/components/dao-dashboard/timeline/index.tsx +++ b/components/dao-dashboard/timeline/index.tsx @@ -15,25 +15,19 @@ import Card from './Card' import { useRouter } from 'next/router' import { ethers } from 'ethers' import { useGetProposals } from '@graph/queries/getProposals' -import { useContractRead } from 'wagmi' -import DAO_ABI from '@abi/KaliDAO.json' +import { useDaoStore } from '../useDaoStore' export default function Timeline() { const router = useRouter() - const { dao, chainId } = router.query - const { data: name } = useContractRead({ - addressOrName: dao ? (dao as string) : ethers.constants.AddressZero, - contractInterface: DAO_ABI, - functionName: 'name', - chainId: Number(chainId), - }) + const dao = useDaoStore((state) => state.address) + const chainId = useDaoStore((state) => state.chainId) + const name = useDaoStore((state) => state.name) + const { data, isLoading, error } = useGetProposals( chainId ? Number(chainId) : 1, dao ? (dao as string) : ethers.constants.AddressZero, ) - console.log('proposals', data) - const [show, setShow] = useState(2) // filtering out cancelled proposals @@ -64,7 +58,7 @@ export default function Timeline() { pathname: '/daos/[chainId]/[dao]/propose', query: { dao: dao as string, - chainId: chainId as string, + chainId: chainId.toString(), }, }} passHref diff --git a/components/dao-dashboard/useDaoStore.ts b/components/dao-dashboard/useDaoStore.ts new file mode 100644 index 00000000..299910d3 --- /dev/null +++ b/components/dao-dashboard/useDaoStore.ts @@ -0,0 +1,31 @@ +import create from 'zustand' +import DAO_ABI from '@abi/KaliDAO.json' +import { getProvider } from '@utils/getProvider' +import { ethers } from 'ethers' + +interface DaoStore { + address: string + name: string + symbol: string + decimals: number + chainId: number + abi: any + setDao: (address: string, chainId: number) => void +} + +export const useDaoStore = create((set) => ({ + address: '', + name: '', + symbol: '', + decimals: 18, + chainId: 1, + abi: DAO_ABI, + setDao: async (address: string, chainId: number) => { + const provider = getProvider(chainId) + const contract = new ethers.Contract(address, DAO_ABI, provider) + const name = await contract.name() + const symbol = await contract.symbol() + + set({ address, chainId, name, symbol }) + }, +}))