@@ -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
259267export 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
356369const 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
363386export 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 >
0 commit comments