Skip to content

Commit 04ecaef

Browse files
committed
updated royalty to show percentages instead of bps
1 parent 5585def commit 04ecaef

File tree

3 files changed

+61
-25
lines changed

3 files changed

+61
-25
lines changed

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/modules/components/Claimable.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ function ClaimableModule(props: ModuleInstanceProps) {
7373
const [tokenId, setTokenId] = useState<string>("");
7474

7575
const isErc721 = props.contractInfo.name === "ClaimableERC721";
76+
const isErc20 = props.contractInfo.name === "ClaimableERC20";
7677
const isValidTokenId = positiveIntegerRegex.test(tokenId);
7778

7879
const primarySaleRecipientQuery = useReadContract(
@@ -241,6 +242,7 @@ function ClaimableModule(props: ModuleInstanceProps) {
241242
}}
242243
isOwnerAccount={!!ownerAccount}
243244
isErc721={isErc721}
245+
isErc20={isErc20}
244246
contractChainId={props.contract.chain.id}
245247
setTokenId={setTokenId}
246248
isValidTokenId={isValidTokenId}
@@ -256,6 +258,7 @@ export function ClaimableModuleUI(
256258
props: Omit<ModuleCardUIProps, "children" | "updateButton"> & {
257259
isOwnerAccount: boolean;
258260
isErc721: boolean;
261+
isErc20: boolean;
259262
contractChainId: number;
260263
setTokenId: Dispatch<SetStateAction<string>>;
261264
isValidTokenId: boolean;
@@ -295,7 +298,7 @@ export function ClaimableModuleUI(
295298
<Accordion type="single" collapsible className="-mx-1">
296299
<AccordionItem value="metadata" className="border-none">
297300
<AccordionTrigger className="border-border border-t px-1">
298-
Mint NFT
301+
Mint {props.isErc20 ? "Token" : "NFT"}
299302
</AccordionTrigger>
300303
<AccordionContent className="px-1">
301304
<MintNFTSection
@@ -835,7 +838,7 @@ function MintNFTSection(props: {
835838
name="quantity"
836839
render={({ field }) => (
837840
<FormItem className="flex-1">
838-
<FormLabel>quantity</FormLabel>
841+
<FormLabel>Quantity</FormLabel>
839842
<FormControl>
840843
<Input {...field} />
841844
</FormControl>

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/modules/components/Royalty.tsx

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ function RoyaltyModule(props: ModuleInstanceProps) {
6565
const setRoyaltyForTokenTx = setRoyaltyInfoForToken({
6666
contract: contract,
6767
recipient: values.recipient,
68-
bps: Number(values.bps),
68+
// BPS is 10_000 so we need to multiply by 100
69+
bps: Number(values.percentage) * 100,
6970
tokenId: BigInt(values.tokenId),
7071
});
7172

@@ -108,14 +109,14 @@ function RoyaltyModule(props: ModuleInstanceProps) {
108109
if (!ownerAccount) {
109110
throw new Error("Not an owner account");
110111
}
111-
const [defaultRoyaltyRecipient, defaultRoyaltyBps] =
112+
const [defaultRoyaltyRecipient, defaultRoyaltyPercentage] =
112113
defaultRoyaltyInfoQuery.data || [];
113114

114115
if (
115116
values.recipient &&
116-
values.bps &&
117+
values.percentage &&
117118
(values.recipient !== defaultRoyaltyRecipient ||
118-
Number(values.bps) !== defaultRoyaltyBps)
119+
Number(values.percentage) * 100 !== defaultRoyaltyPercentage)
119120
) {
120121
const setDefaultRoyaltyInfo = isErc721
121122
? RoyaltyERC721.setDefaultRoyaltyInfo
@@ -124,7 +125,7 @@ function RoyaltyModule(props: ModuleInstanceProps) {
124125
const setSaleConfigTx = setDefaultRoyaltyInfo({
125126
contract: contract,
126127
royaltyRecipient: values.recipient,
127-
royaltyBps: Number(values.bps),
128+
royaltyBps: Number(values.percentage) * 100,
128129
});
129130

130131
await sendAndConfirmTransaction({
@@ -250,10 +251,17 @@ const royaltyInfoFormSchema = z.object({
250251
}),
251252

252253
recipient: addressSchema,
253-
bps: z
254+
percentage: z
254255
.string()
255-
.min(1, { message: "Invalid BPS" })
256-
.refine((v) => Number(v) >= 0, { message: "Invalid BPS" }),
256+
.min(1, { message: "Invalid percentage" })
257+
.refine(
258+
(v) => {
259+
console.log("Number(v): ", Number(v));
260+
if (Number(v) === 0) return true;
261+
if (Number(v) >= 0.01 && Number(v) <= 100) return true;
262+
},
263+
{ message: "Invalid percentage" },
264+
),
257265
});
258266

259267
export type RoyaltyInfoFormValues = z.infer<typeof royaltyInfoFormSchema>;
@@ -267,7 +275,7 @@ function RoyaltyInfoPerTokenSection(props: {
267275
values: {
268276
tokenId: "",
269277
recipient: "",
270-
bps: "",
278+
percentage: "",
271279
},
272280
reValidateMode: "onChange",
273281
});
@@ -321,12 +329,17 @@ function RoyaltyInfoPerTokenSection(props: {
321329

322330
<FormField
323331
control={form.control}
324-
name="bps"
332+
name="percentage"
325333
render={({ field }) => (
326334
<FormItem>
327-
<FormLabel>BPS</FormLabel>
335+
<FormLabel>Percentage</FormLabel>
328336
<FormControl>
329-
<Input {...field} />
337+
<div className="flex items-center">
338+
<Input {...field} className="rounded-r-none border-r-0" />
339+
<div className="h-10 rounded-lg rounded-l-none border border-input px-3 py-2">
340+
%
341+
</div>
342+
</div>
330343
</FormControl>
331344
<FormMessage />
332345
</FormItem>
@@ -355,9 +368,19 @@ function RoyaltyInfoPerTokenSection(props: {
355368

356369
const defaultRoyaltyFormSchema = z.object({
357370
recipient: addressSchema,
358-
bps: z.string().refine((v) => v.length === 0 || Number(v) >= 0, {
359-
message: "Invalid BPS",
360-
}),
371+
percentage: z
372+
.string()
373+
.min(1, { message: "Invalid percentage" })
374+
.refine(
375+
(v) => {
376+
console.log("Number(v): ", Number(v));
377+
if (Number(v) === 0) return true;
378+
if (Number(v) >= 0.01 && Number(v) <= 100) return true;
379+
},
380+
{
381+
message: "Invalid percentage",
382+
},
383+
),
361384
});
362385

363386
export type DefaultRoyaltyFormValues = z.infer<typeof defaultRoyaltyFormSchema>;
@@ -367,14 +390,16 @@ function DefaultRoyaltyInfoSection(props: {
367390
update: (values: DefaultRoyaltyFormValues) => Promise<void>;
368391
contractChainId: number;
369392
}) {
370-
const [defaultRoyaltyRecipient, defaultRoyaltyBps] =
393+
const [defaultRoyaltyRecipient, defaultRoyaltyPercentage] =
371394
props.defaultRoyaltyInfo || [];
372395

373396
const form = useForm<DefaultRoyaltyFormValues>({
374397
resolver: zodResolver(defaultRoyaltyFormSchema),
375398
values: {
376399
recipient: defaultRoyaltyRecipient || "",
377-
bps: defaultRoyaltyBps ? String(defaultRoyaltyBps) : "",
400+
percentage: defaultRoyaltyPercentage
401+
? String(defaultRoyaltyPercentage / 100)
402+
: "",
378403
},
379404
reValidateMode: "onChange",
380405
});
@@ -414,12 +439,17 @@ function DefaultRoyaltyInfoSection(props: {
414439

415440
<FormField
416441
control={form.control}
417-
name="bps"
442+
name="percentage"
418443
render={({ field }) => (
419444
<FormItem>
420-
<FormLabel>Default Royalty BPS</FormLabel>
445+
<FormLabel>Default Royalty Percentage</FormLabel>
421446
<FormControl>
422-
<Input {...field} />
447+
<div className="flex items-center">
448+
<Input {...field} className="rounded-r-none border-r-0" />
449+
<div className="h-10 rounded-lg rounded-l-none border border-input px-3 py-2">
450+
%
451+
</div>
452+
</div>
423453
</FormControl>
424454
<FormMessage />
425455
</FormItem>

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/modules/components/Transferable.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,18 +237,21 @@ export function TransferableModuleUI(
237237

238238
{isRestricted && (
239239
<div className="w-full">
240-
{/* Warning - TODO add later */}
241-
{/* {formFields.fields.length === 0 && (
240+
{formFields.fields.length === 0 && (
242241
<Alert variant="warning">
243242
<CircleAlertIcon className="size-5 max-sm:hidden" />
244243
<AlertTitle className="max-sm:!pl-0">
245244
Nobody has permission to transfer tokens on this
246245
contract
247246
</AlertTitle>
248247
</Alert>
249-
)} */}
248+
)}
250249

251250
<div className="flex flex-col gap-3">
251+
<p className="text-muted-foreground text-sm">
252+
Accounts that may override the transfer restrictions
253+
</p>
254+
252255
{/* Addresses */}
253256
{formFields.fields.map((fieldItem, index) => (
254257
<div

0 commit comments

Comments
 (0)