From 3ba37ea4bcc0a60d0fc0a893742ebe9e172869d0 Mon Sep 17 00:00:00 2001
From: mtyszczak <mateusz.tyszczak@gmail.com>
Date: Fri, 31 Jan 2025 15:19:53 +0100
Subject: [PATCH] Fix examples to match new implementation

---
 examples/account-observer/index.html | 15 +++++++++++----
 examples/block-parser/index.html     | 16 ++++++++++------
 examples/post-observer/index.html    | 25 ++++++++++++++++---------
 examples/post-observer/wallet.html   |  7 +++++++
 4 files changed, 44 insertions(+), 19 deletions(-)

diff --git a/examples/account-observer/index.html b/examples/account-observer/index.html
index 7b33a37..b388565 100644
--- a/examples/account-observer/index.html
+++ b/examples/account-observer/index.html
@@ -31,6 +31,13 @@
   <hr>
   <h2>Log</h2>
   <div id="log"></div>
+  <script type="importmap">
+    {
+      "imports": {
+        "@hiveio/wax": "/node_modules/@hiveio/wax/wasm/dist/bundle/web.js"
+      }
+    }
+  </script>
   <script type="module">
     import WorkerBee from "../../dist/bundle/index.js";
 
@@ -52,7 +59,10 @@
     let bot, work;
 
     const actualBotWork = async(accountToObserve) => {
-      work = bot.observe.accountOperations(accountToObserve).subscribe({
+      work = bot.observe.onImpactedAccount(accountToObserve).subscribe({
+        error(error) {
+          log(error, true);
+        },
         next(op) {
           log(op);
         }
@@ -85,9 +95,6 @@
           }
           */
         });
-        bot.on("error", error => {
-          log(error, true);
-        });
 
         await bot.start();
 
diff --git a/examples/block-parser/index.html b/examples/block-parser/index.html
index 467cf4d..cd93bf3 100644
--- a/examples/block-parser/index.html
+++ b/examples/block-parser/index.html
@@ -30,6 +30,13 @@
   <hr>
   <h2>Log</h2>
   <div id="log"></div>
+  <script type="importmap">
+    {
+      "imports": {
+        "@hiveio/wax": "/node_modules/@hiveio/wax/wasm/dist/bundle/web.js"
+      }
+    }
+  </script>
   <script type="module">
     import WorkerBee from "../../dist/bundle/index.js";
 
@@ -51,8 +58,8 @@
     let bot;
 
     const actualBotWork = async() => {
-      for await(const { block, number } of bot) {
-        log(`Got block #${block.block_id} (${number})`);
+      for await(const { id, number } of bot) {
+        log(`Got block #${id} (${number})`);
       }
     };
 
@@ -73,12 +80,9 @@
 
         bot = new WorkerBee({
           chainOptions: {
-            apiEndpoint: process.env.HIVE_API_HOST || 'https://api.hive.blog/'
+            apiEndpoint: (typeof process === "object" && process.env && process.env.HIVE_API_HOST) || 'https://api.hive.blog/'
           }
         });
-        bot.on("error", error => {
-          log(error, true);
-        });
 
         await bot.start();
 
diff --git a/examples/post-observer/index.html b/examples/post-observer/index.html
index 135ad81..d284747 100644
--- a/examples/post-observer/index.html
+++ b/examples/post-observer/index.html
@@ -40,6 +40,14 @@
   <hr>
   <h2>Log</h2>
   <div id="log"></div>
+  <script type="importmap">
+    {
+      "imports": {
+        "@hiveio/wax": "/node_modules/@hiveio/wax/wasm/dist/bundle/web.js",
+        "@hiveio/beekeeper": "/node_modules/@hiveio/beekeeper/dist/bundle/web.js"
+      }
+    }
+  </script>
   <script type="module">
     import WorkerBee from "../../dist/bundle/index.js";
     import { OperationVisitor } from "@hiveio/wax";
@@ -69,12 +77,12 @@
 
     let bot, work, manaWork, beneficiaryName, voterName;
 
-    let chainId = process.env.CHAIN_ID;
+    let chainId = (typeof process === "object" && process.env && process.env.CHAIN_ID) || undefined;
     if (typeof chainId === "string" && chainId.length > 0)
       chainIdNode.value = chainId;
 
     const implicitApiEndpoint = document.location.protocol + '//' + document.location.hostname + ':3000';
-    let apiEndpoint = apiEndpointInput.value = process.env.DIRECT_API_ENDPOINT || implicitApiEndpoint;
+    let apiEndpoint = apiEndpointInput.value = (typeof process === "object" && process.env && process.env.DIRECT_API_ENDPOINT) || implicitApiEndpoint;
     console.log(`Using API endpoint: "${apiEndpoint}" with chain id: "${chainId}"`);
 
     const voted = new Set(/* Set<`${Account}/${Permlink}`> */);
@@ -150,16 +158,18 @@
     }
 
     const actualBotWork = async (accountToObserve) => {
-      work = bot.observe.accountOperations(accountToObserve).subscribe({
-        next({ op, transaction: { block: { number } } }) {
-          new CommentVisitor(number).accept(op);
+      work = bot.observe.onImpactedAccount(accountToObserve).provideBlockHeaderData().subscribe({
+        next(data) {
+          console.log(data);
+          for(const op of data.impactedAccounts[accountToObserve])
+            new CommentVisitor(data.block.number).accept(op);
         },
         error(error) {
           log(error, true);
         }
       });
 
-      manaWork = bot.observe.accountFullManabar(accountToObserve).subscribe({
+      manaWork = bot.observe.onAccountFullManabar(accountToObserve).subscribe({
         next() {
           const key = posts.keys().next().value;
           if (!key)
@@ -215,9 +225,6 @@
             chainId
           }
         });
-        bot.on("error", error => {
-          log(error, true);
-        });
 
         const beekeeper = await beekeeperFactory();
         const session = await beekeeper.createSession("my.salt");
diff --git a/examples/post-observer/wallet.html b/examples/post-observer/wallet.html
index b0ad628..29f0ae4 100644
--- a/examples/post-observer/wallet.html
+++ b/examples/post-observer/wallet.html
@@ -53,6 +53,13 @@
   <hr>
   <h2>Log</h2>
   <div id="log"></div>
+  <script type="importmap">
+    {
+      "imports": {
+        "@hiveio/beekeeper": "/node_modules/@hiveio/beekeeper/dist/bundle/web.js"
+      }
+    }
+  </script>
   <script type="module">
     import beekeeperFactory from "@hiveio/beekeeper";
 
-- 
GitLab