Skip to content

Commit

Permalink
feat: wayfinder skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
martonlederer committed Sep 27, 2023
1 parent 39d591d commit 43767d2
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/gateways/wayfinder.ts
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;
}

0 comments on commit 43767d2

Please sign in to comment.