done with sp view

This commit is contained in:
ue 2019-11-26 21:58:19 +03:00
parent d064ed60f6
commit 7f7e59d666
9 changed files with 70 additions and 45 deletions

View File

@ -1,7 +1,7 @@
/* eslint-disable react/jsx-wrap-multilines */ /* eslint-disable react/jsx-wrap-multilines */
import React from 'react'; import React from 'react';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import { View, Text, FlatList } from 'react-native'; import { View, Text, FlatList, RefreshControl } from 'react-native';
import get from 'lodash/get'; import get from 'lodash/get';
import isEmpty from 'lodash/isEmpty'; import isEmpty from 'lodash/isEmpty';
@ -11,10 +11,11 @@ import { getTimeFromNow } from '../../utils/time';
// Components // Components
import { WalletLineItem, ListPlaceHolder } from '../basicUIElements'; import { WalletLineItem, ListPlaceHolder } from '../basicUIElements';
import { CollapsibleCard } from '..'; import { CollapsibleCard } from '..';
import { ThemeContainer } from '../../containers';
import globalStyles from '../../globalStyles'; import globalStyles from '../../globalStyles';
const TransactionView = ({ transactions, type }) => { const TransactionView = ({ transactions, type, refreshing, setRefreshing }) => {
const intl = useIntl(); const intl = useIntl();
const _renderLoading = () => { const _renderLoading = () => {
@ -27,6 +28,21 @@ const TransactionView = ({ transactions, type }) => {
); );
}; };
const refreshControl = () => (
<ThemeContainer>
{isDarkTheme => (
<RefreshControl
refreshing={refreshing}
onRefresh={() => setRefreshing(true)}
progressBackgroundColor="#357CE6"
tintColor={!isDarkTheme ? '#357ce6' : '#96c0ff'}
titleColor="#fff"
colors={['#fff']}
/>
)}
</ThemeContainer>
);
const _renderItem = (item, index) => { const _renderItem = (item, index) => {
return ( return (
<CollapsibleCard <CollapsibleCard
@ -69,6 +85,8 @@ const TransactionView = ({ transactions, type }) => {
<FlatList <FlatList
data={transactions} data={transactions}
ListEmptyComponent={_renderLoading()} ListEmptyComponent={_renderLoading()}
onRefresh={refreshControl}
refreshing={refreshing}
renderItem={({ item, index }) => _renderItem(item, index)} renderItem={({ item, index }) => _renderItem(item, index)}
/> />
</View> </View>

View File

@ -8,6 +8,7 @@ import get from 'lodash/get';
// Utils // Utils
import parseToken from '../../../utils/parseToken'; import parseToken from '../../../utils/parseToken';
import { vestsToRshares } from '../../../utils/conversions'; import { vestsToRshares } from '../../../utils/conversions';
import { getEstimatedAmount } from '../../../utils/vote';
// Components // Components
import { Icon } from '../../icon'; import { Icon } from '../../icon';
@ -71,20 +72,9 @@ class UpvoteView extends Component {
if (currentAccount && Object.entries(currentAccount).length !== 0) { if (currentAccount && Object.entries(currentAccount).length !== 0) {
const { sliderValue } = this.state; const { sliderValue } = this.state;
const { fundRecentClaims, fundRewardBalance, base, quote } = globalProps;
const votingPower = currentAccount.voting_power;
const totalVests =
parseToken(get(currentAccount, 'vesting_shares')) +
parseToken(get(currentAccount, 'received_vesting_shares')) -
parseToken(get(currentAccount, 'delegated_vesting_shares'));
const votePct = sliderValue * 10000;
const rShares = vestsToRshares(totalVests, votingPower, votePct);
const estimated = (rShares / fundRecentClaims) * fundRewardBalance * (base / quote);
this.setState({ this.setState({
amount: estimated.toFixed(5), amount: getEstimatedAmount(currentAccount, globalProps, sliderValue),
}); });
} }
}; };

View File

@ -86,13 +86,11 @@ const WalletHeaderView = ({
isDisable={isClaiming} isDisable={isClaiming}
style={styles.mainButton} style={styles.mainButton}
height={50} height={50}
onPress={() => onPress={() => (unclaimedBalance ? claim() : navigation.navigate(ROUTES.SCREENS.BOOST))}
unclaimedBalance > 0 ? claim() : navigation.navigate(ROUTES.SCREENS.BOOST)
}
> >
<View style={styles.mainButtonWrapper}> <View style={styles.mainButtonWrapper}>
<Text style={styles.unclaimedText}> <Text style={styles.unclaimedText}>
{unclaimedBalance > 0 {unclaimedBalance
? unclaimedBalance ? unclaimedBalance
: intl.formatMessage({ id: `wallet.${type}.buy` })} : intl.formatMessage({ id: `wallet.${type}.buy` })}
</Text> </Text>
@ -126,18 +124,3 @@ const WalletHeaderView = ({
}; };
export default withNavigation(WalletHeaderView); export default withNavigation(WalletHeaderView);
// const refreshControl = () => (
// <ThemeContainer>
// {isDarkTheme => (
// <RefreshControl
// refreshing={refreshing}
// onRefresh={fetchUserActivity}
// progressBackgroundColor="#357CE6"
// tintColor={!isDarkTheme ? '#357ce6' : '#96c0ff'}
// titleColor="#fff"
// colors={['#fff']}
// />
// )}
// </ThemeContainer>
// );

View File

@ -45,6 +45,7 @@
"to": "To", "to": "To",
"estimated_value_desc": "*determined by purchase value", "estimated_value_desc": "*determined by purchase value",
"estimated_value": "Estimated value", "estimated_value": "Estimated value",
"estimated_amount": "Vote value",
"amount_information": "Drag the slider to adjust the amount", "amount_information": "Drag the slider to adjust the amount",
"amount": "Amount", "amount": "Amount",
"memo": "Memo", "memo": "Memo",

View File

@ -16,6 +16,7 @@ import { groomingWalletData, groomingTransactionData } from '../utils/wallet';
import parseToken from '../utils/parseToken'; import parseToken from '../utils/parseToken';
import { vestsToSp } from '../utils/conversions'; import { vestsToSp } from '../utils/conversions';
import { navigate } from '../navigation/service'; import { navigate } from '../navigation/service';
import { getEstimatedAmount } from '../utils/vote';
// Constants // Constants
import ROUTES from '../constants/routeNames'; import ROUTES from '../constants/routeNames';
@ -48,9 +49,14 @@ const WalletContainer = ({
const [steemSavingBalance, setSteemSavingBalance] = useState(0); const [steemSavingBalance, setSteemSavingBalance] = useState(0);
const [estimatedValue, setEstimatedValue] = useState(0); const [estimatedValue, setEstimatedValue] = useState(0);
const [unclaimedBalance, setUnclaimedBalance] = useState(''); const [unclaimedBalance, setUnclaimedBalance] = useState('');
const [estimatedAmount, setEstimatedAmount] = useState(0);
const intl = useIntl(); const intl = useIntl();
const dispatch = useDispatch(); const dispatch = useDispatch();
useEffect(() => {
setEstimatedAmount(getEstimatedAmount(currentAccount, globalProps));
}, [currentAccount, globalProps]);
useEffect(() => { useEffect(() => {
_getWalletData(selectedUser); _getWalletData(selectedUser);
}, [_getWalletData, selectedUser]); }, [_getWalletData, selectedUser]);
@ -138,7 +144,7 @@ const WalletContainer = ({
}) })
.then(() => getAccount(currentAccount.name)) .then(() => getAccount(currentAccount.name))
.then(account => { .then(account => {
_getWalletData(account && account[0]); _getWalletData(selectedUser);
if (isHasUnclaimedRewards) { if (isHasUnclaimedRewards) {
dispatch( dispatch(
toastNotification( toastNotification(
@ -150,7 +156,7 @@ const WalletContainer = ({
} }
}) })
.then(account => { .then(account => {
_getWalletData(account && account[0]); _getWalletData(selectedUser);
setIsClaiming(false); setIsClaiming(false);
}) })
.catch(() => { .catch(() => {
@ -171,7 +177,7 @@ const WalletContainer = ({
getAccount(selectedUser.name) getAccount(selectedUser.name)
.then(account => { .then(account => {
_getWalletData(account && account[0]); _getWalletData(selectedUser);
setRefreshing(false); setRefreshing(false);
}) })
.catch(() => { .catch(() => {
@ -245,7 +251,8 @@ const WalletContainer = ({
savingSteemDropdown: SAVING_STEEM_DROPDOWN, savingSteemDropdown: SAVING_STEEM_DROPDOWN,
savingSbdDropdown: SAVING_SBD_DROPDOWN, savingSbdDropdown: SAVING_SBD_DROPDOWN,
steemPowerDropdown: STEEM_POWER_DROPDOWN, steemPowerDropdown: STEEM_POWER_DROPDOWN,
unclaimedBalance: unclaimedBalance.trim(), unclaimedBalance: unclaimedBalance && unclaimedBalance.trim(),
estimatedAmount,
}) })
); );
}; };

View File

@ -22,7 +22,7 @@ const EstmView = ({ handleOnSelected, index, currentIndex }) => (
dropdownOptions, dropdownOptions,
}) => ( }) => (
<WalletHeader <WalletHeader
componentDidUpdate={() => handleOnSelected(userActivities, 'estm')} componentDidUpdate={() => handleOnSelected(userActivities, 'estm', fetchUserActivity)}
index={index} index={index}
showIconList showIconList
claim={claim} claim={claim}
@ -31,7 +31,9 @@ const EstmView = ({ handleOnSelected, index, currentIndex }) => (
isLoading={isLoading} isLoading={isLoading}
refreshing={refreshing} refreshing={refreshing}
userActivities={userActivities} userActivities={userActivities}
unclaimedBalance={get(userPoints, 'unclaimed_points', 0)} unclaimedBalance={
get(userPoints, 'unclaimed_points') > 0 && get(userPoints, 'unclaimed_points')
}
userBalance={[ userBalance={[
{ balance: get(userPoints, 'points'), nameKey: 'estm', options: dropdownOptions }, { balance: get(userPoints, 'points'), nameKey: 'estm', options: dropdownOptions },
]} ]}

View File

@ -19,12 +19,11 @@ const SpView = ({ handleOnSelected, index, currentIndex }) => (
userActivities, userActivities,
spBalance, spBalance,
isLoading, isLoading,
steemSavingBalance,
estimatedValue, estimatedValue,
steemPowerDropdown, steemPowerDropdown,
savingSteemDropdown,
unclaimedBalance, unclaimedBalance,
navigate, navigate,
estimatedAmount,
}) => ( }) => (
<WalletHeader <WalletHeader
componentDidUpdate={() => handleOnSelected(userActivities, 'steem_power')} componentDidUpdate={() => handleOnSelected(userActivities, 'steem_power')}
@ -50,8 +49,8 @@ const SpView = ({ handleOnSelected, index, currentIndex }) => (
value: <FormatedCurrency isApproximate value={estimatedValue} />, value: <FormatedCurrency isApproximate value={estimatedValue} />,
}, },
{ {
textKey: 'estimated_value', textKey: 'estimated_amount',
value: <FormatedCurrency isApproximate value={estimatedValue} />, value: <FormatedCurrency isApproximate value={estimatedAmount} />,
}, },
]} ]}
/> />

View File

@ -18,8 +18,9 @@ const WalletScreen = () => {
const [selectedUserActivities, setSelectedUserActivities] = useState(null); const [selectedUserActivities, setSelectedUserActivities] = useState(null);
const [selectedType, setSelectedType] = useState('points'); const [selectedType, setSelectedType] = useState('points');
const [currentIndex, setCurrentIndex] = useState(0); const [currentIndex, setCurrentIndex] = useState(0);
const [refreshing, setRefreshing] = useState(false);
const _handleSwipeItemChange = (userActivities, type) => { const _handleSwipeItemChange = (userActivities, type, xx) => {
setSelectedUserActivities(userActivities); setSelectedUserActivities(userActivities);
setSelectedType(type); setSelectedType(type);
}; };
@ -40,21 +41,29 @@ const WalletScreen = () => {
<EstmView <EstmView
index={0} index={0}
handleOnSelected={_handleSwipeItemChange} handleOnSelected={_handleSwipeItemChange}
refreshing={refreshing}
currentIndex={currentIndex} currentIndex={currentIndex}
/> />
<SteemView <SteemView
index={1} index={1}
handleOnSelected={_handleSwipeItemChange} handleOnSelected={_handleSwipeItemChange}
refreshing={refreshing}
currentIndex={currentIndex} currentIndex={currentIndex}
/> />
<SpView <SpView
index={2} index={2}
refreshing={refreshing}
handleOnSelected={_handleSwipeItemChange} handleOnSelected={_handleSwipeItemChange}
currentIndex={currentIndex} currentIndex={currentIndex}
/> />
</Swiper> </Swiper>
<Transaction type="wallet" transactions={selectedUserActivities} /> <Transaction
type="wallet"
transactions={selectedUserActivities}
refreshing={refreshing}
setRefreshing={setRefreshing}
/>
</> </>
)} )}
</LoggedInContainer> </LoggedInContainer>

16
src/utils/vote.js Normal file
View File

@ -0,0 +1,16 @@
import parseToken from './parseToken';
import get from 'lodash/get';
import { vestsToRshares } from './conversions';
export const getEstimatedAmount = (account, globalProps, value = 100) => {
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);
return ((rShares / fundRecentClaims) * fundRewardBalance * (base / quote)).toFixed(5);
};