Skip to content

Commit

Permalink
cleanup and remove the stepper
Browse files Browse the repository at this point in the history
  • Loading branch information
sstraatemans committed Dec 11, 2024
1 parent 33e59fc commit d4b014f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<IProps> = ({ handleDone }) => {
const router = useRouter();
const { addExistingAsset } = useAsset();
const {
Expand All @@ -26,6 +29,7 @@ export const AddExistingAssetForm: FC = () => {
if (!asset) return;

router.refresh();
if (handleDone) handleDone();
};

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -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<IProps> = ({ handleDone }) => {
const [contractData, setContractData] = useState<
IAddContractProps | undefined
>();
const [step, setStep] = useState<number>(STEPS.CREATE_NAMESPACE);
const [step, setStep] = useState<number>(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,
Expand Down Expand Up @@ -78,7 +70,6 @@ export const AssetStepperForm: FC<IProps> = ({ handleDone }) => {
return;
}

setContractData(data);
const tx = await submitContract(data);
if (tx?.result?.status === 'success') {
setStep(STEPS.DONE);
Expand All @@ -94,87 +85,39 @@ export const AssetStepperForm: FC<IProps> = ({ handleDone }) => {

return (
<Stack width="100%" flexDirection="column" alignItems="center">
<Stepper direction="horizontal">
<Step
status={step >= STEPS.CREATE_NAMESPACE ? 'active' : 'inactive'}
active={step === STEPS.CREATE_NAMESPACE}
>
Namespace
</Step>
<Step
status={step >= STEPS.CREATE_CONTRACT ? 'active' : 'inactive'}
active={step === STEPS.CREATE_CONTRACT}
>
Contract
</Step>
<Step
status={step >= STEPS.INIT_CONTRACT ? 'active' : 'inactive'}
active={step === STEPS.INIT_CONTRACT}
>
Init
</Step>
</Stepper>

{error && (
<Notification role="alert">
<NotificationHeading>There was an issue</NotificationHeading>
{error}
</Notification>
)}

{step === STEPS.CREATE_NAMESPACE && (
{step === STEPS.START && (
<Stack flexDirection="column" gap="sm">
<AddExistingAssetForm />
<AddExistingAssetForm handleDone={handleDone} />
<Stack width="100%" justifyContent="center">
<Text bold>or</Text>
</Stack>
<Button
variant="outlined"
onPress={async () => {
setError('');
// const transaction = await submit();

// console.log({ transaction });
// if (transaction?.result?.status === 'success') {
// const ns = (transaction.result.data as string).split('.')[0];
// if (!ns) {
// setError(
// `no namespace created from result (${transaction.result.data})`,
// );
// }
// setNamespace(ns);
// setStep(STEPS.CREATE_CONTRACT);
// } else {
// setError(`no namespace created`);
// }
setStep(STEPS.CREATE_CONTRACT);
}}
>
Start New Asset
</Button>
</Stack>
)}
{step === STEPS.INIT_CONTRACT && (

{step === STEPS.DONE && (
<Button
onPress={async () => {
setError('');

const transaction = await submitInit(contractData);

if (transaction?.result?.status === 'success' && contractData) {
setStep(STEPS.DONE);
const asset = addAsset({
contractName: contractData.contractName,
namespace: contractData.namespace,
});
if (!asset) return;
setAsset(asset);
if (handleDone) handleDone();
} else {
setError(`init failed`);
}
router.replace('/assets');
router.refresh();
if (handleDone) handleDone();
}}
>
Init Contract
DONE
</Button>
)}

Expand Down
48 changes: 0 additions & 48 deletions packages/apps/rwa-demo/src/hooks/initContract.ts

This file was deleted.

44 changes: 0 additions & 44 deletions packages/apps/rwa-demo/src/services/initContract.ts

This file was deleted.

0 comments on commit d4b014f

Please sign in to comment.