Skip to content

Commit 437c973

Browse files
committed
fix review
1 parent 0edb8c7 commit 437c973

File tree

1 file changed

+9
-29
lines changed

1 file changed

+9
-29
lines changed

src/lib/massa-react/hooks/useResolveDeweb.ts

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,48 @@
11
import { useState, useEffect } from 'react';
2-
import { CHAIN_ID, resolveDeweb } from '@massalabs/massa-web3';
2+
import { resolveDeweb } from '@massalabs/massa-web3';
33

44
interface UseResolveDewebResult {
55
resolvedUrl: string;
66
isLoading: boolean;
77
error: string | null;
88
}
99

10-
interface UseResolveDewebOptions {
11-
fallbackUrl?: string;
12-
shouldResolve?: boolean;
13-
chainId?: bigint;
14-
}
15-
1610
/**
1711
* Custom hook to resolve DeWeb URLs using the massa-web3 resolveDeweb function
18-
* @param originalUrl - The original URL to resolve (should contain massa.network domains)
19-
* @param options - Optional configuration
12+
* @param Url - The original URL to resolve (should contain massa.network domains)
13+
* @param chainId - The chain ID to resolve the URL on
2014
* @returns Object containing the resolved URL, loading state, and error state
2115
*/
2216
export function useResolveDeweb(
23-
originalUrl: string,
24-
options: UseResolveDewebOptions = {},
17+
Url: string,
18+
chainId: bigint,
2519
): UseResolveDewebResult {
26-
const {
27-
fallbackUrl = originalUrl,
28-
shouldResolve = true,
29-
chainId = CHAIN_ID.Mainnet,
30-
} = options;
31-
32-
const [resolvedUrl, setResolvedUrl] = useState<string>(fallbackUrl);
33-
const [isLoading, setIsLoading] = useState<boolean>(shouldResolve);
20+
const [resolvedUrl, setResolvedUrl] = useState<string>(Url);
21+
const [isLoading, setIsLoading] = useState<boolean>(false);
3422
const [error, setError] = useState<string | null>(null);
3523

3624
useEffect(() => {
37-
// Only resolve if shouldResolve is true and URL contains massa.network
38-
if (!shouldResolve) {
39-
setResolvedUrl(originalUrl);
40-
setIsLoading(false);
41-
return;
42-
}
43-
4425
const resolveUrl = async () => {
4526
try {
4627
setIsLoading(true);
4728
setError(null);
4829

4930
// Extract the path from the original URL to pass to resolveDeweb
50-
const pathToResolve = extractMNSUrl(originalUrl);
31+
const pathToResolve = extractMNSUrl(Url);
5132

5233
const resolved = await resolveDeweb(pathToResolve, chainId);
5334
setResolvedUrl(resolved);
5435
} catch (err) {
5536
const errorMessage =
5637
err instanceof Error ? err.message : 'Failed to resolve DeWeb URL';
5738
setError(errorMessage);
58-
setResolvedUrl(fallbackUrl);
5939
} finally {
6040
setIsLoading(false);
6141
}
6242
};
6343

6444
resolveUrl();
65-
}, [originalUrl, fallbackUrl, shouldResolve, chainId]);
45+
}, [Url, chainId]);
6646

6747
return {
6848
resolvedUrl,

0 commit comments

Comments
 (0)