From d82d93fb4a2b355d63ce6a9e84c1b10e2738da8b Mon Sep 17 00:00:00 2001 From: bitbeckers Date: Sun, 26 Nov 2023 11:13:44 +0100 Subject: [PATCH] feat(rights): add rights as props --- frontend/components/hypercert-create.tsx | 28 +++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/frontend/components/hypercert-create.tsx b/frontend/components/hypercert-create.tsx index 98b37b6a..d2c4062e 100644 --- a/frontend/components/hypercert-create.tsx +++ b/frontend/components/hypercert-create.tsx @@ -8,7 +8,7 @@ import { DataProvider } from "@plasmicapp/loader-nextjs"; import dayjs from "dayjs"; import { Formik, FormikProps } from "formik"; import html2canvas from "html2canvas"; -import _ from "lodash"; +import _, { get } from "lodash"; import { useRouter } from "next/router"; import qs from "qs"; import React, { ReactNode } from "react"; @@ -377,6 +377,7 @@ export function HypercertCreateForm(props: HypercertCreateFormProps) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion address!, applicationName, + transferRestrictions, image, ); console.log(`Metadata(valid=${metaData.valid}): `, metaData.data); @@ -440,10 +441,28 @@ export function HypercertCreateForm(props: HypercertCreateFormProps) { ); } +const getTransferRights = (transferRestrictions: TransferRestrictions) => { + // enum TransferRestrictions { + // AllowAll, + // DisallowAll, + // FromCreatorOnly + // } + if (transferRestrictions === 0) { + return "Allow All Transfers"; + } + if (transferRestrictions === 1) { + return "Disallow All Transfers"; + } + if (transferRestrictions === 2) { + return "Transfer From Creator Only"; + } +}; + const formatValuesToMetaData = ( val: HypercertCreateFormData, address: string, applicationName: string, + transferRestrictions: TransferRestrictions, image?: string, ) => { // Split contributor names and addresses. @@ -477,12 +496,19 @@ const formatValuesToMetaData = ( ? new Date(val.workTimeEnd).getTime() / 1000 : 0; + const transferRights = getTransferRights(transferRestrictions); + const rightsProps = [...val.rights, transferRights]; + let properties = [ { trait_type: "Minted by", value: "true", application: applicationName, }, + { + trait_type: "Rights", + value: rightsProps.join(", "), + }, ]; if (val.metadataProperties) { try {