diff --git a/frontend/src/app/docs/api-docs/api-docs-data.ts b/frontend/src/app/docs/api-docs/api-docs-data.ts index 7ea01584e..4a95c5015 100644 --- a/frontend/src/app/docs/api-docs/api-docs-data.ts +++ b/frontend/src/app/docs/api-docs/api-docs-data.ts @@ -17,50 +17,50 @@ export const wsApiDocsData = { codeTemplate: { curl: `/api/v1/ws`, commonJS: ` - const { %{0}: { websocket } } = mempoolJS(); + const { %{0}: { websocket } } = mempoolJS(); - const ws = websocket.initClient({ - options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'], - }); + const ws = websocket.initClient({ + options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'], + }); - ws.addEventListener('message', function incoming({data}) { - const res = JSON.parse(data.toString()); - if (res.block) { - document.getElementById("result-blocks").textContent = JSON.stringify(res.block, undefined, 2); - } - if (res.mempoolInfo) { - document.getElementById("result-mempool-info").textContent = JSON.stringify(res.mempoolInfo, undefined, 2); - } - if (res.transactions) { - document.getElementById("result-transactions").textContent = JSON.stringify(res.transactions, undefined, 2); - } - if (res["mempool-blocks"]) { - document.getElementById("result-mempool-blocks").textContent = JSON.stringify(res["mempool-blocks"], undefined, 2); - } - }); + ws.addEventListener('message', function incoming({data}) { + const res = JSON.parse(data.toString()); + if (res.block) { + document.getElementById("result-blocks").textContent = JSON.stringify(res.block, undefined, 2); + } + if (res.mempoolInfo) { + document.getElementById("result-mempool-info").textContent = JSON.stringify(res.mempoolInfo, undefined, 2); + } + if (res.transactions) { + document.getElementById("result-transactions").textContent = JSON.stringify(res.transactions, undefined, 2); + } + if (res["mempool-blocks"]) { + document.getElementById("result-mempool-blocks").textContent = JSON.stringify(res["mempool-blocks"], undefined, 2); + } + }); `, esModule: ` -const { %{0}: { websocket } } = mempoolJS(); + const { %{0}: { websocket } } = mempoolJS(); -const ws = websocket.initServer({ -options: ["blocks", "stats", "mempool-blocks", "live-2h-chart"], -}); + const ws = websocket.initServer({ + options: ["blocks", "stats", "mempool-blocks", "live-2h-chart"], + }); -ws.on("message", function incoming(data) { -const res = JSON.parse(data.toString()); -if (res.block) { -console.log(res.block); -} -if (res.mempoolInfo) { -console.log(res.mempoolInfo); -} -if (res.transactions) { -console.log(res.transactions); -} -if (res["mempool-blocks"]) { -console.log(res["mempool-blocks"]); -} -}); + ws.on("message", function incoming(data) { + const res = JSON.parse(data.toString()); + if (res.block) { + console.log(res.block); + } + if (res.mempoolInfo) { + console.log(res.mempoolInfo); + } + if (res.transactions) { + console.log(res.transactions); + } + if (res["mempool-blocks"]) { + console.log(res["mempool-blocks"]); + } + }); `, }, codeSampleMainnet: emptyCodeSample, diff --git a/frontend/src/app/docs/code-template/code-template.component.ts b/frontend/src/app/docs/code-template/code-template.component.ts index 1875e175a..b9ec5972f 100644 --- a/frontend/src/app/docs/code-template/code-template.component.ts +++ b/frontend/src/app/docs/code-template/code-template.component.ts @@ -152,6 +152,7 @@ export class CodeTemplateComponent implements OnInit { const init = async () => { ${codeText} }; + init();`; } }