forked from wanderwallet/Wander
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39d591d
commit 43767d2
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { defaultGateway, Gateway } from "./gateway"; | ||
import { useEffect, useState } from "react"; | ||
|
||
/** | ||
* Selects the appropriate gateway for the provided usecase. | ||
*/ | ||
export async function findGateway( | ||
requirements: Requirements | ||
): Promise<Gateway> {} | ||
|
||
/** | ||
* Gateway hook that uses wayfinder to select the active gateway. | ||
*/ | ||
export function useGateway(requirements: Requirements) { | ||
// currently active gw | ||
const [activeGateway, setActiveGateway] = useState<Gateway>(defaultGateway); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
try { | ||
// select recommended gateway using wayfinder | ||
const recommended = await findGateway(requirements); | ||
|
||
setActiveGateway(recommended); | ||
} catch {} | ||
})(); | ||
}, [requirements]); | ||
|
||
return activeGateway; | ||
} | ||
|
||
interface Requirements { | ||
/* Whether the gateway should support GraphQL requests */ | ||
graphql?: boolean; | ||
/* Should the gateway support ArNS */ | ||
arns?: boolean; | ||
/** | ||
* The block where the gateway should start syncing data from. | ||
* Set for 0 to include all blocks. | ||
* If undefined, wayfinder will not ensure that the start block | ||
* is 0. | ||
*/ | ||
startBlock?: number; | ||
/** | ||
* Ensure that the gateway has a high stake. This is required | ||
* with data that is important to be accurate. If true, wayfinder | ||
* will make sure that the gateway stake is higher than the | ||
* average stake of ar.io nodes. | ||
*/ | ||
ensureStake?: boolean; | ||
} |