Merge pull request #2000 from ecency/votte

wip vote improvements
This commit is contained in:
Feruz M 2021-07-17 19:31:42 +03:00 committed by GitHub
commit f89fa6925d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View File

@ -1671,4 +1671,12 @@ const getActiveKey = (local, pin) => {
return false;
};
export const votingPower = (account) => {
// @ts-ignore "Account" is compatible with dhive's "ExtendedAccount"
const calc = client.rc.calculateVPMana(account);
const { percentage } = calc;
return percentage / 100;
};
/* eslint-enable */

View File

@ -1,20 +1,23 @@
import parseToken from './parseToken';
import { GlobalProps } from '../redux/reducers/accountReducer';
import { votingPower } from '../providers/hive/dhive';
export const getEstimatedAmount = (account, globalProps:GlobalProps, sliderValue:number = 1) => {
const { fundRecentClaims, fundRewardBalance, base, quote } = globalProps;
const votingPower:number = account.voting_power;
const _votingPower:number = Number((100 * votingPower(account)).toFixed(0));
/*
const vestingShares = parseToken(account.vesting_shares);
const receievedVestingShares = parseToken(account.received_vesting_shares);
const delegatedVestingShared = parseToken(account.delegated_vesting_shares);
const totalVests = vestingShares + receievedVestingShares - delegatedVestingShared;
*/
const vestingShares = parseToken(account.post_voting_power);
const totalVests = vestingShares;
const weight = sliderValue * 10000;
const hbdMedian = base / quote;
const totalVests = vestingShares + receievedVestingShares - delegatedVestingShared;
const voteEffectiveShares = calculateVoteRshares(totalVests, votingPower, weight)
const voteValue = (voteEffectiveShares / fundRecentClaims) * fundRewardBalance * hbdMedian;
const voteEffectiveShares = calculateVoteRshares(totalVests, _votingPower, weight)
const voteValue = (voteEffectiveShares / fundRecentClaims) * fundRewardBalance * hbdMedian / 4;
const estimatedAmount = weight < 0 ? Math.min(voteValue * -1, 0) : Math.max(voteValue, 0)
return Number.isNaN(estimatedAmount) ? '0.00000' : estimatedAmount.toFixed(5);