66import {
77 Button ,
88 ButtonType ,
9+ Checkbox ,
910 Dialog ,
1011 DialogBody ,
1112 DialogContent ,
@@ -14,12 +15,16 @@ import {
1415 Header ,
1516 LoadingIndicator ,
1617 Panel ,
18+ Select ,
19+ SelectOption ,
1720} from '@iota/apps-ui-kit' ;
1821import { useCurrentAccount , useIotaClient , useSignAndExecuteTransaction } from '@iota/dapp-kit' ;
1922import { useMutation , useQueryClient } from '@tanstack/react-query' ;
23+ import { useState } from 'react' ;
2024
2125import { NameUpdate , queryKey , useUpdateNameTransaction } from '@/hooks' ;
2226import { useBalance } from '@/hooks/useBalance' ;
27+ import { useCoreConfig } from '@/hooks/useCoreConfig' ;
2328import { useNameRecord } from '@/hooks/useNameRecord' ;
2429import {
2530 GAS_BALANCE_TOO_LOW_ID ,
@@ -28,7 +33,7 @@ import {
2833} from '@/lib/constants' ;
2934import { formatNanosToIota } from '@/lib/utils' ;
3035import { denormalizeName } from '@/lib/utils/format/formatNames' ;
31- import { getDefaultExpirationDate } from '@/lib/utils/getDefaultExpirationDate ' ;
36+ import { getTargetExpirationDate } from '@/lib/utils/names ' ;
3237
3338type PurchaseNameProps = {
3439 name : string ;
@@ -41,11 +46,21 @@ export function PurchaseNameDialog({ name, open, setOpen, onPurchase }: Purchase
4146 const queryClient = useQueryClient ( ) ;
4247 const client = useIotaClient ( ) ;
4348 const account = useCurrentAccount ( ) ;
49+ const { data : coreConfig } = useCoreConfig ( ) ;
50+
51+ const [ renewYears , setRenewYears ] = useState < number > ( 1 ) ;
52+ const [ isDisplayName , setIsDisplayName ] = useState < boolean > ( false ) ;
53+
4454 const {
4555 data : nameRecordData ,
4656 isLoading : isNameRecordLoading ,
4757 error : nameRecordError ,
48- } = useNameRecord ( name ) ;
58+ } = useNameRecord ( name , {
59+ price : {
60+ years : renewYears ,
61+ isRegistration : true ,
62+ } ,
63+ } ) ;
4964
5065 const price = nameRecordData ?. type === 'available' ? nameRecordData ?. price : 0 ;
5166 const isConnected = ! ! account ?. address ;
@@ -57,7 +72,8 @@ export function PurchaseNameDialog({ name, open, setOpen, onPurchase }: Purchase
5772 type : 'register-name' ,
5873 name : name ,
5974 price : price ,
60- years : 1 ,
75+ years : renewYears ,
76+ setDefault : isDisplayName ,
6177 } ) ;
6278 }
6379
@@ -107,6 +123,13 @@ export function PurchaseNameDialog({ name, open, setOpen, onPurchase }: Purchase
107123
108124 if ( ! isConnected ) return null ;
109125
126+ const RENEW_OPTIONS : SelectOption [ ] = coreConfig ?. max_years
127+ ? Array . from ( { length : coreConfig ?. max_years } , ( _ , i ) => ( {
128+ id : String ( i + 1 ) ,
129+ label : `${ i + 1 } Year${ i ? 's' : '' } ` ,
130+ } ) )
131+ : [ ] ;
132+
110133 const totalBalance = Number ( coinBalance ?. totalBalance ) || 0 ;
111134 const totalGas = Number ( updateNameData ?. gasSummary ?. totalGas ) || 0 ;
112135 const totalPrice = nameRecordData ?. type === 'available' ? nameRecordData . price + totalGas : 0 ;
@@ -126,7 +149,8 @@ export function PurchaseNameDialog({ name, open, setOpen, onPurchase }: Purchase
126149 const canRegister = canPay && ! hasErrors && ! isLoading && ! isSendingTransaction ;
127150
128151 const cleanName = denormalizeName ( name ) ;
129- const expirationDate = getDefaultExpirationDate ( ) ;
152+
153+ const expirationDate = getTargetExpirationDate ( renewYears ) ;
130154
131155 return (
132156 < Dialog open = { open } onOpenChange = { setOpen } >
@@ -142,8 +166,27 @@ export function PurchaseNameDialog({ name, open, setOpen, onPurchase }: Purchase
142166 </ span >
143167 </ div >
144168 </ Panel >
169+ < div className = "px-md py-sm border-t border-names-neutral-6" >
170+ < Select
171+ value = { renewYears . toString ( ) }
172+ options = { RENEW_OPTIONS }
173+ onValueChange = { ( value ) => {
174+ setRenewYears ( parseInt ( value , 10 ) ) ;
175+ } }
176+ placeholder = "Select renewal period"
177+ />
178+ </ div >
145179 </ div >
146180 < div className = "flex flex-col w-full gap-y-md" >
181+ < Panel bgColor = "bg-names-neutral-10" >
182+ < div className = "flex flex-row gap-x-sm w-full p-md" >
183+ < Checkbox
184+ isChecked = { isDisplayName }
185+ onCheckedChange = { ( e ) => setIsDisplayName ( e . target . checked ) }
186+ label = "Set name as Display Name"
187+ />
188+ </ div >
189+ </ Panel >
147190 < div className = "flex flex-row gap-x-sm w-full" >
148191 < DisplayStats label = "Registration Expires" value = { expirationDate } />
149192 < DisplayStats
0 commit comments