@ar.io/wayfinder-react 0.0.5-alpha.2 → 0.0.5-alpha.4
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.
- package/README.md +41 -11
- package/dist/hooks/index.d.ts +23 -1
- package/dist/hooks/index.js +44 -1
- package/package.json +3 -8
package/README.md
CHANGED
|
@@ -25,6 +25,8 @@ import {
|
|
|
25
25
|
WayfinderProvider,
|
|
26
26
|
useWayfinder,
|
|
27
27
|
useWayfinderRequest,
|
|
28
|
+
useWayfinderUrl,
|
|
29
|
+
useWayfinderData,
|
|
28
30
|
} from '@ar.io/wayfinder-react';
|
|
29
31
|
import { NetworkGatewaysProvider } from '@ar.io/wayfinder-core';
|
|
30
32
|
import { ARIO } from '@ar.io/sdk';
|
|
@@ -35,7 +37,11 @@ function App() {
|
|
|
35
37
|
<WayfinderProvider
|
|
36
38
|
// pass in the wayfinder options
|
|
37
39
|
// https://github.com/ar-io/wayfinder/tree/alpha/packages/core#custom-configuration
|
|
38
|
-
gatewaysProvider={new NetworkGatewaysProvider({
|
|
40
|
+
gatewaysProvider={new NetworkGatewaysProvider({
|
|
41
|
+
ario: ARIO.mainnet()
|
|
42
|
+
limit: 3,
|
|
43
|
+
sortBy: 'operatorStake',
|
|
44
|
+
})}
|
|
39
45
|
>
|
|
40
46
|
<YourApp />
|
|
41
47
|
</WayfinderProvider>
|
|
@@ -44,24 +50,48 @@ function App() {
|
|
|
44
50
|
|
|
45
51
|
// Use components
|
|
46
52
|
function YourComponent() {
|
|
47
|
-
const
|
|
48
|
-
|
|
53
|
+
const txId = 'your-transaction-id'; // Replace with actual txId
|
|
54
|
+
|
|
55
|
+
// Use custom hooks for URL resolution and data fetching
|
|
56
|
+
const request = useWayfinderRequest();
|
|
57
|
+
const { resolvedUrl, isLoading: urlLoading, error: urlError } = useWayfinderUrl({ txId });
|
|
49
58
|
|
|
50
|
-
//
|
|
51
|
-
const
|
|
59
|
+
// Use custom hooks for data fetching
|
|
60
|
+
const [data, setData] = useState<any>(null);
|
|
61
|
+
const [dataLoading, setDataLoading] = useState(false);
|
|
62
|
+
const [dataError, setDataError] = useState<Error | null>(null);
|
|
52
63
|
|
|
53
|
-
// request some data from arweave via wayfinder
|
|
54
64
|
useEffect(() => {
|
|
55
65
|
(async () => {
|
|
56
|
-
|
|
57
|
-
|
|
66
|
+
try {
|
|
67
|
+
setDataLoading(true);
|
|
68
|
+
setDataError(null);
|
|
69
|
+
// fetch the data for the txId using wayfinder
|
|
70
|
+
const response = await request(`ar://${txId}`, {
|
|
71
|
+
verificationSettings: {
|
|
72
|
+
enabled: true, // enable verification on the request
|
|
73
|
+
strict: true, // don't use the data if it's not verified
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
const data = await response.arrayBuffer(); // or response.json() if you want to parse the data as JSON
|
|
77
|
+
setData(data);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
setDataError(error as Error);
|
|
80
|
+
} finally {
|
|
81
|
+
setDataLoading(false);
|
|
82
|
+
}
|
|
58
83
|
})();
|
|
59
|
-
}, [
|
|
84
|
+
}, [request, txId]);
|
|
60
85
|
|
|
61
86
|
return (
|
|
62
87
|
<div>
|
|
63
|
-
|
|
64
|
-
<
|
|
88
|
+
{urlLoading && <p>Resolving URL...</p>}
|
|
89
|
+
{urlError && <p>Error resolving URL: {urlError.message}</p>}
|
|
90
|
+
{resolvedUrl && <a href={resolvedUrl}>View on WayFinder</a>}
|
|
91
|
+
<br />
|
|
92
|
+
{dataLoading && <p>Loading data...</p>}
|
|
93
|
+
{dataError && <p>Error loading data: {dataError.message}</p>}
|
|
94
|
+
<pre>{data}</pre>
|
|
65
95
|
</div>
|
|
66
96
|
);
|
|
67
97
|
}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -14,6 +14,28 @@
|
|
|
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
18
|
import { type WayfinderContextValue } from '../components/wayfinder-provider.js';
|
|
19
|
+
/**
|
|
20
|
+
* Hook for getting the Wayfinder instance
|
|
21
|
+
* @returns Wayfinder instance
|
|
22
|
+
*/
|
|
18
23
|
export declare const useWayfinder: () => WayfinderContextValue;
|
|
19
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Hook for getting the Wayfinder request function
|
|
26
|
+
* @returns Wayfinder request function
|
|
27
|
+
*/
|
|
28
|
+
export declare const useWayfinderRequest: () => Wayfinder["request"];
|
|
29
|
+
/**
|
|
30
|
+
* Hook for resolving a transaction ID to a WayFinder URL using the Wayfinder instance (e.g. txId -> https://<some-gateway>/txId)
|
|
31
|
+
* @param txId - The transaction ID to resolve
|
|
32
|
+
* @returns Object containing the resolved URL and loading state
|
|
33
|
+
*/
|
|
34
|
+
export declare const useWayfinderUrl: ({ txId }: {
|
|
35
|
+
txId: string;
|
|
36
|
+
}) => {
|
|
37
|
+
resolvedUrl: string | null;
|
|
38
|
+
isLoading: boolean;
|
|
39
|
+
error: Error | null;
|
|
40
|
+
txId: string;
|
|
41
|
+
};
|
package/dist/hooks/index.js
CHANGED
|
@@ -14,8 +14,12 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
import { useContext } from 'react';
|
|
17
|
+
import { useContext, useEffect, useState } from 'react';
|
|
18
18
|
import { WayfinderContext, } from '../components/wayfinder-provider.js';
|
|
19
|
+
/**
|
|
20
|
+
* Hook for getting the Wayfinder instance
|
|
21
|
+
* @returns Wayfinder instance
|
|
22
|
+
*/
|
|
19
23
|
export const useWayfinder = () => {
|
|
20
24
|
const context = useContext(WayfinderContext);
|
|
21
25
|
if (!context) {
|
|
@@ -23,7 +27,46 @@ export const useWayfinder = () => {
|
|
|
23
27
|
}
|
|
24
28
|
return context;
|
|
25
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* Hook for getting the Wayfinder request function
|
|
32
|
+
* @returns Wayfinder request function
|
|
33
|
+
*/
|
|
26
34
|
export const useWayfinderRequest = () => {
|
|
27
35
|
const { wayfinder } = useWayfinder();
|
|
28
36
|
return wayfinder.request;
|
|
29
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* Hook for resolving a transaction ID to a WayFinder URL using the Wayfinder instance (e.g. txId -> https://<some-gateway>/txId)
|
|
40
|
+
* @param txId - The transaction ID to resolve
|
|
41
|
+
* @returns Object containing the resolved URL and loading state
|
|
42
|
+
*/
|
|
43
|
+
export const useWayfinderUrl = ({ txId }) => {
|
|
44
|
+
const { wayfinder } = useWayfinder();
|
|
45
|
+
const [resolvedUrl, setResolvedUrl] = useState(null);
|
|
46
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
47
|
+
const [error, setError] = useState(null);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (!txId) {
|
|
50
|
+
setResolvedUrl(null);
|
|
51
|
+
setError(null);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
setIsLoading(true);
|
|
55
|
+
setError(null);
|
|
56
|
+
(async () => {
|
|
57
|
+
try {
|
|
58
|
+
const resolved = await wayfinder.resolveUrl({
|
|
59
|
+
originalUrl: `ar://${txId}`,
|
|
60
|
+
});
|
|
61
|
+
setResolvedUrl(resolved.toString());
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
setError(err instanceof Error ? err : new Error('Failed to resolve URL'));
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
setIsLoading(false);
|
|
68
|
+
}
|
|
69
|
+
})();
|
|
70
|
+
}, [txId, wayfinder]);
|
|
71
|
+
return { resolvedUrl, isLoading, error, txId };
|
|
72
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ar.io/wayfinder-react",
|
|
3
|
-
"version": "0.0.5-alpha.
|
|
3
|
+
"version": "0.0.5-alpha.4",
|
|
4
4
|
"description": "React components for WayFinder",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -10,12 +10,7 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"files": [
|
|
14
|
-
"dist",
|
|
15
|
-
"package.json",
|
|
16
|
-
"README.md",
|
|
17
|
-
"LICENSE"
|
|
18
|
-
],
|
|
13
|
+
"files": ["dist", "package.json", "README.md", "LICENSE"],
|
|
19
14
|
"author": {
|
|
20
15
|
"name": "Permanent Data Solutions Inc",
|
|
21
16
|
"email": "info@ar.io",
|
|
@@ -35,7 +30,7 @@
|
|
|
35
30
|
"format:check": "biome format"
|
|
36
31
|
},
|
|
37
32
|
"dependencies": {
|
|
38
|
-
"@ar.io/wayfinder-core": "0.0.5-alpha.
|
|
33
|
+
"@ar.io/wayfinder-core": "0.0.5-alpha.3",
|
|
39
34
|
"react": "^18.2.0",
|
|
40
35
|
"react-dom": "^18.2.0"
|
|
41
36
|
},
|