Skip to content
Snippets Groups Projects
Commit fb249eac authored by Dan Notestein's avatar Dan Notestein
Browse files

Merge branch 'fill-missing-account-data-using-find-accounts' into 'develop'

Get hive power for user

See merge request !106
parents b2bda598 7baf6aba
No related branches found
No related tags found
2 merge requests!112Update Prod,!106Get hive power for user
import { call, put, takeLatest } from 'redux-saga/effects';
import * as userProfileActions from './UserProfilesReducer';
import { callBridge } from 'app/utils/steemApi';
import { callBridge, getHivePowerForUser } from 'app/utils/steemApi';
const FETCH_PROFILE = 'userProfilesSaga/FETCH_PROFILE';
......@@ -11,9 +11,14 @@ export const userProfilesWatches = [
export function* fetchUserProfile(action) {
const { account, observer } = action.payload;
const ret = yield call(callBridge, 'get_profile', { account, observer });
const hive_power = yield getHivePowerForUser(account);
if (!ret) throw new Error('Account not found');
yield put(
userProfileActions.addProfile({ username: account, account: ret })
userProfileActions.addProfile({
username: account,
account: { ...ret, stats: { ...ret.stats, sp: hive_power } },
})
);
}
......
......@@ -21,6 +21,32 @@ 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 post_voting_power =
fullAccounts['accounts'][0]['post_voting_power'];
/**
* This magic number is coming from
* https://gitlab.syncad.com/hive/hivemind/-/blame/d2d5ef25107908db09438da5ee3da9d6fcb976bc/hive/server/bridge_api/objects.py
*/
const MAGIC_NUMBER = 0.0005037;
const hive_power = (
post_voting_power.amount *
MAGIC_NUMBER *
(1 / Math.pow(10, post_voting_power.precision))
).toFixed(0);
resolve(hive_power);
} catch (err) {
reject(err);
}
});
}
export async function getStateAsync(url, observer, ssr = false) {
console.log('getStateAsync');
if (observer === undefined) observer = null;
......@@ -66,8 +92,16 @@ export async function getStateAsync(url, observer, ssr = false) {
if (ssr && account) {
// TODO: move to global reducer?
const profile = await callBridge('get_profile', { account });
const hive_power = await getHivePowerForUser(account);
if (profile && profile['name']) {
state['profiles'][account] = profile;
state['profiles'][account] = {
...profile,
stats: {
...profile.stats,
sp: hive_power,
},
};
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment