Skip to content

Commit

Permalink
revert: client/src/helpers/hooks/useAliasDetails.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
begonaalvarezd committed Jan 31, 2024
1 parent 14eef60 commit 764e4ec
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions client/src/helpers/hooks/useAliasDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,30 @@ import { HexHelper } from "../stardust/hexHelper";
*/
export function useAliasDetails(network: string, aliasId: string | null): [AliasOutput | null, boolean] {
const isMounted = useIsMounted();
const [apiClient] = useState(ServiceFactory.get<StardustApiClient>(`api-client-${STARDUST}`));
const [aliasOutput, setAliasOutput] = useState<AliasOutput | null>(null);
const [isLoading, setIsLoading] = useState<boolean>(true);

useEffect(() => {
setIsLoading(true);
if (aliasId && isMounted) {
if (aliasId) {
// eslint-disable-next-line no-void
void (async () => {
try {
const aliasOutput = await fetchAliasDetailsOutput(network, aliasId);
setAliasOutput(aliasOutput);
} finally {
setIsLoading(false);
}
apiClient
.aliasDetails({
network,
aliasId: HexHelper.addPrefix(aliasId),
})
.then((response) => {
if (!response?.error && isMounted) {
const output = response.aliasDetails?.output as AliasOutput;

setAliasOutput(output);
}
})
.finally(() => {
setIsLoading(false);
});
})();
} else {
setIsLoading(false);
Expand All @@ -36,22 +46,3 @@ export function useAliasDetails(network: string, aliasId: string | null): [Alias

return [aliasOutput, isLoading];
}

export const fetchAliasDetailsOutput = async (network: string, aliasId: string | null): Promise<AliasOutput | null> => {
if (!aliasId) {
return null;
}

const apiClient = ServiceFactory.get<StardustApiClient>(`api-client-${STARDUST}`);

const response = await apiClient.aliasDetails({
network,
aliasId: HexHelper.addPrefix(aliasId),
});

if (!response?.error) {
return response.aliasDetails?.output as AliasOutput;
}

return null;
};

0 comments on commit 764e4ec

Please sign in to comment.