diff --git a/.changeset/slow-apples-think.md b/.changeset/slow-apples-think.md new file mode 100644 index 0000000000..a845151cc8 --- /dev/null +++ b/.changeset/slow-apples-think.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/apps/rwa-demo/src/app/(app)/(isAgent)/investors/[investorAccount]/page.tsx b/packages/apps/rwa-demo/src/app/(app)/(isAgent)/investors/[investorAccount]/page.tsx index 4ee4228475..1fdc77e149 100644 --- a/packages/apps/rwa-demo/src/app/(app)/(isAgent)/investors/[investorAccount]/page.tsx +++ b/packages/apps/rwa-demo/src/app/(app)/(isAgent)/investors/[investorAccount]/page.tsx @@ -2,12 +2,14 @@ import { DistributionForm } from '@/components/DistributionForm/DistributionForm'; import { FreezeInvestor } from '@/components/FreezeInvestor/FreezeInvestor'; +import { InvestorForm } from '@/components/InvestorForm/InvestorForm'; import { InvestorInfo } from '@/components/InvestorInfo/InvestorInfo'; import { PartiallyFreezeTokensForm } from '@/components/PartiallyFreezeTokensForm/PartiallyFreezeTokensForm'; import { SideBarBreadcrumbs } from '@/components/SideBarBreadcrumbs/SideBarBreadcrumbs'; import { useAsset } from '@/hooks/asset'; import { useFreeze } from '@/hooks/freeze'; -import { MonoAdd } from '@kadena/kode-icons'; +import { useGetInvestor } from '@/hooks/getInvestor'; +import { MonoAdd, MonoEditNote } from '@kadena/kode-icons'; import { Button, Stack } from '@kadena/kode-ui'; import { SideBarBreadcrumbsItem, useLayout } from '@kadena/kode-ui/patterns'; import { useParams } from 'next/navigation'; @@ -21,6 +23,8 @@ const InvestorPage = () => { const [hasOpenPartiallyFreezeForm, setHasOpenPartiallyFreezeForm] = useState(false); const investorAccount = decodeURIComponent(params.investorAccount as string); + + const { data: investor } = useGetInvestor({ account: investorAccount }); const { frozen } = useFreeze({ investorAccount }); const handleDistributeTokens = () => { @@ -32,6 +36,8 @@ const InvestorPage = () => { setHasOpenPartiallyFreezeForm(true); }; + if (!investor) return null; + return ( <> @@ -60,7 +66,7 @@ const InvestorPage = () => { )} - + + + } + > + Edit Investor + + } + /> diff --git a/packages/apps/rwa-demo/src/app/(app)/agents/[agentAccount]/page.tsx b/packages/apps/rwa-demo/src/app/(app)/agents/[agentAccount]/page.tsx new file mode 100644 index 0000000000..be3eb39525 --- /dev/null +++ b/packages/apps/rwa-demo/src/app/(app)/agents/[agentAccount]/page.tsx @@ -0,0 +1,47 @@ +'use client'; + +import { AgentForm } from '@/components/AgentForm/AgentForm'; +import { AgentInfo } from '@/components/AgentInfo/AgentInfo'; +import { SideBarBreadcrumbs } from '@/components/SideBarBreadcrumbs/SideBarBreadcrumbs'; +import { useAsset } from '@/hooks/asset'; +import { useGetAgent } from '@/hooks/getAgent'; +import { MonoEditNote } from '@kadena/kode-icons'; +import { Button, Stack } from '@kadena/kode-ui'; +import { SideBarBreadcrumbsItem } from '@kadena/kode-ui/patterns'; +import { useParams } from 'next/navigation'; + +const InvestorPage = () => { + const { paused } = useAsset(); + const params = useParams(); + const agentAccount = decodeURIComponent(params.agentAccount as string); + + const { data: agent } = useGetAgent({ account: agentAccount }); + + if (!agent) return null; + + return ( + <> + + + Agent + + + + + + + }> + Edit Agent + + } + /> + + + + ); +}; + +export default InvestorPage; diff --git a/packages/apps/rwa-demo/src/components/AddAgentForm/AddAgentForm.tsx b/packages/apps/rwa-demo/src/components/AddAgentForm/AddAgentForm.tsx deleted file mode 100644 index 2d97413af6..0000000000 --- a/packages/apps/rwa-demo/src/components/AddAgentForm/AddAgentForm.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import { useAddAgent } from '@/hooks/addAgent'; -import type { IAddAgentProps } from '@/services/addAgent'; -import { Button, TextField } from '@kadena/kode-ui'; -import { - RightAside, - RightAsideContent, - RightAsideFooter, - RightAsideHeader, -} from '@kadena/kode-ui/patterns'; -import type { FC } from 'react'; -import { useForm } from 'react-hook-form'; - -interface IProps { - onClose: () => void; -} - -export const AddAgentForm: FC = ({ onClose }) => { - const { submit } = useAddAgent(); - const { register, handleSubmit } = useForm({ - defaultValues: { - accountName: '', - }, - }); - - const onSubmit = async (data: IAddAgentProps) => { - await submit(data); - onClose(); - }; - - return ( - <> - -
- - - - - - - - - -
- - ); -}; diff --git a/packages/apps/rwa-demo/src/components/AddInvestorForm/AddInvestorForm.tsx b/packages/apps/rwa-demo/src/components/AddInvestorForm/AddInvestorForm.tsx deleted file mode 100644 index 7f52a865cb..0000000000 --- a/packages/apps/rwa-demo/src/components/AddInvestorForm/AddInvestorForm.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import { useAddInvestor } from '@/hooks/addInvestor'; -import type { IRegisterIdentityProps } from '@/services/registerIdentity'; -import { Button, TextField } from '@kadena/kode-ui'; -import { - RightAside, - RightAsideContent, - RightAsideFooter, - RightAsideHeader, -} from '@kadena/kode-ui/patterns'; -import type { FC } from 'react'; -import { useForm } from 'react-hook-form'; - -interface IProps { - onClose: () => void; -} - -export const AddInvestorForm: FC = ({ onClose }) => { - const { submit } = useAddInvestor(); - const { register, handleSubmit } = useForm({ - defaultValues: { - accountName: '', - }, - }); - - const onSubmit = async (data: IRegisterIdentityProps) => { - await submit(data); - onClose(); - }; - - return ( - <> - -
- - - - - - - - - -
- - ); -}; diff --git a/packages/apps/rwa-demo/src/components/AgentForm/AgentForm.tsx b/packages/apps/rwa-demo/src/components/AgentForm/AgentForm.tsx new file mode 100644 index 0000000000..8819a6a34c --- /dev/null +++ b/packages/apps/rwa-demo/src/components/AgentForm/AgentForm.tsx @@ -0,0 +1,95 @@ +import { useAddAgent } from '@/hooks/addAgent'; +import type { IAddAgentProps } from '@/services/addAgent'; +import type { IRecord } from '@/utils/filterRemovedRecords'; +import { Button, TextField } from '@kadena/kode-ui'; +import { + RightAside, + RightAsideContent, + RightAsideFooter, + RightAsideHeader, + useLayout, +} from '@kadena/kode-ui/patterns'; +import type { FC, ReactElement } from 'react'; +import { cloneElement, useEffect, useState } from 'react'; +import { Controller, useForm } from 'react-hook-form'; + +interface IProps { + agent?: IRecord; + onClose?: () => void; + trigger: ReactElement; +} + +export const AgentForm: FC = ({ onClose, agent, trigger }) => { + const { submit } = useAddAgent(); + const [isOpen, setIsOpen] = useState(false); + const { setIsRightAsideExpanded, isRightAsideExpanded } = useLayout(); + const { handleSubmit, control } = useForm({ + defaultValues: { + accountName: agent?.accountName ?? '', + alias: agent?.alias ?? '', + alreadyExists: !!agent?.accountName, + }, + }); + + const handleOpen = () => { + setIsRightAsideExpanded(true); + setIsOpen(true); + if (trigger.props.onPress) trigger.props.onPress(); + }; + + const handleOnClose = () => { + setIsOpen(false); + if (onClose) onClose(); + }; + + const onSubmit = async (data: IAddAgentProps) => { + await submit(data); + handleOnClose(); + }; + + useEffect(() => { + console.log('agent', isOpen); + }, [isOpen]); + + return ( + <> + {isRightAsideExpanded && isOpen && ( + +
+ + + ( + + )} + /> + + } + /> + + + + + + +
+ )} + + {cloneElement(trigger, { ...trigger.props, onPress: handleOpen })} + + ); +}; diff --git a/packages/apps/rwa-demo/src/components/AgentInfo/AgentInfo.tsx b/packages/apps/rwa-demo/src/components/AgentInfo/AgentInfo.tsx new file mode 100644 index 0000000000..cc3052083f --- /dev/null +++ b/packages/apps/rwa-demo/src/components/AgentInfo/AgentInfo.tsx @@ -0,0 +1,28 @@ +import type { IRecord } from '@/utils/filterRemovedRecords'; +import { Heading, Stack } from '@kadena/kode-ui'; +import type { FC } from 'react'; +import React from 'react'; +import type { IWalletAccount } from '../AccountProvider/utils'; + +interface IProps { + account: IRecord | IWalletAccount; +} + +const getAccountName = (account: IProps['account']) => { + if ('accountName' in account) return account.accountName; + return account.address; +}; + +export const AgentInfo: FC = ({ account }) => { + const accountName = getAccountName(account); + + if (!account) return null; + + return ( + + + agent: {account.alias ? account.alias : accountName} + + + ); +}; diff --git a/packages/apps/rwa-demo/src/components/AgentsList/AgentsList.tsx b/packages/apps/rwa-demo/src/components/AgentsList/AgentsList.tsx index 065d2a99f1..5d526e5221 100644 --- a/packages/apps/rwa-demo/src/components/AgentsList/AgentsList.tsx +++ b/packages/apps/rwa-demo/src/components/AgentsList/AgentsList.tsx @@ -1,7 +1,11 @@ import { useAsset } from '@/hooks/asset'; import { useGetAgents } from '@/hooks/getAgents'; import { useRemoveAgent } from '@/hooks/removeAgent'; -import { MonoDelete, MonoSupportAgent } from '@kadena/kode-icons'; +import { + MonoDelete, + MonoFindInPage, + MonoSupportAgent, +} from '@kadena/kode-icons'; import { Button } from '@kadena/kode-ui'; import { CompactTable, @@ -10,75 +14,92 @@ import { SectionCardBody, SectionCardContentBlock, SectionCardHeader, - useLayout, } from '@kadena/kode-ui/patterns'; +import { useRouter } from 'next/navigation'; import type { FC } from 'react'; -import { useState } from 'react'; -import { AddAgentForm } from '../AddAgentForm/AddAgentForm'; +import { AgentForm } from '../AgentForm/AgentForm'; import { Confirmation } from '../Confirmation/Confirmation'; export const AgentsList: FC = () => { - const { setIsRightAsideExpanded, isRightAsideExpanded } = useLayout(); const { paused } = useAsset(); const { data } = useGetAgents(); const { submit } = useRemoveAgent(); - const [hasOpenAgentForm, setHasOpenAgentForm] = useState(false); - - const handleAddAgent = () => { - setIsRightAsideExpanded(true); - setHasOpenAgentForm(true); - }; + const router = useRouter(); const handleDelete = async (accountName: any) => { await submit({ agent: accountName }); }; + const handleLink = async (accountName: any) => { + router.push(`/agents/${accountName}`); + }; + return ( <> - {isRightAsideExpanded && hasOpenAgentForm && ( - { - setIsRightAsideExpanded(false); - setHasOpenAgentForm(false); - }} - /> - )} All the agents for this contract} actions={ - + } + variant="outlined" + > + Add Agent + + } + /> } /> } + onPress={handleLink} + /> + ), + }), }, - { label: 'Account', key: 'accountName', width: '50%' }, - { label: 'Requestkey', key: 'requestKey', width: '30%' }, { label: '', key: 'accountName', - width: '10%', + width: '7%', render: CompactTableFormatters.FormatActions({ trigger: ( } />} + trigger={ + } > diff --git a/packages/apps/rwa-demo/src/components/HomePage/AgentRootPage.tsx b/packages/apps/rwa-demo/src/components/HomePage/AgentRootPage.tsx index 4174a36ed8..9d3017dc15 100644 --- a/packages/apps/rwa-demo/src/components/HomePage/AgentRootPage.tsx +++ b/packages/apps/rwa-demo/src/components/HomePage/AgentRootPage.tsx @@ -1,25 +1,12 @@ import { SideBarBreadcrumbs } from '@/components/SideBarBreadcrumbs/SideBarBreadcrumbs'; import { useAccount } from '@/hooks/account'; -import { useAsset } from '@/hooks/asset'; -import { MonoAdd } from '@kadena/kode-icons'; -import { Button, Stack } from '@kadena/kode-ui'; -import { useLayout } from '@kadena/kode-ui/patterns'; +import { Stack } from '@kadena/kode-ui'; import type { FC } from 'react'; -import { useState } from 'react'; -import { AddInvestorForm } from '../AddInvestorForm/AddInvestorForm'; import { InvestorList } from '../InvestorList/InvestorList'; import { PauseForm } from '../PauseForm/PauseForm'; export const AgentRootPage: FC = () => { const { isAgent, account } = useAccount(); - const { paused } = useAsset(); - const { setIsRightAsideExpanded, isRightAsideExpanded } = useLayout(); - const [hasOpenInvestorForm, setHasOpenInvestorForm] = useState(false); - - const handleAddInvestor = () => { - setIsRightAsideExpanded(true); - setHasOpenInvestorForm(true); - }; if (!isAgent) return null; @@ -27,23 +14,8 @@ export const AgentRootPage: FC = () => { agent: {account?.address} - {isRightAsideExpanded && hasOpenInvestorForm && ( - { - setIsRightAsideExpanded(false); - setHasOpenInvestorForm(false); - }} - /> - )} - diff --git a/packages/apps/rwa-demo/src/components/HomePage/InvestorRootPage.tsx b/packages/apps/rwa-demo/src/components/HomePage/InvestorRootPage.tsx index 3db2e5f741..f2203318fa 100644 --- a/packages/apps/rwa-demo/src/components/HomePage/InvestorRootPage.tsx +++ b/packages/apps/rwa-demo/src/components/HomePage/InvestorRootPage.tsx @@ -33,7 +33,7 @@ export const InvestorRootPage: FC = () => { )} - + + + + + + )} + + {cloneElement(trigger, { ...trigger.props, onPress: handleOpen })} + + ); +}; diff --git a/packages/apps/rwa-demo/src/components/InvestorInfo/InvestorInfo.tsx b/packages/apps/rwa-demo/src/components/InvestorInfo/InvestorInfo.tsx index 57cc0467c7..c856ef4868 100644 --- a/packages/apps/rwa-demo/src/components/InvestorInfo/InvestorInfo.tsx +++ b/packages/apps/rwa-demo/src/components/InvestorInfo/InvestorInfo.tsx @@ -1,20 +1,32 @@ import { useFreeze } from '@/hooks/freeze'; +import type { IRecord } from '@/utils/filterRemovedRecords'; import { MonoPause, MonoPlayArrow } from '@kadena/kode-icons'; import { Button, Heading, Stack } from '@kadena/kode-ui'; import type { FC } from 'react'; import React from 'react'; +import type { IWalletAccount } from '../AccountProvider/utils'; import { InvestorBalance } from '../InvestorBalance/InvestorBalance'; interface IProps { - investorAccount: string; + account: IRecord | IWalletAccount; } -export const InvestorInfo: FC = ({ investorAccount }) => { - const { frozen } = useFreeze({ investorAccount }); +const getAccountName = (account: IProps['account']) => { + if ('accountName' in account) return account.accountName; + return account.address; +}; + +export const InvestorInfo: FC = ({ account }) => { + const accountName = getAccountName(account); + const { frozen } = useFreeze({ investorAccount: accountName }); + + if (!account) return null; return ( - investor: {investorAccount} + + investor: {account.alias ? account.alias : accountName} + - + ); diff --git a/packages/apps/rwa-demo/src/components/InvestorList/InvestorList.tsx b/packages/apps/rwa-demo/src/components/InvestorList/InvestorList.tsx index 19e375dba5..4039daa642 100644 --- a/packages/apps/rwa-demo/src/components/InvestorList/InvestorList.tsx +++ b/packages/apps/rwa-demo/src/components/InvestorList/InvestorList.tsx @@ -1,53 +1,112 @@ +import { useAsset } from '@/hooks/asset'; import { useDeleteInvestor } from '@/hooks/deleteInvestor'; import { useGetInvestors } from '@/hooks/getInvestors'; -import { MonoDelete } from '@kadena/kode-icons'; -import { Button, Heading } from '@kadena/kode-ui'; -import { CompactTable, CompactTableFormatters } from '@kadena/kode-ui/patterns'; -import Link from 'next/link'; +import { MonoAdd, MonoDelete, MonoFindInPage } from '@kadena/kode-icons'; +import { Button } from '@kadena/kode-ui'; +import { + CompactTable, + CompactTableFormatters, + SectionCard, + SectionCardBody, + SectionCardContentBlock, + SectionCardHeader, +} from '@kadena/kode-ui/patterns'; +import { useRouter } from 'next/navigation'; import type { FC } from 'react'; +import { InvestorForm } from '../InvestorForm/InvestorForm'; +import { FormatFreeze } from '../TableFormatters/FormatFreeze'; export const InvestorList: FC = () => { const { data } = useGetInvestors(); + const router = useRouter(); const { submit } = useDeleteInvestor(); + const { paused } = useAsset(); const handleDelete = async (accountName: any) => { return await submit({ investor: accountName }); }; + const handleLink = async (accountName: any) => { + router.push(`/investors/${accountName}`); + }; return ( <> - Investors - } onPress={handleDelete} /> - ), - }), - }, - ]} - data={data} - /> + + + } + > + Add Investor + + } + /> + } + /> + + + } + onPress={handleLink} + /> + ), + }), + }, + { + label: '', + key: 'accountName', + width: '7%', + render: CompactTableFormatters.FormatActions({ + trigger: ( +