Skip to content

Commit

Permalink
feat(restriction): add transfer restriction to fe (#1173)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbeckers authored Nov 8, 2023
1 parent 44baf47 commit a827b5e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
11 changes: 9 additions & 2 deletions frontend/components/hypercert-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { parseListFromString } from "../lib/parsing";
import { useConfetti } from "./confetti";
import { useContractModal } from "./contract-interaction-dialog-context";
import { DATE_INDEFINITE, DateIndefinite, FormContext } from "./forms";
import { formatHypercertData } from "@hypercerts-org/sdk";
import { TransferRestrictions, formatHypercertData } from "@hypercerts-org/sdk";
import { DataProvider } from "@plasmicapp/loader-nextjs";
import dayjs from "dayjs";
import { Formik, FormikProps } from "formik";
Expand Down Expand Up @@ -62,6 +62,7 @@ const DEFAULT_FORM_DATA: HypercertCreateFormData = {
backgroundColor: "",
backgroundVectorArt: "",
metadataProperties: "",
transferRestrictions: TransferRestrictions.FromCreatorOnly,
};

interface HypercertCreateFormData {
Expand Down Expand Up @@ -89,6 +90,7 @@ interface HypercertCreateFormData {
backgroundColor: string;
backgroundVectorArt: string;
metadataProperties: string;
transferRestrictions: TransferRestrictions;
}

/**
Expand Down Expand Up @@ -385,9 +387,14 @@ export function HypercertCreateForm(props: HypercertCreateFormProps) {
allowlistUrl: values.allowlistUrl,
allowlistPercentage: values.allowlistPercentage,
deduplicate: values.deduplicateAllowlist,
transferRestrictions: values.transferRestrictions,
});
} else {
await mintClaim(metaData.data, DEFAULT_NUM_FRACTIONS);
await mintClaim(
metaData.data,
DEFAULT_NUM_FRACTIONS,
values.transferRestrictions,
);
}
} else {
toast("Error creating hypercert. Please contact the team.", {
Expand Down
11 changes: 8 additions & 3 deletions frontend/hooks/mintClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const useMintClaim = ({ onComplete }: { onComplete?: () => void }) => {
const initializeWrite = async (
metaData: HypercertMetadata,
units: number,
transferRestrictions: TransferRestrictions,
) => {
setStep("minting");
try {
Expand All @@ -33,7 +34,7 @@ export const useMintClaim = ({ onComplete }: { onComplete?: () => void }) => {
const hash = await client.mintClaim(
metaData,
BigInt(units),
TransferRestrictions.FromCreatorOnly,
transferRestrictions,
);

const receipt = await publicClient?.waitForTransactionReceipt({
Expand Down Expand Up @@ -67,10 +68,14 @@ export const useMintClaim = ({ onComplete }: { onComplete?: () => void }) => {
};

return {
write: async (metaData: HypercertMetadata, units: number) => {
write: async (
metaData: HypercertMetadata,
units: number,
transferRestrictions: TransferRestrictions = TransferRestrictions.FromCreatorOnly,
) => {
showModal({ stepDescriptions });
setStep("preparing");
await initializeWrite(metaData, units);
await initializeWrite(metaData, units, transferRestrictions);
},
txPending,
readOnly: isLoading || !client || client.readonly,
Expand Down
6 changes: 5 additions & 1 deletion frontend/hooks/mintClaimAllowlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const useMintClaimAllowlist = ({
allowlistUrl: string,
allowlistPercentage: number,
deduplicate: boolean,
transferRestrictions: TransferRestrictions,
) => {
setStep("validateAllowlist");

Expand Down Expand Up @@ -126,7 +127,7 @@ export const useMintClaimAllowlist = ({
_allowlist,
metaData,
_totalSupply,
TransferRestrictions.FromCreatorOnly,
transferRestrictions,
);

const receipt = await publicClient?.waitForTransactionReceipt({
Expand Down Expand Up @@ -165,18 +166,21 @@ export const useMintClaimAllowlist = ({
allowlistUrl,
allowlistPercentage,
deduplicate,
transferRestrictions = TransferRestrictions.FromCreatorOnly,
}: {
metaData: HypercertMetadata;
allowlistUrl: string;
allowlistPercentage: number;
deduplicate: boolean;
transferRestrictions?: TransferRestrictions;
}) => {
showModal({ stepDescriptions });
await initializeWrite(
metaData,
allowlistUrl,
allowlistPercentage,
deduplicate,
transferRestrictions,
);
},
txPending,
Expand Down
10 changes: 10 additions & 0 deletions frontend/plasmic-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ PLASMIC.registerComponent(HypercertFetcher, {
importPath: "./components/hypercert-metadata-fetcher",
});

/**
* AllowAll: 0,
* DisallowAll: 1,
* FromCreatorOnly: 2,
*/
PLASMIC.registerComponent(HypercertCreateForm, {
name: "HypercertCreateForm",
description: "Create a hypercert",
Expand All @@ -233,6 +238,11 @@ PLASMIC.registerComponent(HypercertCreateForm, {
value: "Placeholder",
},
},
transferRestrictions: {
type: "choice",
options: ["AllowAll", "DisallowAll", "FromCreatorOnly"],
defaultValueHint: "FromCreatorOnly",
},
},
providesData: true,
importPath: "./components/hypercert-create",
Expand Down

0 comments on commit a827b5e

Please sign in to comment.