Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Left() {

let codeAnchor = ``;
codeAnchor += `async function getMeshJsonHash(url: string) {\n`;
codeAnchor += ` var drepAnchor = getFile(url);\n`;
codeAnchor += ` var drepAnchor = await getFile(url);\n`;
codeAnchor += ` const anchorObj = JSON.parse(drepAnchor);\n`;
codeAnchor += ` return hashDrepAnchor(anchorObj);\n`;
codeAnchor += `}\n`;
Expand Down Expand Up @@ -129,7 +129,7 @@ function Right() {
const [anchorUrl, setAnchorUrl] = useState<string>("");

async function getMeshJsonHash(url: string) {
var drepAnchor = getFile(url);
var drepAnchor = await getFile(url);
const anchorObj = JSON.parse(drepAnchor);
const anchorHash = hashDrepAnchor(anchorObj);
return anchorHash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function Right() {
const [anchorUrl, setAnchorUrl] = useState<string>("");

async function getMeshJsonHash(url: string) {
var drepAnchor = getFile(url);
var drepAnchor = await getFile(url);
const anchorObj = JSON.parse(drepAnchor);
const anchorHash = hashDrepAnchor(anchorObj);
return anchorHash;
Expand Down
15 changes: 10 additions & 5 deletions packages/mesh-common/src/utils/file.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
export function getFile(url: string) {
var Httpreq = new XMLHttpRequest();
Httpreq.open("GET", url, false);
Httpreq.send(null);
return Httpreq.responseText;
export async function getFile(url: string) {
if (typeof XMLHttpRequest !== "undefined") {
var Httpreq = new XMLHttpRequest();
Httpreq.open("GET", url, false);
Httpreq.send(null);
return Httpreq.responseText;
} else {
const res = await fetch(url);
return res.text();
}
}