Skip to content

Commit

Permalink
feat(rwa): createtoken (#2662)
Browse files Browse the repository at this point in the history
  • Loading branch information
sstraatemans authored Nov 15, 2024
1 parent 4da520c commit 83bd571
Show file tree
Hide file tree
Showing 31 changed files with 952 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ export const SideBarBreadcrumbs: FC<IBreadcrumbsProps> = ({
const { activeNetwork } = useWallet();

return (
<SideBarBreadcrumbsUI {...props}>
<>
<SideBarBreadcrumbsUI
{...props}
badge={
<Badge size="sm" style="highContrast">{`${activeNetwork?.name}`}</Badge>
{React.Children.map(children, (child) => {
if (!React.isValidElement(child)) {
return null;
}
return React.cloneElement(child, { ...child.props, component: Link });
})}
</>
}
>
{React.Children.map(children, (child) => {
if (!React.isValidElement(child)) {
return null;
}
return React.cloneElement(child, { ...child.props, component: Link });
})}
</SideBarBreadcrumbsUI>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { env } from '@/utils/env';
import { getAccountCookieName } from '@/utils/getAccountCookieName';
import { store } from '@/utils/socket/store';
import { connect, initSpireKey } from '@kadena/spirekey-sdk';
import { connect } from '@kadena/spirekey-sdk';
import { useRouter } from 'next/navigation';
import type { FC, PropsWithChildren } from 'react';
import { createContext, useCallback, useEffect, useState } from 'react';
Expand Down Expand Up @@ -59,9 +59,6 @@ export const AccountProvider: FC<PropsWithChildren> = ({ children }) => {
}
}

initSpireKey({
hostUrl: process.env.NEXT_PUBLIC_WALLET_URL,
});
setIsMounted(true);
}, []);

Expand Down
1 change: 1 addition & 0 deletions packages/apps/rwa-demo/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ module.exports = {
'@rushstack/no-new-null': 'off',
'react/react-in-jsx-scope': 'off',
'react/jsx-uses-react': 'off',
'@typescript-eslint/strict-boolean-expressions': 'off',
},
};
10 changes: 9 additions & 1 deletion packages/apps/rwa-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"build": "next build",
"dev": "next dev",
"generate": "pactjs contract-generate --contract \"RWA.agent-role\" --chain 0 --network development --api \"http://localhost:8080/chainweb/0.0/development/chain/0/pact\"",
"lint": "pnpm run /^lint:.*/",
"lint:fmt": "prettier . --cache --check",
"lint:src": "eslint src",
Expand All @@ -14,9 +15,12 @@
"test:watch": "vitest --coverage"
},
"dependencies": {
"@hookform/resolvers": "^3.2.0",
"@kadena/client": "^1.15.0",
"@kadena/cryptography-utils": "workspace:*",
"@kadena/kode-icons": "workspace:*",
"@kadena/kode-ui": "workspace:*",
"@kadena/pactjs": "workspace:*",
"@kadena/spirekey-sdk": "^1.0.0",
"@vanilla-extract/css": "1.14.2",
"@vanilla-extract/css-utils": "^0.1.3",
Expand All @@ -26,12 +30,16 @@
"next": "14.2.2",
"next-themes": "^0.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-hook-form": "^7.45.4"
},
"devDependencies": {
"@kadena-dev/eslint-config": "workspace:*",
"@kadena-dev/lint-package": "workspace:*",
"@kadena-dev/shared-config": "workspace:*",
"@kadena/pactjs": "workspace:*",
"@kadena/pactjs-cli": "^1.15.0",
"@kadena/pactjs-generator": "workspace:*",
"@types/node": "^20.12.7",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
Expand Down
52 changes: 51 additions & 1 deletion packages/apps/rwa-demo/src/app/(app)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,57 @@
'use client';
import { AddAgentForm } from '@/components/AddAgentForm/AddAgentForm';
import { InitTokenForm } from '@/components/InitTokenForm/InitTokenForm';
import { SideBarBreadcrumbs } from '@/components/SideBarBreadcrumbs/SideBarBreadcrumbs';
import { MonoAdd } from '@kadena/kode-icons';
import { Button } from '@kadena/kode-ui';
import { SideBarBreadcrumbsItem, useLayout } from '@kadena/kode-ui/patterns';
import { useState } from 'react';

const Home = () => {
return <div>Hello world</div>;
const { setIsRightAsideExpanded, isRightAsideExpanded } = useLayout();
const [hasOpenInitForm, setHasOpenInitForm] = useState(false);
const [hasOpenAgentForm, setHasOpenAgentForm] = useState(false);

const handleAddAgent = () => {
setIsRightAsideExpanded(true);
setHasOpenAgentForm(true);
};

const handleInitToken = () => {
setIsRightAsideExpanded(true);
setHasOpenInitForm(true);
};

return (
<div>
<SideBarBreadcrumbs>
<SideBarBreadcrumbsItem href="/">Tokens</SideBarBreadcrumbsItem>
</SideBarBreadcrumbs>
{isRightAsideExpanded && hasOpenAgentForm && (
<AddAgentForm
onClose={() => {
setIsRightAsideExpanded(false);
setHasOpenAgentForm(false);
}}
/>
)}
{isRightAsideExpanded && hasOpenInitForm && (
<InitTokenForm
onClose={() => {
setIsRightAsideExpanded(false);
setHasOpenInitForm(false);
}}
/>
)}
<Button startVisual={<MonoAdd />} onClick={handleAddAgent}>
Add Agent
</Button>

<Button startVisual={<MonoAdd />} onClick={handleInitToken}>
Init Token
</Button>
</div>
);
};

export default Home;
13 changes: 9 additions & 4 deletions packages/apps/rwa-demo/src/app/Providers.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { AccountProvider } from '@/components/AccountProvider/AccountProvider';
import { AssetProvider } from '@/components/AssetProvider/AssetProvider';
import { NetworkProvider } from '@/components/NetworkProvider/NetworkProvider';
import { MediaContextProvider } from '@kadena/kode-ui';
import { LayoutProvider } from '@kadena/kode-ui/patterns';
import { darkThemeClass } from '@kadena/kode-ui/styles';
Expand All @@ -10,17 +12,20 @@ export const Providers: FC<PropsWithChildren> = ({ children }) => {
<MediaContextProvider>
<ThemeProvider
attribute="class"
forcedTheme="dark"
value={{
light: 'light',
dark: darkThemeClass,
}}
enableSystem={true}
enableColorScheme={true} // When enabled, we can't make the background of the embedded iframe transparent
>
<LayoutProvider>
<AccountProvider>{children}</AccountProvider>
</LayoutProvider>
<NetworkProvider>
<AccountProvider>
<LayoutProvider>
<AssetProvider>{children}</AssetProvider>
</LayoutProvider>
</AccountProvider>
</NetworkProvider>
</ThemeProvider>
</MediaContextProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const AccountProvider: FC<PropsWithChildren> = ({ children }) => {
useEffect(() => {
const storage = localStorage.getItem(getAccountCookieName());
if (storage) {
console.log({ account: JSON.parse(storage) });
try {
setAccount(JSON.parse(storage));
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { useAccount } from '@/hooks/account';
import { useNetwork } from '@/hooks/networks';
import type { IAddAgentProps } from '@/services/addAgent';
import { addAgent } 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 { useState } from 'react';
import { useForm } from 'react-hook-form';

interface IProps {
onClose: () => void;
}

export const AddAgentForm: FC<IProps> = ({ onClose }) => {
const { activeNetwork } = useNetwork();
const { account } = useAccount();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, setError] = useState<string | null>(null);
const { register, handleSubmit } = useForm<IAddAgentProps>({
defaultValues: {
agent: '',
},
});

const onSubmit = async (data: IAddAgentProps) => {
console.log({ data });
setError(null);
try {
await addAgent(data, activeNetwork, account!);

// setIsRightAsideExpanded(false);
} catch (e: any) {
setError(e?.message || e);
}

// onClose();
};

return (
<RightAside isOpen onClose={onClose}>
<form onSubmit={handleSubmit(onSubmit)}>
<RightAsideHeader label="Add Agent" />
<RightAsideContent>
<TextField
label="Agent Account"
{...register('agent', { required: true })}
/>
</RightAsideContent>
<RightAsideFooter>
<Button onPress={onClose} variant="transparent">
Cancel
</Button>
<Button type="submit">Add Agent</Button>
</RightAsideFooter>
</form>
</RightAside>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use client';
import type { FC, PropsWithChildren } from 'react';
import { createContext, useState } from 'react';

interface IAsset {
name: string;
}

export interface IAssetContext {
asset?: IAsset;
}

export const AssetContext = createContext<IAssetContext>({});

export const AssetProvider: FC<PropsWithChildren> = ({ children }) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [asset, setAsset] = useState<IAsset>();

return (
<AssetContext.Provider value={{ asset }}>{children}</AssetContext.Provider>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { useAccount } from '@/hooks/account';
import { useNetwork } from '@/hooks/networks';
import type { IInitTokenProps } from '@/services/initToken';
import { initToken } from '@/services/initToken';
import { Button, TextField } from '@kadena/kode-ui';
import {
RightAside,
RightAsideContent,
RightAsideFooter,
RightAsideHeader,
} from '@kadena/kode-ui/patterns';
import type { FC } from 'react';
import { useState } from 'react';
import { useForm } from 'react-hook-form';

interface IProps {
onClose: () => void;
}

export const InitTokenForm: FC<IProps> = ({ onClose }) => {
const { activeNetwork } = useNetwork();
const { account } = useAccount();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [error, setError] = useState<string | null>(null);
const { register, handleSubmit } = useForm<IInitTokenProps>({
defaultValues: {
name: '',
},
});

const onSubmit = async (data: IInitTokenProps) => {
console.log({ data });
setError(null);
//try {
await initToken(data, activeNetwork, account!);

//onClose();
// setIsRightAsideExpanded(false);
// } catch (e: any) {
// setError(e?.message || e);
// }
};

return (
<RightAside isOpen onClose={onClose}>
<form onSubmit={handleSubmit(onSubmit)}>
<RightAsideHeader label="Init Asset" />
<RightAsideContent>
<TextField label="Name" {...register('name', { required: true })} />
<TextField
label="Symbol"
{...register('symbol', { required: true })}
/>
<TextField
label="KadenaId"
{...register('kadenaId', { required: true })}
/>
</RightAsideContent>
<RightAsideFooter>
<Button onPress={onClose} variant="transparent">
Cancel
</Button>
<Button type="submit">Create Security</Button>
</RightAsideFooter>
</form>
</RightAside>
);
};
Loading

0 comments on commit 83bd571

Please sign in to comment.