diff --git a/src/background.ts b/src/background.ts index a691ff5..bb49832 100644 --- a/src/background.ts +++ b/src/background.ts @@ -1,4 +1,4 @@ -import { IO, Gateway, IO_TESTNET_PROCESS_ID } from "@ar.io/sdk/web"; +import { IO, Gateway, IO_TESTNET_PROCESS_ID, WalletAddress, AoGateway } from "@ar.io/sdk/web"; export type OnlineGateway = Gateway & { online?: boolean; @@ -196,7 +196,7 @@ async function isGatewayOnline(gateway: Gateway): Promise { ]); return (response as Response).ok; } catch (error) { - console.log((error as Error).message); // Log the error + console.error(error); return false; } } @@ -214,7 +214,6 @@ async function refreshOnlineGateways(): Promise> { }); const results = await Promise.allSettled(promises); - console.log(results); results.forEach((result) => { if (result.status === "fulfilled") { garCache[result.value.address] = result.value.gateway; @@ -234,7 +233,8 @@ async function getGatewayAddressRegistry(arIO: any): Promise { "Getting the gateways with the SDK and Process Id: ", processId ); - const garCache = await arIO.getGateways(); + + const garCache = await fetchAllGateways(); await chrome.storage.local.set({ garCache }); console.log( `Found ${ @@ -256,6 +256,25 @@ async function getGatewayAddressRegistry(arIO: any): Promise { } } +/** + * Fetch all gateways from the AR.IO SDK. + */ +const fetchAllGateways = async (): Promise> => { + const gateways: Record = {}; + let hasNextPage = true; + let page = 1; + while (hasNextPage) { + const response = await arIO.getGateways({ page }); + for (const gateway of response.items) { + const { gatewayAddress, ...gatewayData } = gateway; + gateways[gatewayAddress] = gatewayData; + } + hasNextPage = response.hasNextPage; + page++; + } + return gateways; +} + /** * Get an online gateway based on the configured routing method. * @returns A promise that resolves to a gateway object.