Skip to content

Commit

Permalink
fix(rwa): return loading state of the create contract, when there was…
Browse files Browse the repository at this point in the history
… an issue (#2774)
  • Loading branch information
sstraatemans authored Jan 7, 2025
1 parent 2c9828f commit 1d28f41
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .changeset/sweet-taxis-try.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
@@ -1,6 +1,5 @@
import { useAsset } from '@/hooks/asset';
import { Button, Stack, TextField } from '@kadena/kode-ui';
import { useRouter } from 'next/navigation';
import type { FC } from 'react';
import { Controller, useForm } from 'react-hook-form';

Expand All @@ -12,8 +11,7 @@ interface IAddExistingAssetProps {
}

export const AddExistingAssetForm: FC<IProps> = ({ handleDone }) => {
const router = useRouter();
const { addExistingAsset } = useAsset();
const { setAsset, addExistingAsset } = useAsset();
const {
handleSubmit,
control,
Expand All @@ -28,7 +26,9 @@ export const AddExistingAssetForm: FC<IProps> = ({ handleDone }) => {
const asset = addExistingAsset(data.name);
if (!asset) return;

router.refresh();
setAsset(asset);
window.location.href = '/';

if (handleDone) handleDone();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ export const AssetStepperForm: FC<IProps> = ({ handleDone }) => {
setError('');
if (!data.namespace) {
setError('there was an issue creating the namespace');
setIsLoading(false);
return;
}

setIsLoading(true);
const tx = await submitContract(data);
if (tx?.result?.status === 'success') {
setStep(STEPS.DONE);
setIsLoading(false);
const asset = addAsset({
contractName: data.contractName,
namespace: data.namespace,
Expand All @@ -77,6 +77,7 @@ export const AssetStepperForm: FC<IProps> = ({ handleDone }) => {
setAsset(asset);
window.location.href = '/';
}
setIsLoading(false);
};

return (
Expand Down Expand Up @@ -123,7 +124,9 @@ export const AssetStepperForm: FC<IProps> = ({ handleDone }) => {
<Controller
name="namespace"
control={control}
rules={{ required: true }}
rules={{
required: true,
}}
render={({ field }) => (
<TextField label="Namespace" isDisabled {...field} />
)}
Expand All @@ -132,7 +135,13 @@ export const AssetStepperForm: FC<IProps> = ({ handleDone }) => {
<Controller
name="contractName"
control={control}
rules={{ required: true }}
rules={{
required: true,
pattern: {
value: /^\S*$/gi,
message: 'no spaces allowed',
},
}}
render={({ field }) => (
<TextField label="Contract Name" {...field} />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ const interpretMessage = (str: string, data?: ITransaction): string => {
if (str?.includes('exceeds max investor')) {
return `The maximum amount of investors has been reached`;
}
if (str?.includes('PactDuplicateTableError')) {
return `This already exists`;
}

return `${data?.type}: ${str}`;
};
Expand Down

0 comments on commit 1d28f41

Please sign in to comment.