Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
condenser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
condenser
Commits
c07f555f
Commit
c07f555f
authored
4 years ago
by
Jason Salyers
Browse files
Options
Downloads
Patches
Plain Diff
[JES] Also pass the observer to the loadThread call
parent
e52ce513
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!224
Develop
,
!219
[JES] Also pass the observer to the loadThread call
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app/utils/steemApi.js
+20
-65
20 additions, 65 deletions
src/app/utils/steemApi.js
with
20 additions
and
65 deletions
src/app/utils/steemApi.js
+
20
−
65
View file @
c07f555f
...
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment