Skip to content

Commit

Permalink
fix: refactor endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaswma committed Jul 3, 2024
1 parent a2bf901 commit 2a5b52a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/api/modules/dispatch/dispatch.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { DispatchResult } from "./index";
import { signedTxTags } from "../sign/tags";
import { getActiveKeyfile } from "~wallets";
import { isString } from "typed-assert";
import Application, { pricingEndpoint } from "~applications/application";
import Application from "~applications/application";
import browser from "webextension-polyfill";
import Arweave from "arweave";
import { ensureAllowanceDispatch } from "./allowance";
Expand Down Expand Up @@ -88,7 +88,7 @@ const background: ModuleFunction<ReturnType> = async (
const dataEntry = createData(data, dataSigner, { tags });

// check allowance
const price = await getPrice(dataEntry, pricingEndpoint);
const price = await getPrice(dataEntry, await app.getBundler());

await ensureAllowanceDispatch(
dataEntry,
Expand Down
9 changes: 8 additions & 1 deletion src/api/modules/dispatch/uploader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { DataItem } from "arbundles";
import { defaultBundler, pricingEndpoint } from "~applications/application";

/**
* Upload a data entry to a Bundlr node
Expand Down Expand Up @@ -31,7 +32,13 @@ export async function getPrice(dataItem: DataItem, node: string) {
const size = dataItem.getRaw().length;

// fetch price
const res = await fetch(`${node}/price/arweave/${size}`);
let endpoint;
if (node === defaultBundler) {
endpoint = pricingEndpoint;
} else {
endpoint = node;
}
const res = await fetch(`${endpoint}/price/arweave/${size}`);

if (res.status >= 400)
throw new Error(`Error fetching price: ${res.status} ${res.statusText}`);
Expand Down

0 comments on commit 2a5b52a

Please sign in to comment.