Merge pull request #1380 from esteemapp/bugfix/walletpage

Wallet bug fixes
This commit is contained in:
Feruz M 2019-12-11 08:10:10 +02:00 committed by GitHub
commit ec06701a30
7 changed files with 43 additions and 29 deletions

View File

@ -16,6 +16,7 @@ import globalStyles from '../../globalStyles';
const TransactionView = ({ transactions, type, refreshing, setRefreshing, isLoading }) => { const TransactionView = ({ transactions, type, refreshing, setRefreshing, isLoading }) => {
const intl = useIntl(); const intl = useIntl();
const transaction_types = ['ESTM', 'STEEM', 'SBD', 'SP'];
const _renderLoading = () => { const _renderLoading = () => {
if (isLoading) { if (isLoading) {
@ -44,7 +45,8 @@ const TransactionView = ({ transactions, type, refreshing, setRefreshing, isLoad
const _renderItem = (item, index) => { const _renderItem = (item, index) => {
return ( return (
Object.keys(item).length > 0 && ( Object.keys(item).length > 0 &&
item.value.indexOf(transaction_types[type]) > -1 && (
<CollapsibleCard <CollapsibleCard
key={item.created.toString()} key={item.created.toString()}
noBorder noBorder

View File

@ -19,6 +19,7 @@
"outgoing_transfer_title": "Outgoing transfer", "outgoing_transfer_title": "Outgoing transfer",
"checkin_extra": "Bonus", "checkin_extra": "Bonus",
"delegation": "Delegation", "delegation": "Delegation",
"delegations": "Delegations",
"delegation_title": "Delegation reward", "delegation_title": "Delegation reward",
"delegation_desc": "Earn ESTM everyday for delegation", "delegation_desc": "Earn ESTM everyday for delegation",
"post_title": "Points for post", "post_title": "Points for post",

View File

@ -55,6 +55,7 @@ const WalletContainer = ({
const [estimatedSpValue, setEstimatedSpValue] = useState(0); const [estimatedSpValue, setEstimatedSpValue] = useState(0);
const [unclaimedBalance, setUnclaimedBalance] = useState(''); const [unclaimedBalance, setUnclaimedBalance] = useState('');
const [estimatedAmount, setEstimatedAmount] = useState(0); const [estimatedAmount, setEstimatedAmount] = useState(0);
const [delegationsAmount, setDelegationsAmount] = useState(0);
const [transferHistory, setTransferHistory] = useState([]); const [transferHistory, setTransferHistory] = useState([]);
const intl = useIntl(); const intl = useIntl();
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -67,10 +68,6 @@ const WalletContainer = ({
_getWalletData(selectedUser); _getWalletData(selectedUser);
}, [_getWalletData, selectedUser]); }, [_getWalletData, selectedUser]);
useEffect(() => {
_getWalletData(selectedUser);
}, [_getWalletData, selectedUser]);
useEffect(() => { useEffect(() => {
const _transferHistory = userActivities.filter( const _transferHistory = userActivities.filter(
item => item =>
@ -106,6 +103,12 @@ const WalletContainer = ({
setEstimatedSteemValue(get(walletData, 'estimatedSteemValue', 0)); setEstimatedSteemValue(get(walletData, 'estimatedSteemValue', 0));
setEstimatedSbdValue(get(walletData, 'estimatedSbdValue', 0)); setEstimatedSbdValue(get(walletData, 'estimatedSbdValue', 0));
setEstimatedSpValue(get(walletData, 'estimatedSpValue', 0)); setEstimatedSpValue(get(walletData, 'estimatedSpValue', 0));
setDelegationsAmount(
vestsToSp(
get(walletData, 'vestingSharesReceived', 0) - get(walletData, 'vestingSharesDelegated', 0),
get(walletData, 'steemPerMVests', 0),
).toFixed(3),
);
setUnclaimedBalance( setUnclaimedBalance(
`${ `${
@ -140,9 +143,6 @@ const WalletContainer = ({
), ),
); );
setEstimatedWalletValue && setEstimatedWalletValue(_walletData.estimatedValue); setEstimatedWalletValue && setEstimatedWalletValue(_walletData.estimatedValue);
setEstimatedSbdValue && setEstimatedSbdValue(_walletData.estimatedSbdValue);
setEstimatedSteemValue && setEstimatedSteemValue(_walletData.estimatedSteemValue);
setEstimatedSpValue && setEstimatedSpValue(_walletData.estimatedSpValue);
}, },
[globalProps, intl.formatNumber, setEstimatedWalletValue, steemPerMVests], [globalProps, intl.formatNumber, setEstimatedWalletValue, steemPerMVests],
); );
@ -282,6 +282,7 @@ const WalletContainer = ({
estimatedSteemValue, estimatedSteemValue,
estimatedSbdValue, estimatedSbdValue,
estimatedSpValue, estimatedSpValue,
delegationsAmount,
navigate: _navigate, navigate: _navigate,
steemDropdown: STEEM_DROPDOWN, steemDropdown: STEEM_DROPDOWN,
sbdDropdown: SBD_DROPDOWN, sbdDropdown: SBD_DROPDOWN,

View File

@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { View } from 'react-native'; import { View, Text } from 'react-native';
import { WalletHeader, FormattedCurrency } from '../../../components'; import { WalletHeader, FormattedCurrency } from '../../../components';
import { SteemWalletContainer, AccountContainer } from '../../../containers'; import { SteemWalletContainer, AccountContainer } from '../../../containers';
@ -20,6 +20,7 @@ const SpView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) =
spBalance, spBalance,
isLoading, isLoading,
estimatedSpValue, estimatedSpValue,
delegationsAmount,
steemPowerDropdown, steemPowerDropdown,
unclaimedBalance, unclaimedBalance,
navigate, navigate,
@ -45,6 +46,15 @@ const SpView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) =
currentIndex={currentIndex} currentIndex={currentIndex}
showIconList={false} showIconList={false}
valueDescriptions={[ valueDescriptions={[
{
textKey: 'delegations',
value: (
<Text>
{delegationsAmount}
{' SP'}
</Text>
),
},
{ {
textKey: 'estimated_value', textKey: 'estimated_value',
value: <FormattedCurrency isApproximate isToken value={estimatedSpValue} />, value: <FormattedCurrency isApproximate isToken value={estimatedSpValue} />,

View File

@ -100,7 +100,7 @@ const WalletScreen = () => {
scrollEventThrottle={16} scrollEventThrottle={16}
> >
<Transaction <Transaction
type="wallet" type={currentIndex}
transactions={selectedUserActivities} transactions={selectedUserActivities}
refreshing={false} refreshing={false}
setRefreshing={setRefreshing} setRefreshing={setRefreshing}

View File

@ -172,25 +172,28 @@ export const groomingWalletData = async (user, globalProps, userCurrency) => {
const state = await getState(`/@${get(user, 'name')}/transfers`); const state = await getState(`/@${get(user, 'name')}/transfers`);
const { accounts } = state; const { accounts } = state;
if (!accounts) {
return walletData;
}
const userdata = get(accounts, get(user, 'name'), '');
// TODO: move them to utils these so big for a lifecycle function // TODO: move them to utils these so big for a lifecycle function
walletData.rewardSteemBalance = parseToken(user.reward_steem_balance); walletData.rewardSteemBalance = parseToken(userdata.reward_steem_balance);
walletData.rewardSbdBalance = parseToken(user.reward_sbd_balance); walletData.rewardSbdBalance = parseToken(userdata.reward_sbd_balance);
walletData.rewardVestingSteem = parseToken(user.reward_vesting_steem); walletData.rewardVestingSteem = parseToken(userdata.reward_vesting_steem);
walletData.hasUnclaimedRewards = walletData.hasUnclaimedRewards =
walletData.rewardSteemBalance > 0 || walletData.rewardSteemBalance > 0 ||
walletData.rewardSbdBalance > 0 || walletData.rewardSbdBalance > 0 ||
walletData.rewardVestingSteem > 0; walletData.rewardVestingSteem > 0;
walletData.balance = parseToken(user.balance); walletData.balance = parseToken(userdata.balance);
walletData.vestingShares = parseToken(user.vesting_shares); walletData.vestingShares = parseToken(userdata.vesting_shares);
walletData.vestingSharesDelegated = parseToken(user.delegated_vesting_shares); walletData.vestingSharesDelegated = parseToken(userdata.delegated_vesting_shares);
walletData.vestingSharesReceived = parseToken(user.received_vesting_shares); walletData.vestingSharesReceived = parseToken(userdata.received_vesting_shares);
walletData.vestingSharesTotal = walletData.vestingSharesTotal =
walletData.vestingShares - walletData.vestingSharesDelegated + walletData.vestingSharesReceived; walletData.vestingShares - walletData.vestingSharesDelegated + walletData.vestingSharesReceived;
walletData.sbdBalance = parseToken(userdata.sbd_balance);
walletData.sbdBalance = parseToken(user.sbd_balance); walletData.savingBalance = parseToken(userdata.savings_balance);
walletData.savingBalance = parseToken(user.savings_balance); walletData.savingBalanceSbd = parseToken(userdata.savings_sbd_balance);
walletData.savingBalanceSbd = parseToken(user.savings_sbd_balance);
const feedHistory = await getFeedHistory(); const feedHistory = await getFeedHistory();
const base = parseToken(feedHistory.current_median_history.base); const base = parseToken(feedHistory.current_median_history.base);
@ -215,17 +218,14 @@ export const groomingWalletData = async (user, globalProps, userCurrency) => {
walletData.estimatedSteemValue = (walletData.balance + walletData.savingBalance) * ppSteem; walletData.estimatedSteemValue = (walletData.balance + walletData.savingBalance) * ppSteem;
walletData.estimatedSbdValue = totalSbd * ppSbd; walletData.estimatedSbdValue = totalSbd * ppSbd;
walletData.estimatedSpValue = walletData.estimatedSpValue =
vestsToSp(walletData.vestingSharesTotal, walletData.steemPerMVests) * ppSteem; vestsToSp(walletData.vestingShares, walletData.steemPerMVests) * ppSteem;
walletData.showPowerDown = user.next_vesting_withdrawal !== '1969-12-31T23:59:59'; walletData.showPowerDown = userdata.next_vesting_withdrawal !== '1969-12-31T23:59:59';
const timeDiff = Math.abs(parseDate(user.next_vesting_withdrawal) - new Date()); const timeDiff = Math.abs(parseDate(userdata.next_vesting_withdrawal) - new Date());
walletData.nextVestingWithdrawal = Math.round(timeDiff / (1000 * 3600)); walletData.nextVestingWithdrawal = Math.round(timeDiff / (1000 * 3600));
const { transfer_history: transferHistory, other_history: virtualHistory } = get( const { transfer_history: transferHistory, other_history: virtualHistory } = userdata;
accounts,
user.name,
[],
);
const realHistory = transferHistory const realHistory = transferHistory
? transferHistory.slice(Math.max(transferHistory.length - 50, 0)) ? transferHistory.slice(Math.max(transferHistory.length - 50, 0))
: []; : [];