33
44'use client' ;
55
6- import { Add , Info , Refresh , Warning } from '@iota/apps-ui-icons' ;
6+ import { Add , Info , Refresh } from '@iota/apps-ui-icons' ;
77import {
88 Badge ,
99 BadgeType ,
@@ -19,16 +19,14 @@ import {
1919} from '@iota/apps-ui-kit' ;
2020import { useCurrentAccount } from '@iota/dapp-kit' ;
2121import { normalizeIotaName } from '@iota/iota-names-sdk' ;
22+ import { useQueryClient } from '@tanstack/react-query' ;
2223import { useState } from 'react' ;
2324import toast from 'react-hot-toast' ;
2425
25- import { useAuctions } from '@/auctions' ;
26- import { groupUserAuctions , type AuctionCard } from '@/auctions/lib/utils/groupUserAuctions' ;
2726import { RenewSubnameDialog } from '@/components/dialogs/RenewSubameDialog' ;
28- import { ExtendedAuctionCard } from '@/components/name-card/ExtendedAuctionCard' ;
2927import { ExtendedNameCard } from '@/components/name-card/ExtendedNameCard' ;
3028import { CardSkeletonLoader } from '@/components/skeletons/CardSkeletonLoader' ;
31- import { useGetPublicName , useRefreshAuctions , useRegistrationNfts } from '@/hooks' ;
29+ import { useGetPublicName , useRegistrationNfts } from '@/hooks' ;
3230import { RegistrationNft } from '@/lib/interfaces' ;
3331import { useAvailabilityCheckDialog } from '@/stores/useAvailabilityCheckDialog' ;
3432
@@ -37,7 +35,7 @@ import { GroupedNamesFilter } from './filters';
3735
3836export default function MyNamesPage ( ) : JSX . Element {
3937 const { open } = useAvailabilityCheckDialog ( ) ;
40- const account = useCurrentAccount ( ) ;
38+ const queryClient = useQueryClient ( ) ;
4139
4240 const [ selectedNameForRenewal , setSelectedNameForRenewal ] = useState < RegistrationNft | null > (
4341 null ,
@@ -48,6 +46,7 @@ export default function MyNamesPage(): JSX.Element {
4846 const [ selectedFilter , setSelectedFilter ] = useState < GroupedNamesFilter > (
4947 GroupedNamesFilter . All ,
5048 ) ;
49+ const [ isRefreshing , setIsRefreshing ] = useState ( false ) ;
5150
5251 const {
5352 data : names ,
@@ -59,35 +58,19 @@ export default function MyNamesPage(): JSX.Element {
5958 error : isSubnamesErrored ,
6059 isLoading : isLoadingSubnames ,
6160 } = useRegistrationNfts ( 'subname' ) ;
62- const {
63- data : auctionDetails ,
64- error : isAuctionsErrored ,
65- isLoading : isLoadingAuctions ,
66- } = useAuctions ( {
67- type : 'user' ,
68- userAddress : account ?. address ,
69- status : 'all' ,
70- } ) ;
71-
72- const { isRefreshing, handleRefresh } = useRefreshAuctions ( auctionDetails ) ;
7361
7462 const address = useCurrentAccount ( ) ?. address ?? '' ;
7563 const { data : publicName } = useGetPublicName ( address ) ;
7664
77- const isLoadingCards = isLoadingAuctions || isLoadingSubnames || isLoadingRegistrations ;
78-
79- const groupedAuctions = groupUserAuctions ( auctionDetails , account ?. address ?? '' ) ;
65+ const isLoadingCards = isLoadingSubnames || isLoadingRegistrations ;
8066
81- const filteredNames : ( RegistrationNft | AuctionCard ) [ ] = ( ( ) => {
82- const auctionCards = groupedAuctions ?? [ ] ;
67+ const filteredNames : RegistrationNft [ ] = ( ( ) => {
8368 const namesRegistrations = names ?? [ ] ;
8469 const subnamesRegistrations = subnames ?? [ ] ;
8570
8671 switch ( selectedFilter ) {
8772 case GroupedNamesFilter . All :
88- return [ ...namesRegistrations , ...subnamesRegistrations , ...auctionCards ] ;
89- case GroupedNamesFilter . InAuction :
90- return auctionCards ;
73+ return [ ...namesRegistrations , ...subnamesRegistrations ] ;
9174 case GroupedNamesFilter . Names :
9275 return namesRegistrations ;
9376 case GroupedNamesFilter . Subnames :
@@ -100,13 +83,7 @@ export default function MyNamesPage(): JSX.Element {
10083 const totalItemsCount = filteredNames . length ;
10184
10285 const noCardToDisplay =
103- ! isLoadingCards &&
104- filteredNames . length === 0 &&
105- ! isAuctionsErrored &&
106- ! isNamesErrored &&
107- ! isSubnamesErrored ;
108-
109- const noAuctions = auctionDetails . every ( ( auction ) => auction . metadata === null ) ;
86+ ! isLoadingCards && filteredNames . length === 0 && ! isNamesErrored && ! isSubnamesErrored ;
11087
11188 function handleFilterSelect ( filter : GroupedNamesFilter ) : void {
11289 setSelectedFilter ( filter ) ;
@@ -130,6 +107,24 @@ export default function MyNamesPage(): JSX.Element {
130107 setRightPanelSelectedName ( null ) ;
131108 }
132109
110+ async function handleRefresh ( ) : Promise < void > {
111+ if ( isRefreshing ) return ;
112+
113+ setIsRefreshing ( true ) ;
114+ try {
115+ // Invalidate names and subnames queries to fetch fresh data
116+ await queryClient . invalidateQueries ( {
117+ queryKey : [ 'iota-name' , 'owned-objects' ] ,
118+ } ) ;
119+
120+ toast . success ( 'Refreshed successfully' ) ;
121+ } catch ( error ) {
122+ toast . error ( 'Failed to refresh data' ) ;
123+ } finally {
124+ setIsRefreshing ( false ) ;
125+ }
126+ }
127+
133128 return (
134129 < >
135130 < div className = "flex flex-row gap-md items-center pt-[80px] md:pt-0 btn-alt-bg" >
@@ -148,8 +143,7 @@ export default function MyNamesPage(): JSX.Element {
148143 } )
149144 }
150145 />
151- { selectedFilter === GroupedNamesFilter . InAuction ||
152- selectedFilter === GroupedNamesFilter . All ? (
146+ { selectedFilter === GroupedNamesFilter . All && (
153147 < Button
154148 type = { ButtonType . Outlined }
155149 icon = {
@@ -163,7 +157,7 @@ export default function MyNamesPage(): JSX.Element {
163157 disabled = { isRefreshing }
164158 testId = "refresh-button"
165159 />
166- ) : null }
160+ ) }
167161 </ div >
168162 </ div >
169163
@@ -177,7 +171,6 @@ export default function MyNamesPage(): JSX.Element {
177171 selected = { selectedFilter === value }
178172 onClick = { ( ) => handleFilterSelect ( value ) }
179173 disabled = {
180- ( value === GroupedNamesFilter . InAuction && noAuctions ) ||
181174 ( value === GroupedNamesFilter . Names && ! names ?. length ) ||
182175 ( value === GroupedNamesFilter . Subnames && ! subnames ?. length )
183176 }
@@ -191,22 +184,7 @@ export default function MyNamesPage(): JSX.Element {
191184 ) }
192185 </ div >
193186
194- { selectedFilter === GroupedNamesFilter . InAuction && ! isLoadingAuctions ? (
195- isAuctionsErrored || noAuctions ? (
196- < div className = "flex" >
197- < InfoBox
198- style = { InfoBoxStyle . Elevated }
199- type = { isAuctionsErrored ? InfoBoxType . Error : InfoBoxType . Default }
200- supportingText = {
201- isAuctionsErrored
202- ? 'Failed to load auctions. Please try again later.'
203- : "You haven't participated in any auctions yet."
204- }
205- icon = { isAuctionsErrored ? < Warning /> : < Info /> }
206- />
207- </ div >
208- ) : null
209- ) : noCardToDisplay ? (
187+ { noCardToDisplay ? (
210188 < div className = "flex" >
211189 < InfoBox
212190 style = { InfoBoxStyle . Elevated }
@@ -226,32 +204,21 @@ export default function MyNamesPage(): JSX.Element {
226204 { ( ( ! isLoadingCards && filteredNames . length > 0 ) || rightPanelSelectedName ) && (
227205 < div className = "flex flex-row items-start justify-between gap-xl" >
228206 < div className = "gap-lg w-full flex flex-row flex-wrap items-center justify-center sm:justify-start" >
229- { filteredNames . map ( ( nft ) =>
230- 'details' in nft ? (
231- < ExtendedAuctionCard
232- key = { nft . details . name }
233- name = { nft . details . name }
234- auctionDetails = { nft . details }
235- />
236- ) : (
237- < ExtendedNameCard
238- key = { nft . name }
239- nft = { nft }
240- onSubnameListClick = { ( ) => {
241- setRightPanelSelectedName ( nft ) ;
242- } }
243- isActive = { rightPanelSelectedName ?. name === nft . name }
244- badge = {
245- isPublicName ( nft ) ? (
246- < Badge
247- type = { BadgeType . PrimarySolid }
248- label = "Public Name"
249- />
250- ) : null
251- }
252- />
253- ) ,
254- ) }
207+ { filteredNames . map ( ( nft ) => (
208+ < ExtendedNameCard
209+ key = { nft . name }
210+ nft = { nft }
211+ onSubnameListClick = { ( ) => {
212+ setRightPanelSelectedName ( nft ) ;
213+ } }
214+ isActive = { rightPanelSelectedName ?. name === nft . name }
215+ badge = {
216+ isPublicName ( nft ) ? (
217+ < Badge type = { BadgeType . PrimarySolid } label = "Public Name" />
218+ ) : null
219+ }
220+ />
221+ ) ) }
255222 </ div >
256223
257224 { rightPanelSelectedName && (
0 commit comments