diff --git a/apps/playground/src/pages/apis/txbuilder/governance/registration.tsx b/apps/playground/src/pages/apis/txbuilder/governance/registration.tsx index d8587ef10..757d6787b 100644 --- a/apps/playground/src/pages/apis/txbuilder/governance/registration.tsx +++ b/apps/playground/src/pages/apis/txbuilder/governance/registration.tsx @@ -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`; @@ -129,7 +129,7 @@ function Right() { const [anchorUrl, setAnchorUrl] = useState(""); 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; diff --git a/apps/playground/src/pages/apis/txbuilder/governance/update.tsx b/apps/playground/src/pages/apis/txbuilder/governance/update.tsx index 70e86c8a8..fc1dc564e 100644 --- a/apps/playground/src/pages/apis/txbuilder/governance/update.tsx +++ b/apps/playground/src/pages/apis/txbuilder/governance/update.tsx @@ -65,7 +65,7 @@ function Right() { const [anchorUrl, setAnchorUrl] = useState(""); 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; diff --git a/packages/mesh-common/src/utils/file.ts b/packages/mesh-common/src/utils/file.ts index cc54345d7..052e22692 100644 --- a/packages/mesh-common/src/utils/file.ts +++ b/packages/mesh-common/src/utils/file.ts @@ -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(); + } }