mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-14 16:12:40 +03:00
Merge pull request #509 from esteemapp/upvote/bugs
fixed upvote bugs && added steem globalProps && couple enhancment
This commit is contained in:
commit
d5cc201f08
@ -1,4 +1,5 @@
|
|||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
// Component
|
// Component
|
||||||
import TransactionView from '../view/transactionView';
|
import TransactionView from '../view/transactionView';
|
||||||
@ -21,10 +22,14 @@ class TransactionContainer extends PureComponent {
|
|||||||
// Component Functions
|
// Component Functions
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { walletData } = this.props;
|
const { walletData, steemPerMVests } = this.props;
|
||||||
|
|
||||||
return <TransactionView walletData={walletData} />;
|
return <TransactionView walletData={walletData} steemPerMVests={steemPerMVests} />;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default TransactionContainer;
|
const mapStateToProps = state => ({
|
||||||
|
steemPerMVests: state.account.globalProps.steemPerMVests,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(mapStateToProps)(TransactionContainer);
|
||||||
|
@ -36,7 +36,7 @@ class TransactionView extends PureComponent {
|
|||||||
walletData: { transactions },
|
walletData: { transactions },
|
||||||
intl,
|
intl,
|
||||||
intl: { formatNumber },
|
intl: { formatNumber },
|
||||||
walletData,
|
steemPerMVests,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -53,16 +53,16 @@ class TransactionView extends PureComponent {
|
|||||||
<Card>
|
<Card>
|
||||||
{transactions
|
{transactions
|
||||||
&& transactions.map((item, index) => {
|
&& transactions.map((item, index) => {
|
||||||
const transactionData = groomingTransactionData(item, walletData, formatNumber);
|
const transactionData = groomingTransactionData(item, steemPerMVests, formatNumber);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CollapsibleCard
|
<CollapsibleCard
|
||||||
noBorder
|
noBorder
|
||||||
noContainer
|
noContainer
|
||||||
key={index}
|
key={index.toString()}
|
||||||
titleComponent={(
|
titleComponent={(
|
||||||
<WalletLineItem
|
<WalletLineItem
|
||||||
key={index}
|
key={index.toString()}
|
||||||
index={index}
|
index={index}
|
||||||
text={intl.formatMessage({
|
text={intl.formatMessage({
|
||||||
id: `wallet.${transactionData.opName}`,
|
id: `wallet.${transactionData.opName}`,
|
||||||
@ -81,7 +81,7 @@ class TransactionView extends PureComponent {
|
|||||||
>
|
>
|
||||||
{(!!transactionData.details || !!transactionData.memo) && (
|
{(!!transactionData.details || !!transactionData.memo) && (
|
||||||
<WalletLineItem
|
<WalletLineItem
|
||||||
key={index}
|
key={index.toString()}
|
||||||
text={!!transactionData.details && transactionData.details}
|
text={!!transactionData.details && transactionData.details}
|
||||||
isBlackText
|
isBlackText
|
||||||
isThin
|
isThin
|
||||||
|
@ -49,6 +49,7 @@ class UpvoteContainer extends PureComponent {
|
|||||||
isShowPayoutValue,
|
isShowPayoutValue,
|
||||||
pinCode,
|
pinCode,
|
||||||
upvotePercent,
|
upvotePercent,
|
||||||
|
globalProps,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
let author;
|
let author;
|
||||||
let authorPayout;
|
let authorPayout;
|
||||||
@ -83,6 +84,7 @@ class UpvoteContainer extends PureComponent {
|
|||||||
curationPayout={curationPayout}
|
curationPayout={curationPayout}
|
||||||
currentAccount={currentAccount}
|
currentAccount={currentAccount}
|
||||||
fetchPost={fetchPost}
|
fetchPost={fetchPost}
|
||||||
|
globalProps={globalProps}
|
||||||
handleSetUpvotePercent={this._setUpvotePercent}
|
handleSetUpvotePercent={this._setUpvotePercent}
|
||||||
isDecinedPayout={isDecinedPayout}
|
isDecinedPayout={isDecinedPayout}
|
||||||
isLoggedIn={isLoggedIn}
|
isLoggedIn={isLoggedIn}
|
||||||
@ -105,6 +107,7 @@ const mapStateToProps = state => ({
|
|||||||
upvotePercent: state.application.upvotePercent,
|
upvotePercent: state.application.upvotePercent,
|
||||||
pinCode: state.account.pin,
|
pinCode: state.account.pin,
|
||||||
currentAccount: state.account.currentAccount,
|
currentAccount: state.account.currentAccount,
|
||||||
|
globalProps: state.account.globalProps,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps)(UpvoteContainer);
|
export default connect(mapStateToProps)(UpvoteContainer);
|
||||||
|
@ -6,12 +6,17 @@ import { injectIntl } from 'react-intl';
|
|||||||
import { Popover, PopoverController } from 'react-native-modal-popover';
|
import { Popover, PopoverController } from 'react-native-modal-popover';
|
||||||
import Slider from 'react-native-slider';
|
import Slider from 'react-native-slider';
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
import parseToken from '../../../utils/parseToken';
|
||||||
|
import { vestsToRshares } from '../../../utils/conversions';
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
import { Icon } from '../../icon';
|
import { Icon } from '../../icon';
|
||||||
import { PulseAnimation } from '../../animations';
|
import { PulseAnimation } from '../../animations';
|
||||||
import { TextButton } from '../../buttons';
|
import { TextButton } from '../../buttons';
|
||||||
|
|
||||||
// STEEM
|
// STEEM
|
||||||
import { upvoteAmount, vote } from '../../../providers/steem/dsteem';
|
import { vote } from '../../../providers/steem/dsteem';
|
||||||
|
|
||||||
// Styles
|
// Styles
|
||||||
import styles from './upvoteStyles';
|
import styles from './upvoteStyles';
|
||||||
@ -53,21 +58,22 @@ class UpvoteView extends Component {
|
|||||||
|
|
||||||
// Component Functions
|
// Component Functions
|
||||||
_calculateEstimatedAmount = async () => {
|
_calculateEstimatedAmount = async () => {
|
||||||
const { currentAccount } = this.props;
|
const { currentAccount, globalProps } = this.props;
|
||||||
// Calculate total vesting shares
|
|
||||||
if (currentAccount) {
|
if (currentAccount) {
|
||||||
const { sliderValue } = this.state;
|
const { sliderValue } = this.state;
|
||||||
const totalVests = parseFloat(currentAccount.vesting_shares)
|
const {
|
||||||
+ parseFloat(currentAccount.received_vesting_shares)
|
fundRecentClaims, fundRewardBalance, base, quote,
|
||||||
- parseFloat(currentAccount.delegated_vesting_shares);
|
} = globalProps;
|
||||||
|
|
||||||
const finalVest = totalVests * 1e6;
|
const votingPower = currentAccount.voting_power;
|
||||||
|
const totalVests = parseToken(currentAccount.vesting_shares)
|
||||||
|
+ parseToken(currentAccount.received_vesting_shares)
|
||||||
|
- parseToken(currentAccount.delegated_vesting_shares);
|
||||||
|
const votePct = sliderValue * 10000;
|
||||||
|
|
||||||
const power = (currentAccount.voting_power * (sliderValue * 10000)) / 10000 / 50;
|
const rShares = vestsToRshares(totalVests, votingPower, votePct);
|
||||||
|
const estimated = (rShares / fundRecentClaims) * fundRewardBalance * (base / quote);
|
||||||
const rshares = (power * finalVest) / 10000;
|
|
||||||
|
|
||||||
const estimated = await upvoteAmount(rshares);
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
amount: estimated.toFixed(5),
|
amount: estimated.toFixed(5),
|
||||||
@ -252,18 +258,18 @@ class UpvoteView extends Component {
|
|||||||
<Fragment>
|
<Fragment>
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
closePopover();
|
closePopover();
|
||||||
this._upvoteContent();
|
this._upvoteContent();
|
||||||
}}
|
}}
|
||||||
style={styles.upvoteButton}
|
style={styles.upvoteButton}
|
||||||
>
|
>
|
||||||
<Icon
|
<Icon
|
||||||
size={20}
|
size={20}
|
||||||
style={[styles.upvoteIcon, { color: '#007ee5' }]}
|
style={[styles.upvoteIcon, { color: '#007ee5' }]}
|
||||||
active={!isLoggedIn}
|
active={!isLoggedIn}
|
||||||
iconType={iconType}
|
iconType={iconType}
|
||||||
name={iconName}
|
name={iconName}
|
||||||
/>
|
/>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
<Text style={styles.amount}>{_amount}</Text>
|
<Text style={styles.amount}>{_amount}</Text>
|
||||||
<Slider
|
<Slider
|
||||||
@ -274,10 +280,10 @@ class UpvoteView extends Component {
|
|||||||
thumbTintColor="#007ee5"
|
thumbTintColor="#007ee5"
|
||||||
value={sliderValue}
|
value={sliderValue}
|
||||||
onValueChange={(value) => {
|
onValueChange={(value) => {
|
||||||
this.setState({ sliderValue: value }, () => {
|
this.setState({ sliderValue: value }, () => {
|
||||||
this._calculateEstimatedAmount();
|
this._calculateEstimatedAmount();
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Text style={styles.percent}>{_percent}</Text>
|
<Text style={styles.percent}>{_percent}</Text>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
|
@ -47,8 +47,8 @@ class WalletContainer extends Component {
|
|||||||
// Components functions
|
// Components functions
|
||||||
|
|
||||||
_getWalletData = async (selectedUser) => {
|
_getWalletData = async (selectedUser) => {
|
||||||
const { setEstimatedWalletValue } = this.props;
|
const { setEstimatedWalletValue, globalProps } = this.props;
|
||||||
const walletData = await groomingWalletData(selectedUser);
|
const walletData = await groomingWalletData(selectedUser, globalProps);
|
||||||
|
|
||||||
this.setState({ walletData });
|
this.setState({ walletData });
|
||||||
setEstimatedWalletValue(walletData.estimatedValue);
|
setEstimatedWalletValue(walletData.estimatedValue);
|
||||||
@ -133,6 +133,7 @@ const mapStateToProps = state => ({
|
|||||||
currentAccount: state.account.currentAccount,
|
currentAccount: state.account.currentAccount,
|
||||||
pinCode: state.account.pin,
|
pinCode: state.account.pin,
|
||||||
isDarkTheme: state.application.isDarkTheme,
|
isDarkTheme: state.application.isDarkTheme,
|
||||||
|
globalProps: state.account.globalProps,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default injectIntl(connect(mapStateToProps)(WalletContainer));
|
export default injectIntl(connect(mapStateToProps)(WalletContainer));
|
||||||
|
@ -10,13 +10,12 @@ import { decryptKey } from '../../utils/crypto';
|
|||||||
import { parsePosts, parsePost, parseComments } from '../../utils/postParser';
|
import { parsePosts, parsePost, parseComments } from '../../utils/postParser';
|
||||||
import { getName, getAvatar } from '../../utils/user';
|
import { getName, getAvatar } from '../../utils/user';
|
||||||
import { getReputation } from '../../utils/reputation';
|
import { getReputation } from '../../utils/reputation';
|
||||||
|
import parseToken from '../../utils/parseToken';
|
||||||
|
|
||||||
// Constant
|
// Constant
|
||||||
import AUTH_TYPE from '../../constants/authType';
|
import AUTH_TYPE from '../../constants/authType';
|
||||||
|
|
||||||
const DEFAULT_SERVER = 'https://api.steemit.com';
|
const DEFAULT_SERVER = 'https://api.steemit.com';
|
||||||
let rewardFund = null;
|
|
||||||
let medianPrice = null;
|
|
||||||
let client = new Client(DEFAULT_SERVER);
|
let client = new Client(DEFAULT_SERVER);
|
||||||
|
|
||||||
const _getClient = async () => {
|
const _getClient = async () => {
|
||||||
@ -35,6 +34,50 @@ _getClient();
|
|||||||
|
|
||||||
export const getDigitPinCode = pin => decryptKey(pin, Config.PIN_KEY);
|
export const getDigitPinCode = pin => decryptKey(pin, Config.PIN_KEY);
|
||||||
|
|
||||||
|
export const getDynamicGlobalProperties = () => client.database.getDynamicGlobalProperties();
|
||||||
|
|
||||||
|
export const getRewardFund = () => client.database.call('get_reward_fund', ['post']);
|
||||||
|
|
||||||
|
export const getFeedHistory = async () => {
|
||||||
|
try {
|
||||||
|
const feedHistory = await client.database.call('get_feed_history');
|
||||||
|
return feedHistory;
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const fetchGlobalProps = async () => {
|
||||||
|
let globalDynamic;
|
||||||
|
let feedHistory;
|
||||||
|
let rewardFund;
|
||||||
|
|
||||||
|
try {
|
||||||
|
globalDynamic = await getDynamicGlobalProperties();
|
||||||
|
feedHistory = await getFeedHistory();
|
||||||
|
rewardFund = await getRewardFund();
|
||||||
|
} catch (e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const steemPerMVests = (parseToken(globalDynamic.total_vesting_fund_steem)
|
||||||
|
/ parseToken(globalDynamic.total_vesting_shares))
|
||||||
|
* 1e6;
|
||||||
|
const base = parseToken(feedHistory.current_median_history.base);
|
||||||
|
const quote = parseToken(feedHistory.current_median_history.quote);
|
||||||
|
const fundRecentClaims = rewardFund.recent_claims;
|
||||||
|
const fundRewardBalance = parseToken(rewardFund.reward_balance);
|
||||||
|
const globalProps = {
|
||||||
|
steemPerMVests,
|
||||||
|
base,
|
||||||
|
quote,
|
||||||
|
fundRecentClaims,
|
||||||
|
fundRewardBalance,
|
||||||
|
};
|
||||||
|
|
||||||
|
return globalProps;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method getAccount get account data
|
* @method getAccount get account data
|
||||||
* @param user username
|
* @param user username
|
||||||
@ -127,22 +170,6 @@ export const getFollows = user => new Promise((resolve, reject) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* @method getFollowers
|
|
||||||
* @param user username
|
|
||||||
* TODO: Pagination
|
|
||||||
*/
|
|
||||||
// export const getFollowers = (user, limit = 100) => new Promise((resolve, reject) => {
|
|
||||||
// client
|
|
||||||
// .call('follow_api', 'get_followers', [user, '', 'blog', limit])
|
|
||||||
// .then((result) => {
|
|
||||||
// resolve(result);
|
|
||||||
// })
|
|
||||||
// .catch((err) => {
|
|
||||||
// reject(err);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method getFollowing
|
* @method getFollowing
|
||||||
* @param user username
|
* @param user username
|
||||||
@ -426,18 +453,12 @@ export const vote = async (currentAccount, pin, author, permlink, weight) => {
|
|||||||
* @method upvoteAmount estimate upvote amount
|
* @method upvoteAmount estimate upvote amount
|
||||||
*/
|
*/
|
||||||
export const upvoteAmount = async (input) => {
|
export const upvoteAmount = async (input) => {
|
||||||
if (!rewardFund || !medianPrice) {
|
let medianPrice;
|
||||||
rewardFund = await client.database.call('get_reward_fund', ['post']);
|
const rewardFund = await getRewardFund();
|
||||||
|
|
||||||
await client.database
|
await client.database.getCurrentMedianHistoryPrice().then((res) => {
|
||||||
.getCurrentMedianHistoryPrice()
|
medianPrice = res;
|
||||||
.then((res) => {
|
});
|
||||||
medianPrice = res;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
// reject(err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const estimated = (input / parseFloat(rewardFund.recent_claims))
|
const estimated = (input / parseFloat(rewardFund.recent_claims))
|
||||||
* parseFloat(rewardFund.reward_balance)
|
* parseFloat(rewardFund.reward_balance)
|
||||||
@ -563,24 +584,6 @@ export const delegate = (data, activeKey) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const globalProps = async () => {
|
|
||||||
try {
|
|
||||||
const globalProperties = await client.database.getDynamicGlobalProperties();
|
|
||||||
return globalProperties;
|
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getFeedHistory = async () => {
|
|
||||||
try {
|
|
||||||
const feedHistory = await client.database.call('get_feed_history');
|
|
||||||
return feedHistory;
|
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const transferToVesting = (data, activeKey) => {
|
export const transferToVesting = (data, activeKey) => {
|
||||||
const privateKey = PrivateKey.fromString(activeKey);
|
const privateKey = PrivateKey.fromString(activeKey);
|
||||||
|
|
||||||
@ -832,15 +835,4 @@ const getAnyPrivateKey = (local, pin) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// ['postingKey', 'activeKey'].forEach((key) => {
|
|
||||||
// console.log('key :', key);
|
|
||||||
// console.log('pin :', pin);
|
|
||||||
// console.log('local[key] :', local[key]);
|
|
||||||
// if (key) {
|
|
||||||
// const privateKey = decryptKey(local[key], pin);
|
|
||||||
// console.log('privateKey :', privateKey);
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
};
|
};
|
||||||
|
@ -1,24 +1,18 @@
|
|||||||
import { getUser } from '../../providers/steem/dsteem';
|
import { fetchGlobalProps } from '../../providers/steem/dsteem';
|
||||||
import {
|
import {
|
||||||
FETCH_ACCOUNT_FAIL,
|
|
||||||
FETCHING_ACCOUNT,
|
|
||||||
ADD_OTHER_ACCOUNT,
|
ADD_OTHER_ACCOUNT,
|
||||||
|
FETCH_ACCOUNT_FAIL,
|
||||||
|
REMOVE_OTHER_ACCOUNT,
|
||||||
|
SET_GLOBAL_PROPS,
|
||||||
|
SET_PIN_CODE,
|
||||||
UPDATE_CURRENT_ACCOUNT,
|
UPDATE_CURRENT_ACCOUNT,
|
||||||
UPDATE_UNREAD_ACTIVITY_COUNT,
|
UPDATE_UNREAD_ACTIVITY_COUNT,
|
||||||
REMOVE_OTHER_ACCOUNT,
|
|
||||||
SET_PIN_CODE,
|
|
||||||
} from '../constants/constants';
|
} from '../constants/constants';
|
||||||
|
|
||||||
export const fetchAccountFromSteem = (username, password) => (dispatch) => {
|
export const fetchGlobalProperties = () => dispatch => fetchGlobalProps().then(res => dispatch({
|
||||||
dispatch({ type: FETCHING_ACCOUNT });
|
type: SET_GLOBAL_PROPS,
|
||||||
|
payload: { ...res },
|
||||||
return getUser(username)
|
}));
|
||||||
.then(res => dispatch({
|
|
||||||
type: UPDATE_CURRENT_ACCOUNT,
|
|
||||||
payload: { ...res, password },
|
|
||||||
}))
|
|
||||||
.catch(err => dispatch({ type: FETCH_ACCOUNT_FAIL, payload: err }));
|
|
||||||
};
|
|
||||||
|
|
||||||
export const updateCurrentAccount = data => ({
|
export const updateCurrentAccount = data => ({
|
||||||
type: UPDATE_CURRENT_ACCOUNT,
|
type: UPDATE_CURRENT_ACCOUNT,
|
||||||
@ -49,3 +43,8 @@ export const setPinCode = data => ({
|
|||||||
type: SET_PIN_CODE,
|
type: SET_PIN_CODE,
|
||||||
payload: data,
|
payload: data,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const setGlobalProps = data => ({
|
||||||
|
type: SET_GLOBAL_PROPS,
|
||||||
|
payload: data,
|
||||||
|
});
|
||||||
|
@ -24,11 +24,12 @@ export const SET_UPVOTE_PERCENT = 'SET_UPVOTE_PERCENT';
|
|||||||
// Accounts
|
// Accounts
|
||||||
export const ADD_OTHER_ACCOUNT = 'ADD_OTHER_ACCOUNT';
|
export const ADD_OTHER_ACCOUNT = 'ADD_OTHER_ACCOUNT';
|
||||||
export const FETCH_ACCOUNT_FAIL = 'FETCH_ACCOUNT_FAIL';
|
export const FETCH_ACCOUNT_FAIL = 'FETCH_ACCOUNT_FAIL';
|
||||||
export const FETCHING_ACCOUNT = 'FETCHING_ACCOUNT';
|
|
||||||
export const REMOVE_OTHER_ACCOUNT = 'REMOVE_OTHER_ACCOUNT';
|
export const REMOVE_OTHER_ACCOUNT = 'REMOVE_OTHER_ACCOUNT';
|
||||||
export const UPDATE_CURRENT_ACCOUNT = 'UPDATE_CURRENT_ACCOUNT';
|
export const UPDATE_CURRENT_ACCOUNT = 'UPDATE_CURRENT_ACCOUNT';
|
||||||
export const UPDATE_UNREAD_ACTIVITY_COUNT = 'UPDATE_UNREAD_ACTIVITY_COUNT';
|
export const UPDATE_UNREAD_ACTIVITY_COUNT = 'UPDATE_UNREAD_ACTIVITY_COUNT';
|
||||||
export const SET_PIN_CODE = 'SET_PIN_CODE';
|
export const SET_PIN_CODE = 'SET_PIN_CODE';
|
||||||
|
export const SET_GLOBAL_PROPS = 'SET_GLOBAL_PROPS';
|
||||||
|
export const FETCH_GLOBAL_PROPS = 'FETCH_GLOBAL_PROPS';
|
||||||
|
|
||||||
// UI
|
// UI
|
||||||
export const IS_COLLAPSE_POST_BUTTON = 'IS_COLLAPSE_POST_BUTTON';
|
export const IS_COLLAPSE_POST_BUTTON = 'IS_COLLAPSE_POST_BUTTON';
|
||||||
|
@ -7,6 +7,7 @@ import {
|
|||||||
REMOVE_OTHER_ACCOUNT,
|
REMOVE_OTHER_ACCOUNT,
|
||||||
LOGOUT_FAIL,
|
LOGOUT_FAIL,
|
||||||
SET_PIN_CODE,
|
SET_PIN_CODE,
|
||||||
|
SET_GLOBAL_PROPS,
|
||||||
} from '../constants/constants';
|
} from '../constants/constants';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
@ -29,6 +30,12 @@ export default function (state = initialState, action) {
|
|||||||
errorMessage: null,
|
errorMessage: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
case SET_GLOBAL_PROPS:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
globalProps: action.payload,
|
||||||
|
};
|
||||||
|
|
||||||
case FETCH_ACCOUNT_FAIL:
|
case FETCH_ACCOUNT_FAIL:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
@ -5,6 +5,7 @@ import { addLocaleData } from 'react-intl';
|
|||||||
import Config from 'react-native-config';
|
import Config from 'react-native-config';
|
||||||
import AppCenter from 'appcenter';
|
import AppCenter from 'appcenter';
|
||||||
import { NavigationActions } from 'react-navigation';
|
import { NavigationActions } from 'react-navigation';
|
||||||
|
import { bindActionCreators } from 'redux';
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
import en from 'react-intl/locale-data/en';
|
import en from 'react-intl/locale-data/en';
|
||||||
@ -37,6 +38,7 @@ import {
|
|||||||
updateCurrentAccount,
|
updateCurrentAccount,
|
||||||
updateUnreadActivityCount,
|
updateUnreadActivityCount,
|
||||||
removeOtherAccount,
|
removeOtherAccount,
|
||||||
|
fetchGlobalProperties,
|
||||||
} from '../../../redux/actions/accountAction';
|
} from '../../../redux/actions/accountAction';
|
||||||
import {
|
import {
|
||||||
activeApplication,
|
activeApplication,
|
||||||
@ -69,8 +71,11 @@ class ApplicationContainer extends Component {
|
|||||||
|
|
||||||
componentDidMount = async () => {
|
componentDidMount = async () => {
|
||||||
BackHandler.addEventListener('hardwareBackPress', this._onBackPress);
|
BackHandler.addEventListener('hardwareBackPress', this._onBackPress);
|
||||||
|
this._refreshGlobalProps();
|
||||||
await this._getUserData();
|
await this._getUserData();
|
||||||
await this._getSettings();
|
await this._getSettings();
|
||||||
|
|
||||||
|
this.globalInterval = setInterval(this._refreshGlobalProps, 60000);
|
||||||
};
|
};
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
@ -87,6 +92,7 @@ class ApplicationContainer extends Component {
|
|||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
BackHandler.removeEventListener('hardwareBackPress', this.onBackPress);
|
BackHandler.removeEventListener('hardwareBackPress', this.onBackPress);
|
||||||
|
clearInterval(this.globalInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onBackPress = () => {
|
_onBackPress = () => {
|
||||||
@ -100,6 +106,12 @@ class ApplicationContainer extends Component {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_refreshGlobalProps = () => {
|
||||||
|
const { actions } = this.props;
|
||||||
|
|
||||||
|
actions.fetchGlobalProperties();
|
||||||
|
};
|
||||||
|
|
||||||
_getUserData = async () => {
|
_getUserData = async () => {
|
||||||
const { dispatch, pinCode } = this.props;
|
const { dispatch, pinCode } = this.props;
|
||||||
let realmData = [];
|
let realmData = [];
|
||||||
@ -280,20 +292,25 @@ class ApplicationContainer extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
export default connect(
|
||||||
// Application
|
state => ({
|
||||||
isDarkTheme: state.application.isDarkTheme,
|
// Application
|
||||||
selectedLanguage: state.application.language,
|
isDarkTheme: state.application.isDarkTheme,
|
||||||
notificationSettings: state.application.isNotificationOpen,
|
selectedLanguage: state.application.language,
|
||||||
isLogingOut: state.application.isLogingOut,
|
notificationSettings: state.application.isNotificationOpen,
|
||||||
isLoggedIn: state.application.isLoggedIn,
|
isLogingOut: state.application.isLogingOut,
|
||||||
nav: state.nav.routes,
|
isLoggedIn: state.application.isLoggedIn,
|
||||||
|
|
||||||
// Account
|
// Account
|
||||||
unreadActivityCount: state.account.currentAccount.unread_activity_count,
|
unreadActivityCount: state.account.currentAccount.unread_activity_count,
|
||||||
currentAccount: state.account.currentAccount,
|
currentAccount: state.account.currentAccount,
|
||||||
otherAccounts: state.account.otherAccounts,
|
otherAccounts: state.account.otherAccounts,
|
||||||
pinCode: state.account.pin,
|
pinCode: state.account.pin,
|
||||||
});
|
}),
|
||||||
|
(dispatch, props) => ({
|
||||||
export default connect(mapStateToProps)(ApplicationContainer);
|
dispatch,
|
||||||
|
actions: {
|
||||||
|
...bindActionCreators({ fetchGlobalProperties }, dispatch),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
)(ApplicationContainer);
|
@ -1 +1,7 @@
|
|||||||
export const vestsToSp = (vests, steemPerMVests) => (vests / 1e6) * steemPerMVests;
|
export const vestsToSp = (vests, steemPerMVests) => (vests / 1e6) * steemPerMVests;
|
||||||
|
|
||||||
|
export const vestsToRshares = (vests, votingPower, votePerc) => {
|
||||||
|
const vestingShares = parseInt(vests * 1e6, 10);
|
||||||
|
const power = (votingPower * votePerc) / 1e4 / 50 + 1;
|
||||||
|
return (power * vestingShares) / 1e4;
|
||||||
|
};
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import parseDate from './parseDate';
|
import parseDate from './parseDate';
|
||||||
import parseToken from './parseToken';
|
import parseToken from './parseToken';
|
||||||
import { vestsToSp } from './conversions';
|
import { vestsToSp } from './conversions';
|
||||||
import { globalProps, getState, getFeedHistory } from '../providers/steem/dsteem';
|
import { getState, getFeedHistory } from '../providers/steem/dsteem';
|
||||||
|
|
||||||
export const groomingTransactionData = (transaction, walletData, formatNumber) => {
|
|
||||||
if (!transaction || !walletData) {
|
export const groomingTransactionData = (transaction, steemPerMVests, formatNumber) => {
|
||||||
|
if (!transaction || !steemPerMVests) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +24,7 @@ export const groomingTransactionData = (transaction, walletData, formatNumber) =
|
|||||||
const { reward } = opData;
|
const { reward } = opData;
|
||||||
const { comment_author: commentAuthor, comment_permlink: commentPermlink } = opData;
|
const { comment_author: commentAuthor, comment_permlink: commentPermlink } = opData;
|
||||||
|
|
||||||
result.value = `${formatNumber(vestsToSp(parseToken(reward), walletData.steemPerMVests), {
|
result.value = `${formatNumber(vestsToSp(parseToken(reward), steemPerMVests), {
|
||||||
minimumFractionDigits: 3,
|
minimumFractionDigits: 3,
|
||||||
})} SP`;
|
})} SP`;
|
||||||
result.details = `@${commentAuthor}/${commentPermlink}`;
|
result.details = `@${commentAuthor}/${commentPermlink}`;
|
||||||
@ -41,7 +42,7 @@ export const groomingTransactionData = (transaction, walletData, formatNumber) =
|
|||||||
sbdPayout = formatNumber(parseToken(sbdPayout), { minimumFractionDigits: 3 });
|
sbdPayout = formatNumber(parseToken(sbdPayout), { minimumFractionDigits: 3 });
|
||||||
steemPayout = formatNumber(parseToken(steemPayout), { minimumFractionDigits: 3 });
|
steemPayout = formatNumber(parseToken(steemPayout), { minimumFractionDigits: 3 });
|
||||||
vestingPayout = formatNumber(
|
vestingPayout = formatNumber(
|
||||||
vestsToSp(parseToken(vestingPayout), walletData.steemPerMVests),
|
vestsToSp(parseToken(vestingPayout), steemPerMVests),
|
||||||
{ minimumFractionDigits: 3 },
|
{ minimumFractionDigits: 3 },
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -59,7 +60,7 @@ export const groomingTransactionData = (transaction, walletData, formatNumber) =
|
|||||||
|
|
||||||
rewardSdb = formatNumber(parseToken(rewardSdb), { minimumFractionDigits: 3 });
|
rewardSdb = formatNumber(parseToken(rewardSdb), { minimumFractionDigits: 3 });
|
||||||
rewardSteem = formatNumber(parseToken(rewardSteem), { minimumFractionDigits: 3 });
|
rewardSteem = formatNumber(parseToken(rewardSteem), { minimumFractionDigits: 3 });
|
||||||
rewardVests = formatNumber(vestsToSp(parseToken(rewardVests), walletData.steemPerMVests), {
|
rewardVests = formatNumber(vestsToSp(parseToken(rewardVests), steemPerMVests), {
|
||||||
minimumFractionDigits: 3,
|
minimumFractionDigits: 3,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -83,7 +84,7 @@ export const groomingTransactionData = (transaction, walletData, formatNumber) =
|
|||||||
let { vesting_shares: opVestingShares } = opData;
|
let { vesting_shares: opVestingShares } = opData;
|
||||||
|
|
||||||
opVestingShares = parseToken(opVestingShares);
|
opVestingShares = parseToken(opVestingShares);
|
||||||
result.value = `${formatNumber(vestsToSp(opVestingShares, walletData.steemPerMVests), {
|
result.value = `${formatNumber(vestsToSp(opVestingShares, steemPerMVests), {
|
||||||
minimumFractionDigits: 3,
|
minimumFractionDigits: 3,
|
||||||
})} SP`;
|
})} SP`;
|
||||||
result.icon = 'attach-money';
|
result.icon = 'attach-money';
|
||||||
@ -101,14 +102,13 @@ export const groomingTransactionData = (transaction, walletData, formatNumber) =
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const groomingWalletData = async (user) => {
|
export const groomingWalletData = async (user, globalProps) => {
|
||||||
const walletData = {};
|
const walletData = {};
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return walletData;
|
return walletData;
|
||||||
}
|
}
|
||||||
|
|
||||||
const global = await globalProps();
|
|
||||||
const state = await getState(`/@${user.name}/transfers`);
|
const state = await getState(`/@${user.name}/transfers`);
|
||||||
const { accounts } = state;
|
const { accounts } = state;
|
||||||
|
|
||||||
@ -133,9 +133,7 @@ export const groomingWalletData = async (user) => {
|
|||||||
const base = parseToken(feedHistory.current_median_history.base);
|
const base = parseToken(feedHistory.current_median_history.base);
|
||||||
const quote = parseToken(feedHistory.current_median_history.quote);
|
const quote = parseToken(feedHistory.current_median_history.quote);
|
||||||
|
|
||||||
walletData.steemPerMVests = (
|
walletData.steemPerMVests = globalProps.steemPerMVests;
|
||||||
parseToken(global.total_vesting_fund_steem) / parseToken(global.total_vesting_shares)
|
|
||||||
) * 1e6;
|
|
||||||
|
|
||||||
walletData.estimatedValue = (
|
walletData.estimatedValue = (
|
||||||
vestsToSp(walletData.vestingShares, walletData.steemPerMVests) * (base / quote)
|
vestsToSp(walletData.vestingShares, walletData.steemPerMVests) * (base / quote)
|
||||||
|
Loading…
Reference in New Issue
Block a user