-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
158 additions
and
207 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './lib/hooks'; | ||
export * from './lib/providers'; | ||
export * from './lib/components/SignatureOnMounted'; |
14 changes: 2 additions & 12 deletions
14
packages/@justaname.id/react/src/lib/components/SignatureOnMounted.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 37 additions & 46 deletions
83
packages/@justaname.id/react/src/lib/hooks/useCommunitySubnames.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,57 @@ | ||
import { SubnameGetAllByDomainChainIdResponse } from '@justaname.id/sdk'; | ||
import { | ||
QueryObserverResult, | ||
RefetchOptions, | ||
useQuery, | ||
} from '@tanstack/react-query'; | ||
import { InfiniteData, useInfiniteQuery, UseInfiniteQueryResult } from '@tanstack/react-query'; | ||
import { useJustaName } from '../providers'; | ||
import { SubnameGetAllByDomainChainIdResponse } from '@justaname.id/sdk'; | ||
|
||
export const buildCommunitySubnamesKey = (domainName: string | undefined) => [ | ||
'COMMUNITY_SUBNAMES_BY_ADDRESS', | ||
domainName, | ||
]; | ||
export interface UseCommunitySubnamesOptions { | ||
ensDomain: string; | ||
page?: number; | ||
limit?: number; | ||
isClaimed?: boolean; | ||
isClaimed: boolean; | ||
} | ||
|
||
interface UseCommunitySubnamesResult { | ||
communitySubnamesResponse: SubnameGetAllByDomainChainIdResponse; | ||
isLoading: boolean; | ||
refetchCommunitySubnames: ( | ||
options?: RefetchOptions | undefined | ||
) => Promise< | ||
QueryObserverResult< | ||
SubnameGetAllByDomainChainIdResponse | undefined, | ||
unknown | ||
> | ||
>; | ||
} | ||
export const useCommunitySubnames = ( | ||
props: UseCommunitySubnamesOptions | ||
): UseCommunitySubnamesResult => { | ||
): UseInfiniteQueryResult<InfiniteData<SubnameGetAllByDomainChainIdResponse, unknown>, Error> => { | ||
const { justaname, chainId } = useJustaName(); | ||
|
||
const query = useQuery({ | ||
return useInfiniteQuery({ | ||
queryKey: buildCommunitySubnamesKey(props.ensDomain), | ||
queryFn: async () => | ||
await justaname?.subnames.getCommunitySubnamesByDomain({ | ||
queryFn: ({ | ||
pageParam: { page, limit }, | ||
}) => { | ||
return justaname?.subnames.getCommunitySubnamesByDomain({ | ||
ensDomain: props.ensDomain, | ||
isClaimed: true, | ||
coinType: 60, | ||
isClaimed: props.isClaimed, | ||
chainId: chainId, | ||
}), | ||
enabled: Boolean(props.ensDomain) && Boolean(justaname), | ||
}); | ||
page, | ||
limit, | ||
}) | ||
}, | ||
initialPageParam: { | ||
page: 1, | ||
limit: 20, | ||
}, | ||
getNextPageParam: (p) => { | ||
if (p.pagination.hasNextPage) { | ||
return { | ||
page: p.pagination.nextPage ?? 1, | ||
limit: 20, | ||
}; | ||
} | ||
|
||
return { | ||
communitySubnamesResponse: query.data ?? { | ||
subnames: [], | ||
pagination: { | ||
totalCount: 0, | ||
page: 0, | ||
limit: 0, | ||
totalPages: 0, | ||
nextPage: 0, | ||
prevPage: 0, | ||
hasNextPage: false, | ||
hasPrevPage: false, | ||
}, | ||
return undefined; | ||
}, | ||
getPreviousPageParam: (p) => { | ||
if (p.pagination.hasPrevPage) { | ||
return { | ||
page: p.pagination.prevPage ?? 1, | ||
limit: 20, | ||
}; | ||
} | ||
return undefined; | ||
}, | ||
isLoading: query.isLoading, | ||
refetchCommunitySubnames: query.refetch, | ||
}; | ||
enabled: Boolean(props.ensDomain) && Boolean(justaname), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.