Skip to content

Commit

Permalink
replace node-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
timbrinded committed Jul 4, 2024
1 parent c302ee3 commit 32beb73
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
4 changes: 4 additions & 0 deletions packages/cli/src/internal/cmdFunctions/downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ export async function downloader(url: string, outputPath: string): Promise<void>
const writeStream = fs.createWriteStream(tempPath);
let transferredBytes = 0;

if (url.startsWith("ws")) {
console.log("you've passed a websocket to fetch, is this intended?");
}

const response = await fetch(url);

if (!response.body) {
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/internal/cmdFunctions/fetchArtifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export async function fetchArtifact(args: fetchArtifactArgs) {
throw new Error(`No releases found for ${repo.ghAuthor}.${repo.ghRepo}, try again later.`);
}

// const releases = (await (await fetch(url)).json()) as Release[];
const release = binary.includes("-runtime")
? releases.data.find((release) => {
if (args.ver === "latest") {
Expand Down
9 changes: 6 additions & 3 deletions packages/cli/src/lib/rpcFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { vitestAutoUrl } from "../internal/providerFactories";
import { getEnvironmentFromConfig } from "./configReader";
import fetch from "node-fetch";

export async function customDevRpcRequest(method: string, params: any[] = []): Promise<any> {
const env = getEnvironmentFromConfig();
const endpoint = env.connections
? env.connections[0].endpoints[0].replace("ws://", "http://")
: vitestAutoUrl().replace("ws://", "http://").replace("wss://", "https://");
? env.connections[0].endpoints[0].replaceAll("ws://", "http://")
: vitestAutoUrl().replaceAll("ws://", "http://").replaceAll("wss://", "https://");
const data = {
jsonrpc: "2.0",
id: 1,
method,
params,
};

if (endpoint.startsWith("ws")) {
console.log("you've passed a websocket to fetch, is this intended?");
}

const response = await fetch(endpoint, {
method: "POST",
body: JSON.stringify(data),
Expand Down
1 change: 0 additions & 1 deletion packages/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
"ethers": "6.13.1",
"inquirer": "9.3.3",
"inquirer-press-to-continue": "1.2.0",
"node-fetch": "3.3.2",
"rlp": "3.0.0",
"semver": "7.6.2",
"viem": "2.17.0",
Expand Down
5 changes: 4 additions & 1 deletion packages/util/src/functions/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import "@moonbeam-network/api-augment";
import { BN } from "@polkadot/util";
import fetch from "node-fetch";

// Sort dict by key
export function sortObjectByKeys(obj: Record<string, any>): Record<string, any> {
Expand Down Expand Up @@ -124,6 +123,10 @@ export async function directRpcRequest(
params,
};

if (endpoint.startsWith("ws")) {
console.log("you've passed a websocket to fetch, is this intended?");
}

const response = await fetch(endpoint, {
method: "POST",
body: JSON.stringify(data),
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 32beb73

Please sign in to comment.