From 6e4b1a56ebb5ef5c2d2e9c3a0148c8f28cfb458d Mon Sep 17 00:00:00 2001 From: Don <100505855+DonFungible@users.noreply.github.com> Date: Sat, 9 Dec 2023 18:00:10 -0800 Subject: [PATCH 1/5] stage for debugging --- ...onfigureLicenseWriteAccordionInputForm.tsx | 364 ++++++++++++++++++ app/admin/CreateLicenseNftWriteAccordion.tsx | 58 ++- app/admin/LicenseWriteAccordionInputForm.tsx | 361 +++++++++++++++++ app/ipo/[ipOrgId]/page.tsx | 33 +- hooks/useCreateLicense.ts | 3 +- 5 files changed, 792 insertions(+), 27 deletions(-) create mode 100644 app/admin/ConfigureLicenseWriteAccordionInputForm.tsx create mode 100644 app/admin/LicenseWriteAccordionInputForm.tsx diff --git a/app/admin/ConfigureLicenseWriteAccordionInputForm.tsx b/app/admin/ConfigureLicenseWriteAccordionInputForm.tsx new file mode 100644 index 0000000..d667226 --- /dev/null +++ b/app/admin/ConfigureLicenseWriteAccordionInputForm.tsx @@ -0,0 +1,364 @@ +'use client'; +import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'; +import { useForm } from 'react-hook-form'; +import { zodResolver } from '@hookform/resolvers/zod'; +import * as z from 'zod'; +import { Input } from '@/components/ui/input'; +import { useEffect, useState } from 'react'; +import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'; +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, + DialogTrigger, +} from '@/components/ui/dialog'; +import { ArrowPathIcon, CheckIcon, ExclamationCircleIcon, XCircleIcon } from '@heroicons/react/24/outline'; +import EtherscanLink from '@/utils/EtherscanLink'; +import { useAccount, useNetwork } from 'wagmi'; +// import ConnectWalletButton from '@/components/Navbar/ConnectWalletButton2'; +import { ConnectButton } from '@rainbow-me/rainbowkit'; +import { cn } from '@/utils'; +import { ConfigureLicenseRequest, CreateLicenseRequest } from '@story-protocol/core-sdk'; + +type InputFormProps = { + formSchema: z.ZodObject; + hook: any; + fcnName: string; + description?: string; + onSuccessDisplay?: any; + defaultValues?: Record; + descriptions?: Record; + placeholders?: Record; +}; + +function getDefaultValuesFromSchema( + schema: z.ZodObject, + defaultValues: Record, +): Record { + const shape = schema.shape; + const values: Record = {}; + + for (const key in shape) { + values[key] = defaultValues[key] || ''; // Use the default value if available, or set an empty string as a fallback + } + + // Set default values for keys that are in defaultValues but not in the form schema + for (const key in defaultValues) { + if (!values[key]) { + values[key] = defaultValues[key]; + } + } + + return values; +} + +function getZodTypeName(type: z.ZodType): string { + if (type instanceof z.ZodString) return 'string'; + if (type instanceof z.ZodNumber) return 'number'; + if (type instanceof z.ZodBoolean) return 'boolean'; + if (type instanceof z.ZodNativeEnum) return 'enum'; + if (type instanceof z.ZodArray) return 'array'; + return ''; +} + +type EnumDropdownProps = { + field: any; + enumType: Record; +}; + +function EnumDropdown({ field, enumType }: EnumDropdownProps) { + const [selectedValue, setSelectedValue] = useState(''); + + const handleChange = (event: React.ChangeEvent) => { + const selectedValue = event.target.value; + setSelectedValue(selectedValue); + const isEnumOfNumbers = typeof enumType[selectedValue] === 'number'; + + const convertedValue = isEnumOfNumbers ? Number(enumType[selectedValue]) : selectedValue; + console.log(convertedValue); + field.onChange(convertedValue); + }; + + const enumKeys = Object.keys(enumType).filter((key) => isNaN(Number(key))); + + return ( +
+ +
+ + + +
+
+ ); +} + +type BooleanDropdownProps = { + field: any; +}; + +const BooleanDropdown: React.FC = ({ field }) => { + const [hasSelection, setHasSelection] = useState(false); + + useEffect(() => { + // Ensure the initial field value is undefined + if (!hasSelection && field.value !== undefined) { + field.onChange(undefined); + } + }, [hasSelection, field]); + + const handleSelectChange = (event: React.ChangeEvent) => { + const selectedValue = event.target.value === 'true'; + field.onChange(selectedValue); + setHasSelection(true); + }; + + return ( +
+ +
+ + + +
+
+ ); +}; + +type NestedFieldProps = { + control: any; + name: string; + schema: z.ZodType; + defaultValue?: Record; + description?: string; + placeholder?: string; +}; + +function isZodOptional(type: z.ZodType): boolean { + return type.isOptional(); +} + +function NestedField({ control, name, schema, defaultValue, description, placeholder }: NestedFieldProps) { + const typeName = getZodTypeName(schema); + const optionalText = isZodOptional(schema) ? ' (optional)' : ''; + + const isReadOnly = defaultValue && defaultValue[name] !== undefined; // Check if a default value exists for the current field + + if (schema instanceof z.ZodObject) { + return ( +
+

{name.split('.').pop()}

{/* Displaying the name of the nested object */} + {Object.keys(schema.shape).map((key) => ( + + ))} +
+ ); + } + + return ( + ( + + + {name.split('.').pop()} {Boolean(optionalText.length) && optionalText} + {!(schema instanceof z.ZodOptional) && *} + + + {typeName === 'enum' ? ( + )._def.values} /> + ) : typeName === 'boolean' ? ( // Check if the type is boolean + + ) : ( + + )} + + + {description && {description}} + + )} + /> + ); +} + +export default function ConfigureLicenseWriteAccordionInputForm({ + formSchema, + hook, + fcnName, + description = '', + defaultValues = {}, + onSuccessDisplay = <>, + descriptions = {}, + placeholders = {}, +}: InputFormProps) { + const { chain } = useNetwork(); + const { isConnected } = useAccount(); + const form = useForm>({ + resolver: zodResolver(formSchema), + defaultValues: getDefaultValuesFromSchema(formSchema, defaultValues), + }); + + async function onSubmit(values: z.infer, event: any) { + event.preventDefault(); + await execute(); + } + console.log('form state:', form.formState); + const configureLicenseReq: ConfigureLicenseRequest = { + ipOrg: form.getValues().ipOrg, + frameworkId: form.getValues().frameworkId, + licensor: form.getValues().licensor, + params: [ + { + tag: 'Attribution', + value: { + interface: 'bool', + data: form.getValues().attribution, + }, + }, + ], + txOptions: { + waitForTransaction: true, + }, + }; + console.log('Configuring license:', configureLicenseReq); + const { execute, isIdle, isLoading, isSuccess, data, reset, errorMsg } = hook(configureLicenseReq); + + const IdleComponent = () => ( + <> + +

Please confirm the transaction in your wallet.

+ + ); + const LoadingComponent = () => ( + <> + +

+ Transaction in progress... +

+ + ); + + const SuccessComponent = () => ( + <> + +

Transaction successful!

+ {onSuccessDisplay} + + ); + + const FailedComponent = () => { + console.log('Failed:', data); + return ( + <> + +
+

Transaction failed.

+ {errorMsg && {errorMsg}} + +
+ + ); + }; + + const DialogComponent = isIdle + ? IdleComponent + : isLoading + ? LoadingComponent + : isSuccess + ? SuccessComponent + : FailedComponent; + + return ( + <> + reset()}> + + + Transaction Status + + + + + + + + {fcnName} + + {description && ( +
+ +

{description}

+
+ )} + {isConnected ? ( +
+ + {Object.keys(formSchema.shape).map((key) => ( + + ))} + + Submit + + + + ) : ( +
+

Connect your wallet first to perform a transaction

+ {/* */} + +
+ )} +
+
+
+
+ + ); +} diff --git a/app/admin/CreateLicenseNftWriteAccordion.tsx b/app/admin/CreateLicenseNftWriteAccordion.tsx index 662ecdf..989c214 100644 --- a/app/admin/CreateLicenseNftWriteAccordion.tsx +++ b/app/admin/CreateLicenseNftWriteAccordion.tsx @@ -1,30 +1,74 @@ 'use client'; import React from 'react'; import * as z from 'zod'; -import WriteAccordionInputForm from './WriteAccordionInputForm'; -import { CreateLicenseRequest } from '@story-protocol/core-sdk'; +import { ConfigureLicenseRequest, CreateLicenseRequest } from '@story-protocol/core-sdk'; import useCreateLicense from '@/hooks/useCreateLicense'; +import ConfigureLicenseWriteAccordionInputForm from './ConfigureLicenseWriteAccordionInputForm'; +import CreateLicenseWriteAccordionInputForm from './LicenseWriteAccordionInputForm'; export default function CreateLicenseNftWriteAccordion({ - defaultValues, + createDefaultValues, + configureDefaultValues, }: { - defaultValues: Partial; + createDefaultValues: Partial; + configureDefaultValues: Partial; }) { const createIpaBoundLicenseSchema = z.object({ ipOrgId: z.string().min(1, { message: 'Required.', }), + attribution: z.boolean(), + ipaId: z.string().optional(), }); + const createDescriptions = { + ipaId: + 'Specify the IPA ID if you want to create a license specifically for an IP Asset. Else, leave empty or enter 0', + attribution: 'To specify if the license requires the licensee to credit the original IP', + }; + + const configureLicenseSchema = z.object({ + ipOrg: z.string().min(1, { + message: 'Required.', + }), + frameworkId: z.nativeEnum({ + 'SPUML-1.0': 'SPUML-1.0', + }), + licensor: z.nativeEnum({ + IpOrgOwnerAlways: 1, + Source: 2, + }), + attribution: z.boolean(), + ipaId: z.string().optional(), + }); + + const configureDescriptions = { + ipaId: + 'Specify the IPA ID if you want to create a license specifically for an IP Asset. Else, leave empty or enter 0', + frameworkId: + 'The framework ID of the license. Only SPUML-1.0 is currently supported (https://github.com/storyprotocol/protocol-contracts/blob/main/SPUML-v1.pdf)', + licensor: + 'Specify the licensor configuration type. `IpOrgOwnerAlways` will set the licensor as the IP Org. `Source` will inherit the license from its appropriate source (parent license, linked license, or inherit from IP Org).', + attribution: 'To specify if the license requires the licensee to credit the original IP', + }; return (

License

- +
); diff --git a/app/admin/LicenseWriteAccordionInputForm.tsx b/app/admin/LicenseWriteAccordionInputForm.tsx new file mode 100644 index 0000000..3df5e21 --- /dev/null +++ b/app/admin/LicenseWriteAccordionInputForm.tsx @@ -0,0 +1,361 @@ +'use client'; +import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'; +import { useForm } from 'react-hook-form'; +import { zodResolver } from '@hookform/resolvers/zod'; +import * as z from 'zod'; +import { Input } from '@/components/ui/input'; +import { useEffect, useState } from 'react'; +import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'; +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, + DialogTrigger, +} from '@/components/ui/dialog'; +import { ArrowPathIcon, CheckIcon, ExclamationCircleIcon, XCircleIcon } from '@heroicons/react/24/outline'; +import EtherscanLink from '@/utils/EtherscanLink'; +import { useAccount, useNetwork } from 'wagmi'; +// import ConnectWalletButton from '@/components/Navbar/ConnectWalletButton2'; +import { ConnectButton } from '@rainbow-me/rainbowkit'; +import { cn } from '@/utils'; +import { CreateLicenseRequest } from '@story-protocol/core-sdk'; + +type InputFormProps = { + formSchema: z.ZodObject; + hook: any; + fcnName: string; + description?: string; + onSuccessDisplay?: any; + defaultValues?: Record; + descriptions?: Record; + placeholders?: Record; +}; + +function getDefaultValuesFromSchema( + schema: z.ZodObject, + defaultValues: Record, +): Record { + const shape = schema.shape; + const values: Record = {}; + + for (const key in shape) { + values[key] = defaultValues[key] || ''; // Use the default value if available, or set an empty string as a fallback + } + + // Set default values for keys that are in defaultValues but not in the form schema + for (const key in defaultValues) { + if (!values[key]) { + values[key] = defaultValues[key]; + } + } + + return values; +} + +function getZodTypeName(type: z.ZodType): string { + if (type instanceof z.ZodString) return 'string'; + if (type instanceof z.ZodNumber) return 'number'; + if (type instanceof z.ZodBoolean) return 'boolean'; + if (type instanceof z.ZodNativeEnum) return 'enum'; + if (type instanceof z.ZodArray) return 'array'; + return ''; +} + +type EnumDropdownProps = { + field: any; + enumType: Record; +}; + +function EnumDropdown({ field, enumType }: EnumDropdownProps) { + const [selectedValue, setSelectedValue] = useState(''); + + const handleChange = (event: React.ChangeEvent) => { + const selectedValue = event.target.value; + setSelectedValue(selectedValue); + const isEnumOfNumbers = typeof enumType[selectedValue] === 'number'; + + const convertedValue = isEnumOfNumbers ? Number(enumType[selectedValue]) : selectedValue; + console.log(convertedValue); + field.onChange(convertedValue); + }; + + const enumKeys = Object.keys(enumType).filter((key) => isNaN(Number(key))); + + return ( +
+ +
+ + + +
+
+ ); +} + +type BooleanDropdownProps = { + field: any; +}; + +const BooleanDropdown: React.FC = ({ field }) => { + const [hasSelection, setHasSelection] = useState(false); + + useEffect(() => { + // Ensure the initial field value is undefined + if (!hasSelection && field.value !== undefined) { + field.onChange(undefined); + } + }, [hasSelection, field]); + + const handleSelectChange = (event: React.ChangeEvent) => { + const selectedValue = event.target.value === 'true'; + field.onChange(selectedValue); + setHasSelection(true); + }; + + return ( +
+ +
+ + + +
+
+ ); +}; + +type NestedFieldProps = { + control: any; + name: string; + schema: z.ZodType; + defaultValue?: Record; + description?: string; + placeholder?: string; +}; + +function isZodOptional(type: z.ZodType): boolean { + return type.isOptional(); +} + +function NestedField({ control, name, schema, defaultValue, description, placeholder }: NestedFieldProps) { + const typeName = getZodTypeName(schema); + const optionalText = isZodOptional(schema) ? ' (optional)' : ''; + + const isReadOnly = defaultValue && defaultValue[name] !== undefined; // Check if a default value exists for the current field + + if (schema instanceof z.ZodObject) { + return ( +
+

{name.split('.').pop()}

{/* Displaying the name of the nested object */} + {Object.keys(schema.shape).map((key) => ( + + ))} +
+ ); + } + + return ( + ( + + + {name.split('.').pop()} {Boolean(optionalText.length) && optionalText} + {!(schema instanceof z.ZodOptional) && *} + + + {typeName === 'enum' ? ( + )._def.values} /> + ) : typeName === 'boolean' ? ( // Check if the type is boolean + + ) : ( + + )} + + + {description && {description}} + + )} + /> + ); +} + +export default function CreateLicenseWriteAccordionInputForm({ + formSchema, + hook, + fcnName, + description = '', + defaultValues = {}, + onSuccessDisplay = <>, + descriptions = {}, + placeholders = {}, +}: InputFormProps) { + const { chain } = useNetwork(); + const { isConnected } = useAccount(); + const form = useForm>({ + resolver: zodResolver(formSchema), + defaultValues: getDefaultValuesFromSchema(formSchema, defaultValues), + }); + + async function onSubmit(values: z.infer, event: any) { + event.preventDefault(); + await execute(); + } + console.log('form state:', form.formState); + const createLicenseReq: CreateLicenseRequest = { + ipOrgId: form.getValues().ipOrgId, + ipaId: form.getValues().ipaId || '0', + parentLicenseId: '0', + params: [ + { + tag: 'Attribution', + value: { + interface: 'bool', + data: form.getValues().requireAttribution, + }, + }, + ], + txOptions: { + waitForTransaction: true, + }, + }; + console.log('Creating license:', createLicenseReq); + const { execute, isIdle, isLoading, isSuccess, data, reset, errorMsg } = hook(createLicenseReq); + + const IdleComponent = () => ( + <> + +

Please confirm the transaction in your wallet.

+ + ); + const LoadingComponent = () => ( + <> + +

+ Transaction in progress... +

+ + ); + + const SuccessComponent = () => ( + <> + +

Transaction successful!

+ {onSuccessDisplay} + + ); + + const FailedComponent = () => ( + <> + +
+

Transaction failed.

+ {errorMsg && {errorMsg}} + +
+ + ); + + const DialogComponent = isIdle + ? IdleComponent + : isLoading + ? LoadingComponent + : isSuccess + ? SuccessComponent + : FailedComponent; + + return ( + <> + reset()}> + + + Transaction Status + + + + + + + + {fcnName} + + {description && ( +
+ +

{description}

+
+ )} + {isConnected ? ( +
+ + {Object.keys(formSchema.shape).map((key) => ( + + ))} + + Submit + + + + ) : ( +
+

Connect your wallet first to perform a transaction

+ {/* */} + +
+ )} +
+
+
+
+ + ); +} diff --git a/app/ipo/[ipOrgId]/page.tsx b/app/ipo/[ipOrgId]/page.tsx index ca5b0d9..de01bbc 100644 --- a/app/ipo/[ipOrgId]/page.tsx +++ b/app/ipo/[ipOrgId]/page.tsx @@ -16,7 +16,7 @@ import IpAssetWriteAccordion from '@/app/admin/IPAssetWriteAccordion'; import Link from 'next/link'; import HookTableWrapper from '@/components/views/Hook/HookTableWrapper'; import ModuleTableWrapper from '@/components/views/Module/ModuleTableWrapper'; -import { CreateLicenseRequest, GetIPOrgRequest } from '@story-protocol/core-sdk'; +import { ConfigureLicenseRequest, CreateLicenseRequest, GetIPOrgRequest } from '@story-protocol/core-sdk'; import IpOrgLicenseDataViewer from '@/components/views/Licenses'; import CreateLicenseNftWriteAccordion from '@/app/admin/CreateLicenseNftWriteAccordion'; import RelationshipTypeWriteAccordion from '@/app/admin/RelationshipTypeWriteAccordion'; @@ -31,22 +31,6 @@ const PageTitle = async ({ ipOrgId }: { ipOrgId: string }) => { return

{ipOrg!.name}

; }; -// const BannerImage = async ({ ipOrgId }: { ipOrgId: string }) => { -// const getReq: GetIPOrgRequest = { -// ipOrgId: ipOrgId, -// }; -// const data: GetIPOrgResponse = await storyClient.ipOrg.get(getReq); -// // const metadata = await fetch(franchiseData.tokenUri).then((res) => res.json()); -// const metadata = { bannerUrl: '', imageUrl: '' }; -// return ( -// IP Org image -// ); -// }; - export default function IpOrgDetailPage({ params: { ipOrgId } }: { params: { ipOrgId: string } }) { const defaultIPOrgId = { ipOrgId, @@ -64,6 +48,16 @@ export default function IpOrgDetailPage({ params: { ipOrgId } }: { params: { ipO }, }; + const defaultConfigureLicenseNftValues: ConfigureLicenseRequest = { + ipOrg: defaultIPOrgId.ipOrgId, + licensor: 2, + frameworkId: 'SPUML-1.0', + params: [], + txOptions: { + waitForTransaction: true, + }, + }; + return (
@@ -133,7 +127,10 @@ export default function IpOrgDetailPage({ params: { ipOrgId } }: { params: { ipO }>
- +
diff --git a/hooks/useCreateLicense.ts b/hooks/useCreateLicense.ts index 7e6fab3..1666003 100644 --- a/hooks/useCreateLicense.ts +++ b/hooks/useCreateLicense.ts @@ -3,7 +3,7 @@ import { useWaitForTransaction } from 'wagmi'; import { Client, CreateLicenseRequest, CreateLicenseResponse } from '@story-protocol/core-sdk'; import { useStoryClient } from './useStoryClient'; -export default function useCreateLicense(createReq: CreateLicenseRequest | CreateLicenseRequest) { +export default function useCreateLicense(createReq: CreateLicenseRequest) { const { client } = useStoryClient(); const [isIdle, setIsIdle] = useState(true); const [isSuccess, setIsSuccess] = useState(false); @@ -21,7 +21,6 @@ export default function useCreateLicense(createReq: CreateLicenseRequest | Creat } = useWaitForTransaction({ hash: txHash as `0x${string}`, }); - useEffect(() => { setIsSuccess(isTxSuccess); setIsError(isTxError); From 7a238bab1714218833681351b6a38926f0c2dffc Mon Sep 17 00:00:00 2001 From: Don <100505855+DonFungible@users.noreply.github.com> Date: Sat, 9 Dec 2023 18:40:36 -0800 Subject: [PATCH 2/5] fix configure license accordion --- app/admin/ConfigureLicenseWriteAccordionInputForm.tsx | 4 ++-- app/admin/CreateLicenseNftWriteAccordion.tsx | 9 +++++---- app/ipo/[ipOrgId]/page.tsx | 4 ++-- hooks/useConfigureLicense.ts | 1 + 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/admin/ConfigureLicenseWriteAccordionInputForm.tsx b/app/admin/ConfigureLicenseWriteAccordionInputForm.tsx index d667226..dc75281 100644 --- a/app/admin/ConfigureLicenseWriteAccordionInputForm.tsx +++ b/app/admin/ConfigureLicenseWriteAccordionInputForm.tsx @@ -232,7 +232,7 @@ export default function ConfigureLicenseWriteAccordionInputForm({ event.preventDefault(); await execute(); } - console.log('form state:', form.formState); + const configureLicenseReq: ConfigureLicenseRequest = { ipOrg: form.getValues().ipOrg, frameworkId: form.getValues().frameworkId, @@ -242,7 +242,7 @@ export default function ConfigureLicenseWriteAccordionInputForm({ tag: 'Attribution', value: { interface: 'bool', - data: form.getValues().attribution, + data: [form.getValues().attribution], }, }, ], diff --git a/app/admin/CreateLicenseNftWriteAccordion.tsx b/app/admin/CreateLicenseNftWriteAccordion.tsx index 989c214..c167f36 100644 --- a/app/admin/CreateLicenseNftWriteAccordion.tsx +++ b/app/admin/CreateLicenseNftWriteAccordion.tsx @@ -5,6 +5,7 @@ import { ConfigureLicenseRequest, CreateLicenseRequest } from '@story-protocol/c import useCreateLicense from '@/hooks/useCreateLicense'; import ConfigureLicenseWriteAccordionInputForm from './ConfigureLicenseWriteAccordionInputForm'; import CreateLicenseWriteAccordionInputForm from './LicenseWriteAccordionInputForm'; +import useConfigureLicense from '@/hooks/useConfigureLicense'; export default function CreateLicenseNftWriteAccordion({ createDefaultValues, @@ -13,13 +14,13 @@ export default function CreateLicenseNftWriteAccordion({ createDefaultValues: Partial; configureDefaultValues: Partial; }) { - const createIpaBoundLicenseSchema = z.object({ + const createLicenseSchema = z.object({ ipOrgId: z.string().min(1, { message: 'Required.', }), - attribution: z.boolean(), ipaId: z.string().optional(), }); + const createDescriptions = { ipaId: 'Specify the IPA ID if you want to create a license specifically for an IP Asset. Else, leave empty or enter 0', @@ -58,14 +59,14 @@ export default function CreateLicenseNftWriteAccordion({ fcnName={'license.configure'} description={"Configure your IP Org's licensing framework before being able to create a license."} formSchema={configureLicenseSchema} - hook={useCreateLicense} + hook={useConfigureLicense} defaultValues={configureDefaultValues} descriptions={configureDescriptions} /> { try { const { txHash } = await (client as Client).license.configure(configureReq); From 3e2300d7882e83a808c71d5cc2da83a60f918c6c Mon Sep 17 00:00:00 2001 From: Don <100505855+DonFungible@users.noreply.github.com> Date: Sat, 9 Dec 2023 19:07:47 -0800 Subject: [PATCH 3/5] stage for allen --- app/admin/CreateLicenseNftWriteAccordion.tsx | 1 + app/admin/LicenseWriteAccordionInputForm.tsx | 10 +--------- app/ipo/[ipOrgId]/page.tsx | 8 ++++---- components/views/IPOrg/IPOrgDataViewerComponent.tsx | 12 ------------ 4 files changed, 6 insertions(+), 25 deletions(-) diff --git a/app/admin/CreateLicenseNftWriteAccordion.tsx b/app/admin/CreateLicenseNftWriteAccordion.tsx index c167f36..71319ab 100644 --- a/app/admin/CreateLicenseNftWriteAccordion.tsx +++ b/app/admin/CreateLicenseNftWriteAccordion.tsx @@ -19,6 +19,7 @@ export default function CreateLicenseNftWriteAccordion({ message: 'Required.', }), ipaId: z.string().optional(), + // parentLicenseId: z.string().optional(), }); const createDescriptions = { diff --git a/app/admin/LicenseWriteAccordionInputForm.tsx b/app/admin/LicenseWriteAccordionInputForm.tsx index 3df5e21..0cc5a3e 100644 --- a/app/admin/LicenseWriteAccordionInputForm.tsx +++ b/app/admin/LicenseWriteAccordionInputForm.tsx @@ -237,15 +237,7 @@ export default function CreateLicenseWriteAccordionInputForm({ ipOrgId: form.getValues().ipOrgId, ipaId: form.getValues().ipaId || '0', parentLicenseId: '0', - params: [ - { - tag: 'Attribution', - value: { - interface: 'bool', - data: form.getValues().requireAttribution, - }, - }, - ], + params: [], txOptions: { waitForTransaction: true, }, diff --git a/app/ipo/[ipOrgId]/page.tsx b/app/ipo/[ipOrgId]/page.tsx index c661678..e84d280 100644 --- a/app/ipo/[ipOrgId]/page.tsx +++ b/app/ipo/[ipOrgId]/page.tsx @@ -36,11 +36,11 @@ export default function IpOrgDetailPage({ params: { ipOrgId } }: { params: { ipO ipOrgId, }; - const defaultCreateLicenseNftValues: CreateLicenseRequest = { + const defaultCreateLicenseValues: CreateLicenseRequest = { ipOrgId: defaultIPOrgId.ipOrgId, - ipaId: '', + ipaId: '0', params: [], - parentLicenseId: '', + parentLicenseId: '0', preHookData: [], postHookData: [], txOptions: { @@ -128,7 +128,7 @@ export default function IpOrgDetailPage({ params: { ipOrgId } }: { params: { ipO
diff --git a/components/views/IPOrg/IPOrgDataViewerComponent.tsx b/components/views/IPOrg/IPOrgDataViewerComponent.tsx index 6c4e12a..05d008f 100644 --- a/components/views/IPOrg/IPOrgDataViewerComponent.tsx +++ b/components/views/IPOrg/IPOrgDataViewerComponent.tsx @@ -43,18 +43,6 @@ const columns: ColumnDef[] = [ ), }, - // { - // accessorKey: 'tokenUri', - // header: 'TokenURI', - // cell: ({ row }) => { - // const uri: string = row.getValue('tokenUri'); - // return ( - // - // - // - // ); - // }, - // }, ]; export default function IPOrgDataViewerComponent({ From 40653a88cb07ba47de5d553554a0577259fa9ff8 Mon Sep 17 00:00:00 2001 From: Don <100505855+DonFungible@users.noreply.github.com> Date: Fri, 15 Dec 2023 17:22:09 -0500 Subject: [PATCH 4/5] fix create license missing param --- app/admin/ConfigureLicenseWriteAccordionInputForm.tsx | 3 +-- app/admin/LicenseWriteAccordionInputForm.tsx | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/admin/ConfigureLicenseWriteAccordionInputForm.tsx b/app/admin/ConfigureLicenseWriteAccordionInputForm.tsx index dc75281..2e9dc38 100644 --- a/app/admin/ConfigureLicenseWriteAccordionInputForm.tsx +++ b/app/admin/ConfigureLicenseWriteAccordionInputForm.tsx @@ -20,7 +20,7 @@ import { useAccount, useNetwork } from 'wagmi'; // import ConnectWalletButton from '@/components/Navbar/ConnectWalletButton2'; import { ConnectButton } from '@rainbow-me/rainbowkit'; import { cn } from '@/utils'; -import { ConfigureLicenseRequest, CreateLicenseRequest } from '@story-protocol/core-sdk'; +import { ConfigureLicenseRequest } from '@story-protocol/core-sdk'; type InputFormProps = { formSchema: z.ZodObject; @@ -250,7 +250,6 @@ export default function ConfigureLicenseWriteAccordionInputForm({ waitForTransaction: true, }, }; - console.log('Configuring license:', configureLicenseReq); const { execute, isIdle, isLoading, isSuccess, data, reset, errorMsg } = hook(configureLicenseReq); const IdleComponent = () => ( diff --git a/app/admin/LicenseWriteAccordionInputForm.tsx b/app/admin/LicenseWriteAccordionInputForm.tsx index 0cc5a3e..baaa459 100644 --- a/app/admin/LicenseWriteAccordionInputForm.tsx +++ b/app/admin/LicenseWriteAccordionInputForm.tsx @@ -232,17 +232,17 @@ export default function CreateLicenseWriteAccordionInputForm({ event.preventDefault(); await execute(); } - console.log('form state:', form.formState); const createLicenseReq: CreateLicenseRequest = { ipOrgId: form.getValues().ipOrgId, ipaId: form.getValues().ipaId || '0', parentLicenseId: '0', params: [], + preHookData: [], + postHookData: [], txOptions: { waitForTransaction: true, }, }; - console.log('Creating license:', createLicenseReq); const { execute, isIdle, isLoading, isSuccess, data, reset, errorMsg } = hook(createLicenseReq); const IdleComponent = () => ( From a7120a8d3b3d10fb68876fed178a73769b1fd69f Mon Sep 17 00:00:00 2001 From: Don <100505855+DonFungible@users.noreply.github.com> Date: Fri, 15 Dec 2023 17:24:34 -0500 Subject: [PATCH 5/5] cleanup --- ...ConfigureLicenseWriteAccordionInputForm.tsx | 18 +++++++++--------- app/admin/LicenseWriteAccordionInputForm.tsx | 15 +++++++-------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/app/admin/ConfigureLicenseWriteAccordionInputForm.tsx b/app/admin/ConfigureLicenseWriteAccordionInputForm.tsx index 2e9dc38..a99e950 100644 --- a/app/admin/ConfigureLicenseWriteAccordionInputForm.tsx +++ b/app/admin/ConfigureLicenseWriteAccordionInputForm.tsx @@ -1,10 +1,15 @@ 'use client'; -import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'; + +import { useEffect, useState } from 'react'; +import { ConfigureLicenseRequest } from '@story-protocol/core-sdk'; +import { useAccount, useNetwork } from 'wagmi'; +import { ConnectButton } from '@rainbow-me/rainbowkit'; +import * as z from 'zod'; import { useForm } from 'react-hook-form'; + +import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'; import { zodResolver } from '@hookform/resolvers/zod'; -import * as z from 'zod'; import { Input } from '@/components/ui/input'; -import { useEffect, useState } from 'react'; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'; import { Dialog, @@ -16,11 +21,7 @@ import { } from '@/components/ui/dialog'; import { ArrowPathIcon, CheckIcon, ExclamationCircleIcon, XCircleIcon } from '@heroicons/react/24/outline'; import EtherscanLink from '@/utils/EtherscanLink'; -import { useAccount, useNetwork } from 'wagmi'; -// import ConnectWalletButton from '@/components/Navbar/ConnectWalletButton2'; -import { ConnectButton } from '@rainbow-me/rainbowkit'; import { cn } from '@/utils'; -import { ConfigureLicenseRequest } from '@story-protocol/core-sdk'; type InputFormProps = { formSchema: z.ZodObject; @@ -41,10 +42,9 @@ function getDefaultValuesFromSchema( const values: Record = {}; for (const key in shape) { - values[key] = defaultValues[key] || ''; // Use the default value if available, or set an empty string as a fallback + values[key] = defaultValues[key] || ''; } - // Set default values for keys that are in defaultValues but not in the form schema for (const key in defaultValues) { if (!values[key]) { values[key] = defaultValues[key]; diff --git a/app/admin/LicenseWriteAccordionInputForm.tsx b/app/admin/LicenseWriteAccordionInputForm.tsx index baaa459..1896655 100644 --- a/app/admin/LicenseWriteAccordionInputForm.tsx +++ b/app/admin/LicenseWriteAccordionInputForm.tsx @@ -1,10 +1,13 @@ 'use client'; -import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'; +import { useEffect, useState } from 'react'; +import * as z from 'zod'; import { useForm } from 'react-hook-form'; +import { useAccount, useNetwork } from 'wagmi'; +import { ConnectButton } from '@rainbow-me/rainbowkit'; + +import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'; import { zodResolver } from '@hookform/resolvers/zod'; -import * as z from 'zod'; import { Input } from '@/components/ui/input'; -import { useEffect, useState } from 'react'; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'; import { Dialog, @@ -16,9 +19,6 @@ import { } from '@/components/ui/dialog'; import { ArrowPathIcon, CheckIcon, ExclamationCircleIcon, XCircleIcon } from '@heroicons/react/24/outline'; import EtherscanLink from '@/utils/EtherscanLink'; -import { useAccount, useNetwork } from 'wagmi'; -// import ConnectWalletButton from '@/components/Navbar/ConnectWalletButton2'; -import { ConnectButton } from '@rainbow-me/rainbowkit'; import { cn } from '@/utils'; import { CreateLicenseRequest } from '@story-protocol/core-sdk'; @@ -41,10 +41,9 @@ function getDefaultValuesFromSchema( const values: Record = {}; for (const key in shape) { - values[key] = defaultValues[key] || ''; // Use the default value if available, or set an empty string as a fallback + values[key] = defaultValues[key] || ''; } - // Set default values for keys that are in defaultValues but not in the form schema for (const key in defaultValues) { if (!values[key]) { values[key] = defaultValues[key];