mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-03 11:40:44 +03:00
updated estimate vote value calculation recipe
This commit is contained in:
parent
550a5f3e1c
commit
df7e35e8d4
@ -70,15 +70,24 @@ export const getFeedHistory = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getCurrentMedianHistoryPrice = async () => {
|
||||||
|
try {
|
||||||
|
const feedHistory = await client.database.call('get_current_median_history_price');
|
||||||
|
return feedHistory;
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const fetchGlobalProps = async () => {
|
export const fetchGlobalProps = async () => {
|
||||||
let globalDynamic;
|
let globalDynamic;
|
||||||
let feedHistory;
|
let medianHistory;
|
||||||
let rewardFund;
|
let rewardFund;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
globalDynamic = await getDynamicGlobalProperties();
|
globalDynamic = await getDynamicGlobalProperties();
|
||||||
await setCache('globalDynamic', globalDynamic);
|
await setCache('globalDynamic', globalDynamic);
|
||||||
feedHistory = await getFeedHistory();
|
medianHistory = await getCurrentMedianHistoryPrice();
|
||||||
rewardFund = await getRewardFund();
|
rewardFund = await getRewardFund();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return;
|
return;
|
||||||
@ -89,8 +98,8 @@ export const fetchGlobalProps = async () => {
|
|||||||
parseToken(get(globalDynamic, 'total_vesting_shares'))) *
|
parseToken(get(globalDynamic, 'total_vesting_shares'))) *
|
||||||
1e6;
|
1e6;
|
||||||
const hbdPrintRate = get(globalDynamic, 'hbd_print_rate');
|
const hbdPrintRate = get(globalDynamic, 'hbd_print_rate');
|
||||||
const base = parseAsset(get(feedHistory, 'current_median_history.base')).amount;
|
const base = parseAsset(medianHistory.base).amount;
|
||||||
const quote = parseAsset(get(feedHistory, 'current_median_history.quote')).amount;
|
const quote = parseAsset(medianHistory.quote).amount;
|
||||||
const fundRecentClaims = get(rewardFund, 'recent_claims');
|
const fundRecentClaims = get(rewardFund, 'recent_claims');
|
||||||
const fundRewardBalance = parseToken(get(rewardFund, 'reward_balance'));
|
const fundRewardBalance = parseToken(get(rewardFund, 'reward_balance'));
|
||||||
const globalProps = {
|
const globalProps = {
|
||||||
|
@ -12,13 +12,35 @@ import {
|
|||||||
SET_GLOBAL_PROPS,
|
SET_GLOBAL_PROPS,
|
||||||
} from '../constants/constants';
|
} from '../constants/constants';
|
||||||
|
|
||||||
const initialState = {
|
|
||||||
|
export interface GlobalProps {
|
||||||
|
hivePerMVests:number;
|
||||||
|
base:number;
|
||||||
|
quote:number;
|
||||||
|
fundRecentClaims:number;
|
||||||
|
fundRewardBalance:number;
|
||||||
|
hbdPrintRate:number;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface AccountState {
|
||||||
|
isFetching:boolean;
|
||||||
|
currentAccount: any;
|
||||||
|
otherAccounts: any[];
|
||||||
|
hasError: boolean;
|
||||||
|
errorMessage: string;
|
||||||
|
isLogingOut: boolean;
|
||||||
|
globalProps:GlobalProps|null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialState: AccountState = {
|
||||||
isFetching: null,
|
isFetching: null,
|
||||||
otherAccounts: [],
|
otherAccounts: [],
|
||||||
currentAccount: {},
|
currentAccount: {},
|
||||||
hasError: false,
|
hasError: false,
|
||||||
errorMessage: null,
|
errorMessage: null,
|
||||||
isLogingOut: false,
|
isLogingOut: false,
|
||||||
|
globalProps: null
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function (state = initialState, action) {
|
export default function (state = initialState, action) {
|
@ -1,18 +0,0 @@
|
|||||||
export const vestsToHp = (vests, hivePerMVests) => {
|
|
||||||
if (!vests || !hivePerMVests) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (vests / 1e6) * hivePerMVests;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const vestsToRshares = (vests, votingPower, votePerc) => {
|
|
||||||
if (!vests || !votingPower || !votePerc) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const vestingShares = parseInt(vests * 1e6, 10);
|
|
||||||
const power = (votingPower * votePerc) / 1e4 / 50 + 1;
|
|
||||||
|
|
||||||
return (power * vestingShares) / 1e4;
|
|
||||||
};
|
|
17
src/utils/conversions.ts
Normal file
17
src/utils/conversions.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
export const vestsToHp = (vests, hivePerMVests) => {
|
||||||
|
if (!vests || !hivePerMVests) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (vests / 1e6) * hivePerMVests;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const vestsToRshares = (vests:number, votingPower:number, weight:number) => {
|
||||||
|
if (!vests || !votingPower || !weight) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const finalVest = vests * 1e6;
|
||||||
|
const power = (votingPower * weight / 10000) / 50
|
||||||
|
return (power * finalVest / 1000)
|
||||||
|
};
|
@ -1,19 +0,0 @@
|
|||||||
import get from 'lodash/get';
|
|
||||||
import parseToken from './parseToken';
|
|
||||||
import { vestsToRshares } from './conversions';
|
|
||||||
|
|
||||||
export const getEstimatedAmount = (account, globalProps, value = 1) => {
|
|
||||||
const { fundRecentClaims, fundRewardBalance, base, quote } = globalProps;
|
|
||||||
const votingPower = account.voting_power;
|
|
||||||
const totalVests =
|
|
||||||
parseToken(get(account, 'vesting_shares')) +
|
|
||||||
parseToken(get(account, 'received_vesting_shares')) -
|
|
||||||
parseToken(get(account, 'delegated_vesting_shares'));
|
|
||||||
const votePct = value * 10000;
|
|
||||||
const rShares = vestsToRshares(totalVests, votingPower, votePct);
|
|
||||||
|
|
||||||
const estimatedAmount = (rShares / fundRecentClaims) * fundRewardBalance * (base / quote);
|
|
||||||
return !Number.isFinite(estimatedAmount) || Number.isNaN(estimatedAmount)
|
|
||||||
? '0.00000'
|
|
||||||
: estimatedAmount.toFixed(5);
|
|
||||||
};
|
|
20
src/utils/vote.ts
Normal file
20
src/utils/vote.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import parseToken from './parseToken';
|
||||||
|
import { vestsToRshares } from './conversions';
|
||||||
|
import { GlobalProps } from '../redux/reducers/accountReducer';
|
||||||
|
|
||||||
|
export const getEstimatedAmount = (account, globalProps:GlobalProps, sliderValue:number = 1) => {
|
||||||
|
|
||||||
|
const { fundRecentClaims, fundRewardBalance, base, quote } = globalProps;
|
||||||
|
const votingPower:number = account.voting_power;
|
||||||
|
const totalVests =
|
||||||
|
parseToken(account.vesting_shares) +
|
||||||
|
parseToken(account.received_vesting_shares) -
|
||||||
|
parseToken(account.delegated_vesting_shares);
|
||||||
|
const weight = sliderValue * 10000;
|
||||||
|
const hbdMedian = base / quote;
|
||||||
|
|
||||||
|
const rShares = vestsToRshares(totalVests, votingPower, weight);
|
||||||
|
const estimatedAmount = rShares / fundRecentClaims * fundRewardBalance * hbdMedian;
|
||||||
|
return Number.isNaN(estimatedAmount) ? '0.00000' : estimatedAmount.toFixed(5);
|
||||||
|
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user