From 5864a3ef42303efb0535c3392b23219aad41e6a6 Mon Sep 17 00:00:00 2001 From: Maciek Malik Date: Thu, 29 Feb 2024 15:09:53 +0100 Subject: [PATCH] Enabled PSP34 extensions on the UI Disabled work in progress modal when switching to the PSP34 standard bumped ink generator version to 0.3.8 Signed-off-by: Maciek Malik --- package.json | 4 +-- pnpm-lock.yaml | 8 ++--- src/components/data-entry/Switch.tsx | 6 ++-- .../homepage/sidebar-form/SidebarForm.tsx | 13 ++++--- .../form-sections/MetadataPSP22.tsx | 35 +++++++++++++++++++ .../sidebar-form/form-sections/Standard.tsx | 23 ------------ .../homepage/sidebar-form/formConstants.ts | 25 ++----------- .../sidebar-form/useSidebarFormSubmit.ts | 27 ++++---------- src/libs/en.ts | 9 ++--- 9 files changed, 62 insertions(+), 88 deletions(-) create mode 100644 src/components/homepage/sidebar-form/form-sections/MetadataPSP22.tsx diff --git a/package.json b/package.json index 7ede47b..62ef359 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "smart-beaver-wizard", - "version": "0.2.0", + "version": "0.3.0", "private": true, "husky": { "hooks": { @@ -33,7 +33,7 @@ "debounce": "^2.0.0", "highlight.js": "^11.9.0", "husky": "^8.0.3", - "ink-generator": "^0.3.5", + "ink-generator": "0.3.8", "next": "14.0.0", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ae3b66a..1dba816 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -39,8 +39,8 @@ dependencies: specifier: ^8.0.3 version: 8.0.3 ink-generator: - specifier: ^0.3.5 - version: 0.3.5 + specifier: 0.3.8 + version: 0.3.8 next: specifier: 14.0.0 version: 14.0.0(@babel/core@7.23.3)(react-dom@18.2.0)(react@18.2.0) @@ -3479,8 +3479,8 @@ packages: /inherits@2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} - /ink-generator@0.3.5: - resolution: {integrity: sha512-lwG1zzlNrBputifYZnp4f8HltDRO+3t9JRlibGaCzE/4crdZ0pz8W+3XK7tfNZLtsB3VMQScdYLtiQjjoLhBcw==} + /ink-generator@0.3.8: + resolution: {integrity: sha512-O+fEityf8upnaMxg8YPHqkOPgjDggIPu2Tjf1vgy8Vm+laLtRudQVzcWTiIPFHI5pxBFq3WgIWaNU8NrGCEiEQ==} dev: false /internal-slot@1.0.6: diff --git a/src/components/data-entry/Switch.tsx b/src/components/data-entry/Switch.tsx index c837069..e0fab45 100644 --- a/src/components/data-entry/Switch.tsx +++ b/src/components/data-entry/Switch.tsx @@ -10,7 +10,7 @@ interface SwitchProps { disabled?: boolean; } -export default function Switch({ name, label, disabled }: SwitchProps) { +export default function Switch({ name, label }: SwitchProps) { const { fieldState: { error }, field: { onChange, ...restField } @@ -24,11 +24,9 @@ export default function Switch({ name, label, disabled }: SwitchProps) { onChange={(e) => { onChange(e); }} - disabled={disabled} className={cn( 'border-transparent relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-teal-700 focus:ring-offset-2 ', - restField.value ? 'bg-teal-600' : 'bg-transparent', - disabled && 'opacity-50' + restField.value ? 'bg-teal-600' : 'bg-transparent' )} >

{dictionary.sidebarForm.sections.singleFile.title}

- +

{dictionary.sidebarForm.configure}

- + {choosenStandard === 'PSP22' && } diff --git a/src/components/homepage/sidebar-form/form-sections/MetadataPSP22.tsx b/src/components/homepage/sidebar-form/form-sections/MetadataPSP22.tsx new file mode 100644 index 0000000..1d01997 --- /dev/null +++ b/src/components/homepage/sidebar-form/form-sections/MetadataPSP22.tsx @@ -0,0 +1,35 @@ +import { useFormContext } from 'react-hook-form'; +import { Input } from '@/components/data-entry/Input'; +import ExpandableFilterContainer from '@/components/homepage/sidebar-form/ExpandableFilterContainer'; +import BeaverMemo from '@/components/homepage/sidebar-form/form-sections/BeaverMemo'; +import { METADATA22 } from '@/components/homepage/sidebar-form/formConstants'; +import { dictionary } from '@/libs/en'; + +export default function MetadataPSP22() { + const { resetField } = useFormContext(); + + const handleResetMetadataSection = () => { + METADATA22.forEach(({ name }) => { + resetField(name); + }); + }; + + return ( + + + {METADATA22.map(({ label, name, placeholder, inputType, disabled }) => ( + + ))} + + ); +} diff --git a/src/components/homepage/sidebar-form/form-sections/Standard.tsx b/src/components/homepage/sidebar-form/form-sections/Standard.tsx index 7c7fe06..11133c9 100644 --- a/src/components/homepage/sidebar-form/form-sections/Standard.tsx +++ b/src/components/homepage/sidebar-form/form-sections/Standard.tsx @@ -1,35 +1,12 @@ -import { useEffect, useState } from 'react'; -import { useWatch } from 'react-hook-form'; import { Radio } from '@/components/data-entry/radio/Radio'; -import PSP34DisclaimerModal from '@/components/homepage/sidebar-form/form-sections/PSP34DisclaimerModal'; -import type { PSPUnion } from '@/components/homepage/sidebar-form/formConstants'; import { SUPPORTED_STANDARDS } from '@/components/homepage/sidebar-form/formConstants'; -interface FormValues { - standard: PSPUnion; -} - export function Standard() { - const [open, setOpen] = useState(false); - const standardButton: PSPUnion = useWatch({ - name: 'standard' - }); - - useEffect(() => { - if (standardButton === 'PSP34') { - setOpen(true); - } else { - setOpen(false); - } - }, [standardButton]); - return ( <>
- {/* Modal is here just for a moment, it will be deleted soon (remember to REMOVE also logic here, component and dictionary) - after fixes on PSP34 */} - ); } diff --git a/src/components/homepage/sidebar-form/formConstants.ts b/src/components/homepage/sidebar-form/formConstants.ts index 4b8ad5c..cd40ea0 100644 --- a/src/components/homepage/sidebar-form/formConstants.ts +++ b/src/components/homepage/sidebar-form/formConstants.ts @@ -37,28 +37,6 @@ export const METADATA22 = [ } ] as const; -export const METADATA34 = [ - { - label: dictionary.sidebarForm.sections.metadata.name.title, - name: 'name', - placeholder: dictionary.sidebarForm.sections.metadata.name.placeholder, - inputType: 'text', - disabled: true - }, - { - label: dictionary.sidebarForm.sections.metadata.symbol.title, - name: 'symbol', - placeholder: dictionary.sidebarForm.sections.metadata.symbol.placeholder, - inputType: 'text', - disabled: true - } -] as const; - -export const METADATA: { [key in keyof typeof STANDARDS]: typeof METADATA22 | typeof METADATA34 } = { - PSP22: METADATA22, - PSP34: METADATA34 -}; - export const FEATURES_OPTIONS22 = [ { label: dictionary.sidebarForm.sections.features.mintable, name: 'mintable', disabled: false }, { label: dictionary.sidebarForm.sections.features.burnable, name: 'burnable', disabled: false }, @@ -69,7 +47,8 @@ export const FEATURES_OPTIONS22 = [ export const FEATURES_OPTIONS34 = [ { label: dictionary.sidebarForm.sections.features.mintable, name: 'mintable', disabled: false }, { label: dictionary.sidebarForm.sections.features.burnable, name: 'burnable', disabled: false }, - { label: dictionary.sidebarForm.sections.features.enumerable, name: 'enumerable', disabled: true } + { label: dictionary.sidebarForm.sections.features.enumerable, name: 'enumerable', disabled: false }, + { label: dictionary.sidebarForm.sections.features.metadata, name: 'metadata', disabled: false } ] as const; export const FEATURES_OPTIONS: { diff --git a/src/components/homepage/sidebar-form/useSidebarFormSubmit.ts b/src/components/homepage/sidebar-form/useSidebarFormSubmit.ts index e738cef..f4eb80c 100644 --- a/src/components/homepage/sidebar-form/useSidebarFormSubmit.ts +++ b/src/components/homepage/sidebar-form/useSidebarFormSubmit.ts @@ -1,5 +1,5 @@ import { Contract, Metadata, start } from 'ink-generator'; -import { FEATURES_OPTIONS, STANDARDS } from '@/components/homepage/sidebar-form/formConstants'; +import { FEATURES_OPTIONS } from '@/components/homepage/sidebar-form/formConstants'; import type { SidebarFormSchema } from '@/components/homepage/sidebar-form/SidebarForm'; import { sortWasmResults } from '@/components/homepage/sidebar-form/sortWasmResults'; import { useWasmData } from '@/contexts/WasmDataContext'; @@ -17,36 +17,23 @@ interface FetchDataResponse { export default function useSidebarFormSubmit() { const { setWasmFileData, setWasmCodeFetchingError } = useWasmData(); - // This is a workaround for the fact that the Rust code doesn't support PSP34 yet. - function filterExtensions(extensions: string[], standard: string): string[] { - if (standard === STANDARDS.PSP34) { - return []; - } - return extensions; - } - return async (data: SidebarFormSchema) => { const { name, symbol, decimals, license, standard, accessControl, isSingleCodeGenerationModeActive } = data; const featureExtensions = FEATURES_OPTIONS[standard] .filter(({ name }) => data[name as keyof typeof data]) .map(({ name }) => name); - const shouldIncludeMetadata = Boolean(name || symbol || Number.isFinite(decimals)) ? 'metadata' : ''; const accessControlExtension = accessControl && accessControl !== '' ? [accessControl] : []; - const extensions = [...featureExtensions, ...accessControlExtension, shouldIncludeMetadata && 'metadata']; + const extensions = [...featureExtensions, ...accessControlExtension]; + if (Boolean(name || symbol || Number.isFinite(decimals))) { + extensions.push('metadata'); + } try { if (!URL) throw new Error('API base URL is not defined.'); const result = await (async (): Promise => { - const metadata = new Metadata(name, symbol, undefined, decimals); - const contract = new Contract( - standard, - metadata, - filterExtensions(extensions, standard), - URL, - license, - isSingleCodeGenerationModeActive - ); + const metadata = new Metadata(name, symbol, undefined, decimals ?? 0); + const contract = new Contract(standard, metadata, extensions, URL, license, isSingleCodeGenerationModeActive); return await start(contract); })(); diff --git a/src/libs/en.ts b/src/libs/en.ts index ace8e8d..2076ce5 100644 --- a/src/libs/en.ts +++ b/src/libs/en.ts @@ -75,7 +75,8 @@ export const dictionary = { burnable: 'Burnable', pausable: 'Pausable', capped: 'Capped', - enumerable: 'Enumerable' + enumerable: 'Enumerable', + metadata: 'Metadata' }, accessControl: { title: 'Access control', @@ -98,12 +99,6 @@ export const dictionary = { }, recommended: 'We recommend accessing the application on a desktop device.' }, - //This is a part you need to delete together with psp34disclaimermodal - modal: { - title: 'Disclaimer', - description: "The final implementation of PSP34 is still in progress, and we'll update it when it's ready.", - button: 'Ok, thanks' - }, errors: { useWasmData: 'useWasmData must be used within a WasmDataProvider', useSidebarFormSubmit: 'Something went wrong while generating code',