@ar.io/wayfinder-react 0.0.5-alpha.4 → 0.0.5-alpha.6
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 +8 -6
- package/dist/cache/index.d.ts +17 -0
- package/dist/cache/index.js +17 -0
- package/dist/cache/local-storage.d.ts +32 -0
- package/dist/cache/local-storage.js +69 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -23,10 +23,9 @@ yarn add @ar.io/wayfinder-react @ar.io/wayfinder-core
|
|
|
23
23
|
```jsx
|
|
24
24
|
import {
|
|
25
25
|
WayfinderProvider,
|
|
26
|
-
useWayfinder,
|
|
27
26
|
useWayfinderRequest,
|
|
28
27
|
useWayfinderUrl,
|
|
29
|
-
|
|
28
|
+
LocalStorageGatewaysProvider,
|
|
30
29
|
} from '@ar.io/wayfinder-react';
|
|
31
30
|
import { NetworkGatewaysProvider } from '@ar.io/wayfinder-core';
|
|
32
31
|
import { ARIO } from '@ar.io/sdk';
|
|
@@ -37,10 +36,13 @@ function App() {
|
|
|
37
36
|
<WayfinderProvider
|
|
38
37
|
// pass in the wayfinder options
|
|
39
38
|
// https://github.com/ar-io/wayfinder/tree/alpha/packages/core#custom-configuration
|
|
40
|
-
gatewaysProvider={new
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
gatewaysProvider={new LocalStorageGatewaysProvider({
|
|
40
|
+
ttlSeconds: 3600, // cache the gateways locally for 1 hour to avoid unnecessary network requests
|
|
41
|
+
gatewaysProvider: new NetworkGatewaysProvider({
|
|
42
|
+
ario: ARIO.mainnet()
|
|
43
|
+
limit: 10,
|
|
44
|
+
sortBy: 'operatorStake',
|
|
45
|
+
}),
|
|
44
46
|
})}
|
|
45
47
|
>
|
|
46
48
|
<YourApp />
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WayFinder
|
|
3
|
+
* Copyright (C) 2022-2025 Permanent Data Solutions, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
export * from './local-storage.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WayFinder
|
|
3
|
+
* Copyright (C) 2022-2025 Permanent Data Solutions, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
export * from './local-storage.js';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WayFinder
|
|
3
|
+
* Copyright (C) 2022-2025 Permanent Data Solutions, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { GatewaysProvider } from '@ar.io/wayfinder-core';
|
|
18
|
+
export declare class LocalStorageGatewaysProvider implements GatewaysProvider {
|
|
19
|
+
private readonly storageKey;
|
|
20
|
+
private readonly defaultTtlSeconds;
|
|
21
|
+
private readonly gatewaysProvider;
|
|
22
|
+
private readonly ttlSeconds;
|
|
23
|
+
constructor({ ttlSeconds, gatewaysProvider, }: {
|
|
24
|
+
ttlSeconds?: number;
|
|
25
|
+
gatewaysProvider: GatewaysProvider;
|
|
26
|
+
});
|
|
27
|
+
getGateways(): Promise<URL[]>;
|
|
28
|
+
private getCachedGateways;
|
|
29
|
+
private isCacheValid;
|
|
30
|
+
private cacheGateways;
|
|
31
|
+
clearCache(): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export class LocalStorageGatewaysProvider {
|
|
2
|
+
storageKey = 'wayfinder-gateways-cache';
|
|
3
|
+
defaultTtlSeconds = 3600; // 1 hour default
|
|
4
|
+
gatewaysProvider;
|
|
5
|
+
ttlSeconds;
|
|
6
|
+
constructor({ ttlSeconds = 300, gatewaysProvider, }) {
|
|
7
|
+
this.gatewaysProvider = gatewaysProvider;
|
|
8
|
+
this.ttlSeconds = ttlSeconds;
|
|
9
|
+
this.gatewaysProvider = gatewaysProvider;
|
|
10
|
+
}
|
|
11
|
+
async getGateways() {
|
|
12
|
+
const cached = this.getCachedGateways();
|
|
13
|
+
if (cached && this.isCacheValid(cached)) {
|
|
14
|
+
return cached.gateways;
|
|
15
|
+
}
|
|
16
|
+
const gateways = await this.gatewaysProvider.getGateways();
|
|
17
|
+
this.cacheGateways(gateways);
|
|
18
|
+
return gateways;
|
|
19
|
+
}
|
|
20
|
+
getCachedGateways() {
|
|
21
|
+
try {
|
|
22
|
+
if (typeof window === 'undefined' || !window.localStorage) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const cached = window.localStorage.getItem(this.storageKey);
|
|
26
|
+
if (!cached) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return JSON.parse(cached);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.warn('Failed to retrieve cached gateways:', error);
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
isCacheValid(cached) {
|
|
37
|
+
const now = Date.now();
|
|
38
|
+
const cacheAge = now - cached.timestamp;
|
|
39
|
+
const ttlMs = (cached.ttlSeconds || this.defaultTtlSeconds) * 1000;
|
|
40
|
+
return cacheAge < ttlMs;
|
|
41
|
+
}
|
|
42
|
+
cacheGateways(gateways) {
|
|
43
|
+
try {
|
|
44
|
+
if (typeof window === 'undefined' || !window.localStorage) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const cached = {
|
|
48
|
+
gateways,
|
|
49
|
+
timestamp: Date.now(),
|
|
50
|
+
ttlSeconds: this.ttlSeconds,
|
|
51
|
+
};
|
|
52
|
+
window.localStorage.setItem(this.storageKey, JSON.stringify(cached));
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.warn('Failed to cache gateways:', error);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
clearCache() {
|
|
59
|
+
try {
|
|
60
|
+
if (typeof window === 'undefined' || !window.localStorage) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
window.localStorage.removeItem(this.storageKey);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.warn('Failed to clear gateway cache:', error);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
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.6",
|
|
4
4
|
"description": "React components for WayFinder",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -10,7 +10,12 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"files": [
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"package.json",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
14
19
|
"author": {
|
|
15
20
|
"name": "Permanent Data Solutions Inc",
|
|
16
21
|
"email": "info@ar.io",
|
|
@@ -30,7 +35,7 @@
|
|
|
30
35
|
"format:check": "biome format"
|
|
31
36
|
},
|
|
32
37
|
"dependencies": {
|
|
33
|
-
"@ar.io/wayfinder-core": "0.0.5-alpha.
|
|
38
|
+
"@ar.io/wayfinder-core": "0.0.5-alpha.5",
|
|
34
39
|
"react": "^18.2.0",
|
|
35
40
|
"react-dom": "^18.2.0"
|
|
36
41
|
},
|