From c07f555f3e80949f08c39569f6189d0be4775a5a Mon Sep 17 00:00:00 2001
From: jsalyers <jsalyers@syncad.com>
Date: Fri, 26 Feb 2021 12:28:20 -0500
Subject: [PATCH] [JES] Also pass the observer to the loadThread call

---
 src/app/utils/steemApi.js | 85 +++++++++------------------------------
 1 file changed, 20 insertions(+), 65 deletions(-)

diff --git a/src/app/utils/steemApi.js b/src/app/utils/steemApi.js
index d2035eb60..7f38d78e7 100644
--- a/src/app/utils/steemApi.js
+++ b/src/app/utils/steemApi.js
@@ -2,10 +2,7 @@ import { api } from '@hiveio/hive-js';
 import Big from 'big.js';
 import { ifHive } from 'app/utils/Community';
 import stateCleaner from 'app/redux/stateCleaner';
-import {
-    fetchCrossPosts,
-    augmentContentWithCrossPost,
-} from 'app/utils/CrossPosts';
+import { fetchCrossPosts, augmentContentWithCrossPost } from 'app/utils/CrossPosts';
 
 export async function callBridge(method, params) {
     // [JES] Hivemind throws an exception if you call for my/[trending/payouts/new/etc] with a null observer
@@ -30,11 +27,7 @@ export async function callBridge(method, params) {
     )
         params.observer = $STM_Config.default_observer;
 
-    console.log(
-        'call bridge',
-        method,
-        params && JSON.stringify(params).substring(0, 200)
-    );
+    console.log('call bridge', method, params && JSON.stringify(params).substring(0, 200));
 
     return new Promise(function(resolve, reject) {
         api.call('bridge.' + method, params, function(err, data) {
@@ -60,24 +53,17 @@ export async function callBridge(method, params) {
 export function getHivePowerForUser(account) {
     return new Promise(async (resolve, reject) => {
         try {
-            const fullAccounts = await api.callAsync(
-                'database_api.find_accounts',
-                { accounts: [account] }
-            );
+            const fullAccounts = await api.callAsync('database_api.find_accounts', { accounts: [account] });
 
             api.getDynamicGlobalProperties((error, result) => {
                 if (error) return reject(error);
 
                 try {
-                    const {
-                        total_vesting_fund_hive,
-                        total_vesting_shares,
-                    } = result;
+                    const { total_vesting_fund_hive, total_vesting_shares } = result;
                     const totalHive = total_vesting_fund_hive.split(' ')[0];
                     const totalVests = total_vesting_shares.split(' ')[0];
 
-                    const post_voting_power =
-                        fullAccounts['accounts'][0]['post_voting_power'];
+                    const post_voting_power = fullAccounts['accounts'][0]['post_voting_power'];
                     /**
                      * old implementation instead of getting hive/vests dynamically
                      * This magic number is coming from
@@ -85,9 +71,7 @@ export function getHivePowerForUser(account) {
                      */
                     //    const MAGIC_NUMBER = 0.0005037;
 
-                    const hiveDividedByVests = new Big(totalHive)
-                        .div(new Big(totalVests))
-                        .toFixed(7);
+                    const hiveDividedByVests = new Big(totalHive).div(new Big(totalVests)).toFixed(7);
 
                     const hive_power = new Big(post_voting_power.amount)
                         .times(new Big(hiveDividedByVests))
@@ -125,7 +109,7 @@ export async function getStateAsync(url, observer, ssr = false) {
         state['content'] = posts['content'];
         state['discussion_idx'] = posts['discussion_idx'];
     } else if (page == 'thread') {
-        const posts = await loadThread(key[0], key[1]);
+        const posts = await loadThread(key[0], key[1], observer);
         state['content'] = posts['content'];
     } else {
         // no-op
@@ -142,10 +126,7 @@ export async function getStateAsync(url, observer, ssr = false) {
     }
 
     // for SSR, load profile on any profile page or discussion thread author
-    const account =
-        tag && tag[0] == '@'
-            ? tag.slice(1)
-            : page == 'thread' ? key[0].slice(1) : null;
+    const account = tag && tag[0] == '@' ? tag.slice(1) : page == 'thread' ? key[0].slice(1) : null;
     if (ssr && account) {
         // TODO: move to global reducer?
         const profile = await callBridge('get_profile', { account });
@@ -173,23 +154,19 @@ export async function getStateAsync(url, observer, ssr = false) {
     return cleansed;
 }
 
-async function loadThread(account, permlink) {
+async function loadThread(account, permlink, observer) {
     const author = account.slice(1);
-    const content = await callBridge('get_discussion', { author, permlink });
+    const content = await callBridge('get_discussion', { author, permlink, observer });
 
     if (content) {
-        const {
-            content: preppedContent,
-            keys,
-            crossPosts,
-        } = await fetchCrossPosts([Object.values(content)[0]], author);
+        const { content: preppedContent, keys, crossPosts } = await fetchCrossPosts(
+            [Object.values(content)[0]],
+            author
+        );
         if (crossPosts) {
             const crossPostKey = content[keys[0]].cross_post_key;
             content[keys[0]] = preppedContent[keys[0]];
-            content[keys[0]] = augmentContentWithCrossPost(
-                content[keys[0]],
-                crossPosts[crossPostKey]
-            );
+            content[keys[0]] = augmentContentWithCrossPost(content[keys[0]], crossPosts[crossPostKey]);
         }
     }
 
@@ -209,10 +186,7 @@ async function loadPosts(sort, tag, observer) {
         posts = await callBridge('get_ranked_posts', params);
     }
 
-    const { content, keys, crossPosts } = await fetchCrossPosts(
-        posts,
-        observer
-    );
+    const { content, keys, crossPosts } = await fetchCrossPosts(posts, observer);
 
     if (Object.keys(crossPosts).length > 0) {
         for (let ki = 0; ki < keys.length; ki += 1) {
@@ -220,10 +194,7 @@ async function loadPosts(sort, tag, observer) {
             let post = content[contentKey];
 
             if (Object.prototype.hasOwnProperty.call(post, 'cross_post_key')) {
-                post = augmentContentWithCrossPost(
-                    post,
-                    crossPosts[post.cross_post_key]
-                );
+                post = augmentContentWithCrossPost(post, crossPosts[post.cross_post_key]);
             }
         }
     }
@@ -241,31 +212,15 @@ function parsePath(url) {
 
     // strip off leading and trailing slashes
     if (url.length > 0 && url[0] == '/') url = url.substring(1, url.length);
-    if (url.length > 0 && url[url.length - 1] == '/')
-        url = url.substring(0, url.length - 1);
+    if (url.length > 0 && url[url.length - 1] == '/') url = url.substring(0, url.length - 1);
 
     // blank URL defaults to `trending`
     if (url === '') url = 'trending';
 
     const part = url.split('/');
     const parts = part.length;
-    const sorts = [
-        'trending',
-        'promoted',
-        'hot',
-        'created',
-        'payout',
-        'payout_comments',
-        'muted',
-    ];
-    const acct_tabs = [
-        'blog',
-        'feed',
-        'posts',
-        'comments',
-        'replies',
-        'payout',
-    ];
+    const sorts = ['trending', 'promoted', 'hot', 'created', 'payout', 'payout_comments', 'muted'];
+    const acct_tabs = ['blog', 'feed', 'posts', 'comments', 'replies', 'payout'];
 
     let page = null;
     let tag = null;
-- 
GitLab