@ar.io/wayfinder-react 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,7 +37,8 @@ export class LocalStorageGatewaysProvider {
37
37
  const now = Date.now();
38
38
  const cacheAge = now - cached.timestamp;
39
39
  const ttlMs = (cached.ttlSeconds || this.defaultTtlSeconds) * 1000;
40
- return cacheAge < ttlMs;
40
+ const gatewaysCount = cached.gateways.length;
41
+ return cacheAge < ttlMs && gatewaysCount > 0;
41
42
  }
42
43
  cacheGateways(gateways) {
43
44
  try {
@@ -14,7 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { Wayfinder } from '@ar.io/wayfinder-core';
17
+ import { Wayfinder, WayfinderURLParams } from '@ar.io/wayfinder-core';
18
18
  import { type WayfinderContextValue } from '../components/wayfinder-provider.js';
19
19
  /**
20
20
  * Hook for getting the Wayfinder instance
@@ -31,11 +31,8 @@ export declare const useWayfinderRequest: () => Wayfinder["request"];
31
31
  * @param txId - The transaction ID to resolve
32
32
  * @returns Object containing the resolved URL and loading state
33
33
  */
34
- export declare const useWayfinderUrl: ({ txId }: {
35
- txId: string;
36
- }) => {
34
+ export declare const useWayfinderUrl: (params: WayfinderURLParams) => {
37
35
  resolvedUrl: string | null;
38
36
  isLoading: boolean;
39
37
  error: Error | null;
40
- txId: string;
41
38
  };
@@ -40,13 +40,13 @@ export const useWayfinderRequest = () => {
40
40
  * @param txId - The transaction ID to resolve
41
41
  * @returns Object containing the resolved URL and loading state
42
42
  */
43
- export const useWayfinderUrl = ({ txId }) => {
43
+ export const useWayfinderUrl = (params) => {
44
44
  const { wayfinder } = useWayfinder();
45
45
  const [resolvedUrl, setResolvedUrl] = useState(null);
46
46
  const [isLoading, setIsLoading] = useState(false);
47
47
  const [error, setError] = useState(null);
48
48
  useEffect(() => {
49
- if (!txId) {
49
+ if (!params) {
50
50
  setResolvedUrl(null);
51
51
  setError(null);
52
52
  return;
@@ -55,9 +55,7 @@ export const useWayfinderUrl = ({ txId }) => {
55
55
  setError(null);
56
56
  (async () => {
57
57
  try {
58
- const resolved = await wayfinder.resolveUrl({
59
- originalUrl: `ar://${txId}`,
60
- });
58
+ const resolved = await wayfinder.resolveUrl(params);
61
59
  setResolvedUrl(resolved.toString());
62
60
  }
63
61
  catch (err) {
@@ -67,6 +65,6 @@ export const useWayfinderUrl = ({ txId }) => {
67
65
  setIsLoading(false);
68
66
  }
69
67
  })();
70
- }, [txId, wayfinder]);
71
- return { resolvedUrl, isLoading, error, txId };
68
+ }, [params, wayfinder]);
69
+ return { resolvedUrl, isLoading, error };
72
70
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/wayfinder-react",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "React components for WayFinder",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",