@@ -25,15 +25,15 @@ import {
2525} from '@iota/apps-ui-kit' ;
2626import { useCurrentAccount , useIotaClient , useSignAndExecuteTransaction } from '@iota/dapp-kit' ;
2727import { Transaction } from '@iota/iota-sdk/transactions' ;
28- import { IOTA_DECIMALS , NANOS_PER_IOTA } from '@iota/iota-sdk/utils' ;
28+ import { IOTA_DECIMALS } from '@iota/iota-sdk/utils' ;
2929import { useMutation , useQueryClient } from '@tanstack/react-query' ;
30- import { useState } from 'react' ;
30+ import { useEffect , useState } from 'react' ;
3131
3232import { useAuctionBid } from '@/auctions/hooks/useAuctionBid' ;
3333import { useCountdown } from '@/auctions/hooks/useCountdown' ;
3434import { useGetAuctionMetadata } from '@/auctions/hooks/useGetAuctionMetadata' ;
3535import { formatTimeRemaining , getTimeRemaining , getUserAuctionStatus } from '@/auctions/lib/utils' ;
36- import { queryKey } from '@/hooks' ;
36+ import { NameRecordData , queryKey , useNameRecord } from '@/hooks' ;
3737import { formatNanosToIota } from '@/lib/utils' ;
3838import { toNanos } from '@/lib/utils/amount' ;
3939import { formatExpirationDate } from '@/lib/utils/format/formatExpirationDate' ;
@@ -49,16 +49,28 @@ export function AuctionBidDialog({ name, closeDialog, onCompleted }: AuctionBidD
4949 const iotaClient = useIotaClient ( ) ;
5050 const account = useCurrentAccount ( ) ;
5151 const queryClient = useQueryClient ( ) ;
52+ const { data : nameRecordData , isLoading : isNameRecordLoading } = useNameRecord ( name ) ;
53+
54+ const nameRecord = nameRecordData as Extract < NameRecordData , { type : 'available' } > | undefined ;
5255 const { data : auctionMetadata } = useGetAuctionMetadata ( name ) ;
53- const minBidNanos = auctionMetadata ?. minBidNanos || NANOS_PER_IOTA ;
54- const [ bidAmountValue , setBidAmountValue ] = useState (
55- formatNanosToIota ( minBidNanos , {
56- formatRounded : false ,
57- showIotaSymbol : false ,
58- } ) ,
59- ) ;
56+ const minBidNanos =
57+ auctionMetadata ?. minBidNanos || ( nameRecord ? BigInt ( nameRecord . price ) : null ) ;
58+
59+ const [ bidAmountValue , setBidAmountValue ] = useState < string | undefined > ( ) ;
60+
61+ // Sync the minimum bid amount
62+ useEffect ( ( ) => {
63+ if ( minBidNanos ) {
64+ setBidAmountValue (
65+ formatNanosToIota ( minBidNanos , {
66+ formatRounded : false ,
67+ showIotaSymbol : false ,
68+ } ) ,
69+ ) ;
70+ }
71+ } , [ minBidNanos ] ) ;
6072
61- const bidNanos = toNanos ( bidAmountValue ) ;
73+ const bidNanos = bidAmountValue ? toNanos ( bidAmountValue ) : null ;
6274
6375 const {
6476 data : auctionBidTransaction ,
@@ -92,22 +104,40 @@ export function AuctionBidDialog({ name, closeDialog, onCompleted }: AuctionBidD
92104 } ,
93105 } ) ;
94106
95- const minBidLabel = formatNanosToIota ( minBidNanos , {
96- formatRounded : false ,
97- showIotaSymbol : true ,
98- } ) ;
107+ const status = auctionMetadata && getUserAuctionStatus ( auctionMetadata , account ?. address || '' ) ;
108+ const timeRemainingMs = auctionMetadata && getTimeRemaining ( auctionMetadata ) ;
109+ const { milliseconds } = useCountdown ( timeRemainingMs || 0 ) ;
99110
100- const minBidWithoutLabel = formatNanosToIota ( minBidNanos , {
101- formatRounded : false ,
102- showIotaSymbol : false ,
103- } ) ;
104111 const isBidAboveDecimals = bidNanos === null ;
105- const isBidBelowMinimum = ( bidNanos || BigInt ( 0 ) ) < minBidNanos ;
112+ const isBidBelowMinimum = minBidNanos ? ( bidNanos || BigInt ( 0 ) ) < minBidNanos : false ;
106113
107- const isLoading = isAuctionBidLoading || isSendingTransaction || isSigningTransaction ;
114+ const isLoading =
115+ isNameRecordLoading || isAuctionBidLoading || isSendingTransaction || isSigningTransaction ;
108116 const isPending = isAuctionBidPending ;
109117 const disablePlaceBid = isPending || isLoading || isBidBelowMinimum ;
110118
119+ const formattedTimeRemaining = formatTimeRemaining ( milliseconds ) ;
120+ const currentBid = auctionMetadata
121+ ? formatNanosToIota ( auctionMetadata . currentBidNanos , {
122+ formatRounded : false ,
123+ showIotaSymbol : true ,
124+ } )
125+ : '--' ;
126+ const expirationDate = auctionMetadata
127+ ? formatExpirationDate ( auctionMetadata . nftExpiration )
128+ : '--' ;
129+ const minBidLabel = minBidNanos
130+ ? formatNanosToIota ( minBidNanos , {
131+ formatRounded : false ,
132+ showIotaSymbol : true ,
133+ } )
134+ : '--' ;
135+ const minBidWithoutLabel = minBidNanos
136+ ? formatNanosToIota ( minBidNanos , {
137+ formatRounded : false ,
138+ showIotaSymbol : false ,
139+ } )
140+ : '--' ;
111141 const errorMessage = ( ( ) => {
112142 if ( isBidAboveDecimals ) {
113143 return `The value exceeds the maximum decimals (${ IOTA_DECIMALS } ).` ;
@@ -119,20 +149,6 @@ export function AuctionBidDialog({ name, closeDialog, onCompleted }: AuctionBidD
119149 } ) ( ) ;
120150 const cleanName = normalizeNameInput ( name ) ;
121151
122- const status = auctionMetadata && getUserAuctionStatus ( auctionMetadata , account ?. address || '' ) ;
123- const timeRemainingMs = auctionMetadata && getTimeRemaining ( auctionMetadata ) ;
124- const { milliseconds } = useCountdown ( timeRemainingMs || 0 ) ;
125-
126- const formattedTimeRemaining = formatTimeRemaining ( milliseconds ) ;
127- const currentBid = auctionMetadata
128- ? formatNanosToIota ( auctionMetadata . currentBidNanos , {
129- formatRounded : false ,
130- showIotaSymbol : true ,
131- } )
132- : '--' ;
133- const expirationDate = auctionMetadata
134- ? formatExpirationDate ( auctionMetadata . nftExpiration )
135- : '--' ;
136152 return (
137153 < Dialog open onOpenChange = { closeDialog } >
138154 < DialogContent containerId = "overlay-portal-container" position = { DialogPosition . Right } >
0 commit comments