-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(rwa): aliases for agents and investors (#2711)
- Loading branch information
1 parent
fb20311
commit f145180
Showing
29 changed files
with
761 additions
and
234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/apps/rwa-demo/src/app/(app)/agents/[agentAccount]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<> | ||
<SideBarBreadcrumbs> | ||
<SideBarBreadcrumbsItem href={`/agents/${agentAccount}`}> | ||
Agent | ||
</SideBarBreadcrumbsItem> | ||
</SideBarBreadcrumbs> | ||
|
||
<Stack width="100%" flexDirection="column"> | ||
<AgentInfo account={agent} /> | ||
<Stack gap="sm"> | ||
<AgentForm | ||
agent={agent} | ||
trigger={ | ||
<Button isDisabled={paused} endVisual={<MonoEditNote />}> | ||
Edit Agent | ||
</Button> | ||
} | ||
/> | ||
</Stack> | ||
</Stack> | ||
</> | ||
); | ||
}; | ||
|
||
export default InvestorPage; |
51 changes: 0 additions & 51 deletions
51
packages/apps/rwa-demo/src/components/AddAgentForm/AddAgentForm.tsx
This file was deleted.
Oops, something went wrong.
51 changes: 0 additions & 51 deletions
51
packages/apps/rwa-demo/src/components/AddInvestorForm/AddInvestorForm.tsx
This file was deleted.
Oops, something went wrong.
95 changes: 95 additions & 0 deletions
95
packages/apps/rwa-demo/src/components/AgentForm/AgentForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IProps> = ({ onClose, agent, trigger }) => { | ||
const { submit } = useAddAgent(); | ||
const [isOpen, setIsOpen] = useState(false); | ||
const { setIsRightAsideExpanded, isRightAsideExpanded } = useLayout(); | ||
const { handleSubmit, control } = useForm<IAddAgentProps>({ | ||
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 && ( | ||
<RightAside | ||
isOpen={isRightAsideExpanded && isOpen} | ||
onClose={handleOnClose} | ||
> | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<RightAsideHeader label="Add Agent" /> | ||
<RightAsideContent> | ||
<Controller | ||
name="accountName" | ||
control={control} | ||
render={({ field }) => ( | ||
<TextField | ||
isDisabled={!!agent?.accountName} | ||
label="AccountName" | ||
{...field} | ||
/> | ||
)} | ||
/> | ||
|
||
<Controller | ||
name="alias" | ||
control={control} | ||
render={({ field }) => <TextField label="Alias" {...field} />} | ||
/> | ||
</RightAsideContent> | ||
<RightAsideFooter> | ||
<Button onPress={handleOnClose} variant="transparent"> | ||
Cancel | ||
</Button> | ||
<Button type="submit">Add Agent</Button> | ||
</RightAsideFooter> | ||
</form> | ||
</RightAside> | ||
)} | ||
|
||
{cloneElement(trigger, { ...trigger.props, onPress: handleOpen })} | ||
</> | ||
); | ||
}; |
28 changes: 28 additions & 0 deletions
28
packages/apps/rwa-demo/src/components/AgentInfo/AgentInfo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IProps> = ({ account }) => { | ||
const accountName = getAccountName(account); | ||
|
||
if (!account) return null; | ||
|
||
return ( | ||
<Stack width="100%" flexDirection="column"> | ||
<Heading as="h3"> | ||
agent: {account.alias ? account.alias : accountName} | ||
</Heading> | ||
</Stack> | ||
); | ||
}; |
Oops, something went wrong.