Skip to content

Commit

Permalink
updates to latest sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
vilenarios committed Dec 6, 2024
1 parent 116cb02 commit 63d43b3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 34 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wayfinder",
"version": "0.0.12",
"version": "0.0.13",
"description": "WayFinder (alpha) is a simple, open source, Google Chrome extension that intelligently routes users to optimal AR.IO gateways, ensuring streamlined access to the permaweb on Arweave.",
"main": "dist/index.js",
"browser": "dist/index.js",
Expand Down Expand Up @@ -37,6 +37,6 @@
},
"homepage": "https://github.com/ar-io/wayfinder#readme",
"dependencies": {
"@ar.io/sdk": "^2.0.0"
"@ar.io/sdk": "^2.6.0"
}
}
55 changes: 33 additions & 22 deletions src/background.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { IO, Gateway, IO_TESTNET_PROCESS_ID, WalletAddress, AoGateway } from "@ar.io/sdk/web";

export type OnlineGateway = Gateway & {
import {
IO,
IO_TESTNET_PROCESS_ID,
WalletAddress,
AoGateway,
} from "@ar.io/sdk/web";

export type OnlineGateway = AoGateway & {
online?: boolean;
};

Expand All @@ -12,12 +17,10 @@ const HIGHEST_STAKE_ROUTE_METHOD = "highestStake";
const RANDOM_TOP_FIVE_STAKED_ROUTE_METHOD = "topFiveStake";
const MAX_HISTORY_ITEMS = 20;

const defaultGateway: Gateway = {
delegates: {},
end: 0,
observerWallet: "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs",
const defaultGateway: AoGateway = {
operatorStake: 250000000000,
settings: {
allowedDelegates: [],
allowDelegatedStaking: true,
autoStake: false,
delegateRewardShareRatio: 30,
Expand All @@ -29,17 +32,17 @@ const defaultGateway: Gateway = {
properties: "raJgvbFU-YAnku-WsupIdbTsqqGLQiYpGzoqk9SCVgY",
protocol: "https",
},
start: 1256694,
stats: {
failedConsecutiveEpochs: 0,
passedEpochCount: 114,
submittedEpochCount: 113,
totalEpochParticipationCount: 120,
totalEpochsPrescribedCount: 120,
passedConsecutiveEpochs: 0,
totalEpochCount: 0,
failedEpochCount: 0,
observedEpochCount: 0,
prescribedEpochCount: 0,
},
status: "joined",
totalDelegatedStake: 13868917608,
vaults: {},
weights: {
stakeWeight: 0,
tenureWeight: 0,
Expand All @@ -48,6 +51,12 @@ const defaultGateway: Gateway = {
observerRewardRatioWeight: 0,
compositeWeight: 0,
},
startTimestamp: 0,
endTimestamp: 0,
observerAddress: "IPdwa3Mb_9pDD8c2IaJx6aad51Ss-_TfStVwBuhtXMs",
services: {
bundlers: [],
},
};

// Set default values in Chrome storage
Expand Down Expand Up @@ -180,7 +189,7 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
* @param gateway The gateway object to check.
* @returns A promise that resolves to true if the gateway is online, otherwise false.
*/
async function isGatewayOnline(gateway: Gateway): Promise<boolean> {
async function isGatewayOnline(gateway: AoGateway): Promise<boolean> {
const url = `${gateway.settings.protocol}://${gateway.settings.fqdn}:${gateway.settings.port}/`;
const timeoutPromise = new Promise<never>((_, reject) =>
setTimeout(
Expand All @@ -196,7 +205,7 @@ async function isGatewayOnline(gateway: Gateway): Promise<boolean> {
]);
return (response as Response).ok;
} catch (error) {
console.error(error);
console.error(error);
return false;
}
}
Expand All @@ -208,8 +217,8 @@ async function isGatewayOnline(gateway: Gateway): Promise<boolean> {
async function refreshOnlineGateways(): Promise<Record<string, OnlineGateway>> {
const { garCache } = await chrome.storage.local.get(["garCache"]);
const promises = Object.entries(garCache).map(async ([address, gateway]) => {
const online = await isGatewayOnline(gateway as Gateway);
const onlineGateway: OnlineGateway = { ...(gateway as Gateway), online };
const online = await isGatewayOnline(gateway as AoGateway);
const onlineGateway: OnlineGateway = { ...(gateway as AoGateway), online };
return { address, gateway: onlineGateway };
});

Expand Down Expand Up @@ -259,7 +268,9 @@ async function getGatewayAddressRegistry(arIO: any): Promise<void> {
/**
* Fetch all gateways from the AR.IO SDK.
*/
const fetchAllGateways = async (): Promise<Record<WalletAddress, AoGateway>> => {
const fetchAllGateways = async (): Promise<
Record<WalletAddress, AoGateway>
> => {
const gateways: Record<WalletAddress, AoGateway> = {};
let cursor;
do {
Expand All @@ -269,18 +280,18 @@ const fetchAllGateways = async (): Promise<Record<WalletAddress, AoGateway>> =>
gateways[gatewayAddress] = gatewayData;
}
cursor = response.nextCursor;
} while (cursor)
} while (cursor);
return gateways;
}
};

/**
* Get an online gateway based on the configured routing method.
* @returns A promise that resolves to a gateway object.
*/
async function getOnlineGateway(): Promise<Gateway> {
async function getOnlineGateway(): Promise<AoGateway> {
const { staticGateway } = (await chrome.storage.local.get([
"staticGateway",
])) as { staticGateway?: Gateway };
])) as { staticGateway?: AoGateway };
if (staticGateway) {
console.log("Static gateway being used:", staticGateway.settings.fqdn);
return staticGateway;
Expand All @@ -302,7 +313,7 @@ async function getOnlineGateway(): Promise<Gateway> {
)
);

let gateway: Gateway | null = null;
let gateway: AoGateway | null = null;
switch (routingMethod) {
case RANDOM_TOP_FIVE_STAKED_ROUTE_METHOD:
gateway = selectRandomTopFiveStakedGateway(filteredGar);
Expand Down
12 changes: 6 additions & 6 deletions src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@ <h2>Gateway Details</h2>
href="https://github.com/ar-io/wayfinder"
target="_blank"
id="githubLink"
title="Wayfinder source code"
>GitHub</a
title="Wayfinder Source Code"
>Github</a
>
<a
href="https://viewblock.io/arweave/contract/bLAgYxAdX2Ry-nt6aH2ixgvJXbpsEYm28NgJgyqfs-U"
href="https://github.com/ar-io/ar-io-network-process"
target="_blank"
id="contractLink"
title="SmartWeave Contract"
>Contract</a
id="contractCodeLink"
title="AR.IO Network Testnet AO Process"
>Network</a
>
</footer>
</body>
Expand Down
6 changes: 2 additions & 4 deletions src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,8 @@ async function showMoreGatewayInfo(gateway: AoGateway, address: string) {
// Convert observerRewardRatioWeight to percentage and format to one decimal place
modalORR.textContent = `${orr}%`;

const grr = gateway.stats.totalEpochParticipationCount
? (gateway.stats.passedEpochCount /
gateway.stats.totalEpochParticipationCount) *
100
const grr = gateway.stats.totalEpochCount
? (gateway.stats.passedEpochCount / gateway.stats.totalEpochCount) * 100
: 100;

// Convert gatewayRewardRatioWeight to percentage and format to one decimal place
Expand Down

0 comments on commit 63d43b3

Please sign in to comment.