From d4b014f91a6a71883153aa7fd5d1b235d16f9f58 Mon Sep 17 00:00:00 2001 From: Steven Straatemans Date: Wed, 11 Dec 2024 12:00:56 +0100 Subject: [PATCH] cleanup and remove the stepper --- .../AssetForm/AddExistingAssetForm.tsx | 6 +- .../components/AssetForm/AssetStepperForm.tsx | 85 +++---------------- .../apps/rwa-demo/src/hooks/initContract.ts | 48 ----------- .../rwa-demo/src/services/initContract.ts | 44 ---------- 4 files changed, 19 insertions(+), 164 deletions(-) delete mode 100644 packages/apps/rwa-demo/src/hooks/initContract.ts delete mode 100644 packages/apps/rwa-demo/src/services/initContract.ts diff --git a/packages/apps/rwa-demo/src/components/AssetForm/AddExistingAssetForm.tsx b/packages/apps/rwa-demo/src/components/AssetForm/AddExistingAssetForm.tsx index 914a9cf4af..f2556f263f 100644 --- a/packages/apps/rwa-demo/src/components/AssetForm/AddExistingAssetForm.tsx +++ b/packages/apps/rwa-demo/src/components/AssetForm/AddExistingAssetForm.tsx @@ -4,11 +4,14 @@ import { useRouter } from 'next/navigation'; import type { FC } from 'react'; import { Controller, useForm } from 'react-hook-form'; +interface IProps { + handleDone?: () => void; +} interface IAddExistingAssetProps { name: string; } -export const AddExistingAssetForm: FC = () => { +export const AddExistingAssetForm: FC = ({ handleDone }) => { const router = useRouter(); const { addExistingAsset } = useAsset(); const { @@ -26,6 +29,7 @@ export const AddExistingAssetForm: FC = () => { if (!asset) return; router.refresh(); + if (handleDone) handleDone(); }; return ( diff --git a/packages/apps/rwa-demo/src/components/AssetForm/AssetStepperForm.tsx b/packages/apps/rwa-demo/src/components/AssetForm/AssetStepperForm.tsx index c3a1c281f0..217cbdb339 100644 --- a/packages/apps/rwa-demo/src/components/AssetForm/AssetStepperForm.tsx +++ b/packages/apps/rwa-demo/src/components/AssetForm/AssetStepperForm.tsx @@ -1,46 +1,38 @@ import { useAsset } from '@/hooks/asset'; import { useCreateContract } from '@/hooks/createContract'; import { useGetPrincipalNamespace } from '@/hooks/getPrincipalNamespace'; -import { useInitContract } from '@/hooks/initContract'; import type { IAddContractProps } from '@/services/createContract'; import { Button, Notification, NotificationHeading, Stack, - Step, - Stepper, Text, TextField, } from '@kadena/kode-ui'; +import { useRouter } from 'next/navigation'; import type { FC } from 'react'; import { useEffect, useState } from 'react'; import { Controller, useForm } from 'react-hook-form'; -import type { IAsset } from '../AssetProvider/AssetProvider'; import { AddExistingAssetForm } from './AddExistingAssetForm'; interface IProps { - asset?: IAsset; handleDone?: () => void; } const STEPS = { - CREATE_NAMESPACE: 0, + START: 0, CREATE_CONTRACT: 1, - INIT_CONTRACT: 2, - DONE: 3, + DONE: 2, } as const; export const AssetStepperForm: FC = ({ handleDone }) => { - const [contractData, setContractData] = useState< - IAddContractProps | undefined - >(); - const [step, setStep] = useState(STEPS.CREATE_NAMESPACE); + const [step, setStep] = useState(STEPS.START); const { addAsset, setAsset } = useAsset(); const { data: namespace } = useGetPrincipalNamespace(); - const { submit: submitInit } = useInitContract(); const { submit: submitContract } = useCreateContract(); const [error, setError] = useState(''); + const router = useRouter(); const { handleSubmit, @@ -78,7 +70,6 @@ export const AssetStepperForm: FC = ({ handleDone }) => { return; } - setContractData(data); const tx = await submitContract(data); if (tx?.result?.status === 'success') { setStep(STEPS.DONE); @@ -94,27 +85,6 @@ export const AssetStepperForm: FC = ({ handleDone }) => { return ( - - = STEPS.CREATE_NAMESPACE ? 'active' : 'inactive'} - active={step === STEPS.CREATE_NAMESPACE} - > - Namespace - - = STEPS.CREATE_CONTRACT ? 'active' : 'inactive'} - active={step === STEPS.CREATE_CONTRACT} - > - Contract - - = STEPS.INIT_CONTRACT ? 'active' : 'inactive'} - active={step === STEPS.INIT_CONTRACT} - > - Init - - - {error && ( There was an issue @@ -122,59 +92,32 @@ export const AssetStepperForm: FC = ({ handleDone }) => { )} - {step === STEPS.CREATE_NAMESPACE && ( + {step === STEPS.START && ( - + or )} - {step === STEPS.INIT_CONTRACT && ( + + {step === STEPS.DONE && ( )} diff --git a/packages/apps/rwa-demo/src/hooks/initContract.ts b/packages/apps/rwa-demo/src/hooks/initContract.ts deleted file mode 100644 index aa9ad53bf4..0000000000 --- a/packages/apps/rwa-demo/src/hooks/initContract.ts +++ /dev/null @@ -1,48 +0,0 @@ -import type { ITransaction } from '@/components/TransactionsProvider/TransactionsProvider'; -import { interpretErrorMessage } from '@/components/TransactionsProvider/TransactionsProvider'; -import type { IAddContractProps } from '@/services/createContract'; -import { initContract } from '@/services/initContract'; -import { getClient } from '@/utils/client'; -import { useNotifications } from '@kadena/kode-ui/patterns'; -import { useAccount } from './account'; -import { useTransactions } from './transactions'; - -export const useInitContract = () => { - const { account, sign } = useAccount(); - const { addTransaction } = useTransactions(); - const { addNotification } = useNotifications(); - - const submit = async ( - data?: IAddContractProps, - ): Promise => { - if (!data) return; - - try { - const tx = await initContract(data, account!); - - const signedTransaction = await sign(tx); - if (!signedTransaction) return; - - const client = getClient(); - const res = await client.submit(signedTransaction); - - console.log(res); - - const dataResult = await client.listen(res); - - return addTransaction({ - ...res, - type: 'CREATEPRINCIPALNAMESPACE', - result: dataResult.result, - }); - } catch (e: any) { - addNotification({ - intent: 'negative', - label: 'there was an error', - message: interpretErrorMessage(e.message), - }); - } - }; - - return { submit }; -}; diff --git a/packages/apps/rwa-demo/src/services/initContract.ts b/packages/apps/rwa-demo/src/services/initContract.ts deleted file mode 100644 index 50d9649980..0000000000 --- a/packages/apps/rwa-demo/src/services/initContract.ts +++ /dev/null @@ -1,44 +0,0 @@ -import type { IWalletAccount } from '@/components/AccountProvider/utils'; -import { getNetwork } from '@/utils/client'; -import { Pact } from '@kadena/client'; -import type { IAddContractProps } from './createContract'; - -const createPubKeyFromAccount = (account: string): string => { - return account.replace('k:', '').replace('r:', ''); -}; - -export const initContract = async ( - data: IAddContractProps, - account: IWalletAccount, -) => { - const keysetname = `${data.namespace}.admin-keyset`; - - return Pact.builder - .execution( - ` - (${data.namespace}.${data.contractName}.init "${data.contractName}" "MVP" 0 "kadenaID" "0.0" [RWA.max-balance-compliance RWA.supply-limit-compliance] false (keyset-ref-guard (read-msg 'keyset-name)))`, - ) - .addData('ns', data.namespace) - .addData('keyset-name', keysetname) - .addData('ks', { - keys: [createPubKeyFromAccount(data.owner)], - pred: 'keys-all', - }) - .addData('owner_guard', { - keys: [createPubKeyFromAccount(data.owner)], - pred: 'keys-all', - }) - .addData('compliance-owner', { - keys: [createPubKeyFromAccount(data.complianceOwner)], - pred: 'keys-all', - }) - .setMeta({ - senderAccount: account.address, - chainId: getNetwork().chainId, - gasLimit: 150000, - }) - - .addSigner(account.keyset.guard.keys[0], (withCap) => []) - .setNetworkId(getNetwork().networkId) - .createTransaction(); -};