Skip to content

Commit

Permalink
feat(rwa): partial freeze (#2708)
Browse files Browse the repository at this point in the history
  • Loading branch information
sstraatemans authored Dec 4, 2024
1 parent 7dc5c60 commit 293eb82
Show file tree
Hide file tree
Showing 21 changed files with 498 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .changeset/perfect-rings-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { DistributionForm } from '@/components/DistributionForm/DistributionForm';
import { FreezeInvestor } from '@/components/FreezeInvestor/FreezeInvestor';
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';
Expand All @@ -17,13 +18,19 @@ const InvestorPage = () => {
const { paused } = useAsset();
const params = useParams();
const [hasOpenDistributeForm, setHasOpenDistributeForm] = useState(false);
const [hasOpenPartiallyFreezeForm, setHasOpenPartiallyFreezeForm] =
useState(false);
const investorAccount = decodeURIComponent(params.investorAccount as string);
const { frozen } = useFreeze({ investorAccount });

const handleDistributeTokens = () => {
setIsRightAsideExpanded(true);
setHasOpenDistributeForm(true);
};
const handlePartiallyFreezeTokens = () => {
setIsRightAsideExpanded(true);
setHasOpenPartiallyFreezeForm(true);
};

return (
<>
Expand All @@ -42,6 +49,15 @@ const InvestorPage = () => {
}}
/>
)}
{isRightAsideExpanded && hasOpenPartiallyFreezeForm && (
<PartiallyFreezeTokensForm
investorAccount={investorAccount}
onClose={() => {
setIsRightAsideExpanded(false);
setHasOpenPartiallyFreezeForm(false);
}}
/>
)}

<Stack width="100%" flexDirection="column">
<InvestorInfo investorAccount={investorAccount} />
Expand All @@ -53,6 +69,15 @@ const InvestorPage = () => {
>
Distribute Tokens
</Button>

<Button
startVisual={<MonoAdd />}
onPress={handlePartiallyFreezeTokens}
isDisabled={frozen || paused}
>
Partially freeze tokens
</Button>

<FreezeInvestor investorAccount={investorAccount} />
</Stack>
</Stack>
Expand Down
4 changes: 3 additions & 1 deletion packages/apps/rwa-demo/src/app/(app)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
'use client';

import { AgentRootPage } from '@/components/HomePage/AgentRootPage';
import { ComplianceOwnerRootPage } from '@/components/HomePage/ComplianceOwnerRootPage';
import { InvestorRootPage } from '@/components/HomePage/InvestorRootPage';
import { OwnerRootPage } from '@/components/HomePage/OwnerRootPage';
import { useAccount } from '@/hooks/account';

const Home = () => {
const { isAgent, isInvestor, isOwner } = useAccount();
const { isAgent, isInvestor, isOwner, isComplianceOwner } = useAccount();

return (
<>
{isComplianceOwner && <ComplianceOwnerRootPage />}
{isOwner && <OwnerRootPage />}
{isAgent && <AgentRootPage />}
{isInvestor && <InvestorRootPage />}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';
import { getBalance as getBalanceFnc } from '@/services/getBalance';
import { isAgent } from '@/services/isAgent';
import { isComplianceOwner } from '@/services/isComplianceOwner';
import { isFrozen } from '@/services/isFrozen';
import { isInvestor } from '@/services/isInvestor';
import { isOwner } from '@/services/isOwner';
Expand All @@ -26,6 +27,7 @@ export interface IAccountContext {
sign: (tx: IUnsignedCommand) => Promise<ICommand | undefined>;
isAgent: boolean;
isOwner: boolean;
isComplianceOwner: boolean;
isInvestor: boolean;
isFrozen: boolean;
selectAccount: (account: IWalletAccount) => void;
Expand All @@ -41,6 +43,7 @@ export const AccountContext = createContext<IAccountContext>({
sign: async () => undefined,
isAgent: false,
isOwner: false,
isComplianceOwner: false,
isInvestor: false,
isFrozen: false,
selectAccount: () => {},
Expand All @@ -52,6 +55,7 @@ export const AccountProvider: FC<PropsWithChildren> = ({ children }) => {
const [accounts, setAccounts] = useState<IWalletAccount[]>();
const [isMounted, setIsMounted] = useState(false);
const [isOwnerState, setIsOwnerState] = useState(false);
const [isComplianceOwnerState, setIsComplianceOwnerState] = useState(false);
const [isAgentState, setIsAgentState] = useState(false);
const [isInvestorState, setIsInvestorState] = useState(false);
const [isFrozenState, setIsFrozenState] = useState(false);
Expand All @@ -66,6 +70,12 @@ export const AccountProvider: FC<PropsWithChildren> = ({ children }) => {
const resIsOwner = await isOwner({ owner: account.address });
setIsOwnerState(!!resIsOwner);
};
const checkIsComplianceOwner = async (account: IWalletAccount) => {
const resIsComplianceOwner = await isComplianceOwner({
owner: account.address,
});
setIsComplianceOwnerState(!!resIsComplianceOwner);
};
const checkIsInvestor = async (account: IWalletAccount) => {
const resIsInvestor = await isInvestor({ account });
setIsInvestorState(!!resIsInvestor);
Expand Down Expand Up @@ -141,13 +151,16 @@ export const AccountProvider: FC<PropsWithChildren> = ({ children }) => {
if (!account) {
setIsAgentState(false);
setIsOwnerState(false);
setIsComplianceOwnerState(false);
setIsInvestorState(false);
return;
}

// eslint-disable-next-line @typescript-eslint/no-floating-promises
checkIsOwner(account);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
checkIsComplianceOwner(account);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
checkIsAgent(account);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
checkIsInvestor(account);
Expand Down Expand Up @@ -188,6 +201,7 @@ export const AccountProvider: FC<PropsWithChildren> = ({ children }) => {
sign,
isMounted,
isOwner: isOwnerState,
isComplianceOwner: isComplianceOwnerState,
isAgent: isAgentState,
isInvestor: isInvestorState,
isFrozen: isFrozenState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const DistributionForm: FC<IProps> = ({ onClose, investorAccount }) => {
useEffect(() => {
if (tx && resolveRef.current) {
resolveRef.current(tx);
onClose();
}
}, [tx]);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
'use client';
import { SetMaxBalanceForm } from '@/components/SetMaxBalanceForm/SetMaxBalanceForm';
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 { useState } from 'react';
import { SetMaxSupplyForm } from '../SetMaxSupplyForm/SetMaxSupplyForm';

export const ComplianceOwnerRootPage = () => {
const { isComplianceOwner } = useAccount();
const { setIsRightAsideExpanded, isRightAsideExpanded } = useLayout();
const { paused } = useAsset();
const [hasOpenMaxBalanceForm, setHasOpenMaxBalanceForm] = useState(false);
const [hasOpenMaxSupplyForm, setHasOpenMaxSupplyForm] = useState(false);

const handleMaxBalanceForm = () => {
setIsRightAsideExpanded(true);
setHasOpenMaxBalanceForm(true);
};
const handleMaxSupplyForm = () => {
setIsRightAsideExpanded(true);
setHasOpenMaxSupplyForm(true);
};

return (
<Stack width="100%" flexDirection="column" gap="md">
<SideBarBreadcrumbs />

{isRightAsideExpanded && hasOpenMaxBalanceForm && (
<SetMaxBalanceForm
onClose={() => {
setIsRightAsideExpanded(false);
setHasOpenMaxBalanceForm(false);
}}
/>
)}
{isRightAsideExpanded && hasOpenMaxSupplyForm && (
<SetMaxSupplyForm
onClose={() => {
setIsRightAsideExpanded(false);
setHasOpenMaxSupplyForm(false);
}}
/>
)}

<Stack gap="sm">
{isComplianceOwner && (
<>
<Button
isDisabled={paused}
startVisual={<MonoAdd />}
onClick={handleMaxBalanceForm}
>
Set Max Balance
</Button>
<Button
isDisabled={paused}
startVisual={<MonoAdd />}
onClick={handleMaxSupplyForm}
>
Set Max Supply
</Button>
</>
)}
</Stack>
</Stack>
);
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useAccount } from '@/hooks/account';
import { useFreeze } from '@/hooks/freeze';
import { MonoCompareArrows } from '@kadena/kode-icons';
import { Button, Stack } from '@kadena/kode-ui';
import { useLayout } from '@kadena/kode-ui/patterns';
Expand All @@ -8,7 +9,8 @@ import { InvestorInfo } from '../InvestorInfo/InvestorInfo';
import { TransferForm } from '../TransferForm/TransferForm';

export const InvestorRootPage: FC = () => {
const { isInvestor, account, isFrozen } = useAccount();
const { isInvestor, account } = useAccount();
const { frozen } = useFreeze({ investorAccount: account?.address! });
const { setIsRightAsideExpanded, isRightAsideExpanded } = useLayout();
const [hasOpenTransferForm, setHasOpenTransferForm] = useState(false);

Expand Down Expand Up @@ -37,7 +39,7 @@ export const InvestorRootPage: FC = () => {
<Button
startVisual={<MonoCompareArrows />}
onPress={handleTransferTokens}
isDisabled={isFrozen}
isDisabled={frozen}
>
Transfer tokens
</Button>
Expand Down
35 changes: 1 addition & 34 deletions packages/apps/rwa-demo/src/components/HomePage/OwnerRootPage.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,13 @@
'use client';
import { AgentsList } from '@/components/AgentsList/AgentsList';
import { SetComplianceForm } from '@/components/SetComplianceForm/SetComplianceForm';
import { SideBarBreadcrumbs } from '@/components/SideBarBreadcrumbs/SideBarBreadcrumbs';
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 { useState } from 'react';
import { Stack } from '@kadena/kode-ui';

export const OwnerRootPage = () => {
const { setIsRightAsideExpanded, isRightAsideExpanded } = useLayout();
const { paused } = useAsset();
const [hasOpenComplianceForm, setHasOpenComplianceForm] = useState(false);

const handleComplianceForm = () => {
setIsRightAsideExpanded(true);
setHasOpenComplianceForm(true);
};

return (
<Stack width="100%" flexDirection="column" gap="md">
<SideBarBreadcrumbs />

{isRightAsideExpanded && hasOpenComplianceForm && (
<SetComplianceForm
onClose={() => {
setIsRightAsideExpanded(false);
setHasOpenComplianceForm(false);
}}
/>
)}

<Stack gap="sm">
<Button
isDisabled={paused}
startVisual={<MonoAdd />}
onClick={handleComplianceForm}
>
Set Compliance
</Button>
</Stack>

<AgentsList />
</Stack>
);
Expand Down
Loading

0 comments on commit 293eb82

Please sign in to comment.