mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-20 11:51:52 +03:00
done with sp view
This commit is contained in:
parent
d064ed60f6
commit
7f7e59d666
@ -1,7 +1,7 @@
|
||||
/* eslint-disable react/jsx-wrap-multilines */
|
||||
import React from 'react';
|
||||
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 isEmpty from 'lodash/isEmpty';
|
||||
|
||||
@ -11,10 +11,11 @@ import { getTimeFromNow } from '../../utils/time';
|
||||
// Components
|
||||
import { WalletLineItem, ListPlaceHolder } from '../basicUIElements';
|
||||
import { CollapsibleCard } from '..';
|
||||
import { ThemeContainer } from '../../containers';
|
||||
|
||||
import globalStyles from '../../globalStyles';
|
||||
|
||||
const TransactionView = ({ transactions, type }) => {
|
||||
const TransactionView = ({ transactions, type, refreshing, setRefreshing }) => {
|
||||
const intl = useIntl();
|
||||
|
||||
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) => {
|
||||
return (
|
||||
<CollapsibleCard
|
||||
@ -69,6 +85,8 @@ const TransactionView = ({ transactions, type }) => {
|
||||
<FlatList
|
||||
data={transactions}
|
||||
ListEmptyComponent={_renderLoading()}
|
||||
onRefresh={refreshControl}
|
||||
refreshing={refreshing}
|
||||
renderItem={({ item, index }) => _renderItem(item, index)}
|
||||
/>
|
||||
</View>
|
||||
|
@ -8,6 +8,7 @@ import get from 'lodash/get';
|
||||
// Utils
|
||||
import parseToken from '../../../utils/parseToken';
|
||||
import { vestsToRshares } from '../../../utils/conversions';
|
||||
import { getEstimatedAmount } from '../../../utils/vote';
|
||||
|
||||
// Components
|
||||
import { Icon } from '../../icon';
|
||||
@ -71,20 +72,9 @@ class UpvoteView extends Component {
|
||||
|
||||
if (currentAccount && Object.entries(currentAccount).length !== 0) {
|
||||
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({
|
||||
amount: estimated.toFixed(5),
|
||||
amount: getEstimatedAmount(currentAccount, globalProps, sliderValue),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -86,13 +86,11 @@ const WalletHeaderView = ({
|
||||
isDisable={isClaiming}
|
||||
style={styles.mainButton}
|
||||
height={50}
|
||||
onPress={() =>
|
||||
unclaimedBalance > 0 ? claim() : navigation.navigate(ROUTES.SCREENS.BOOST)
|
||||
}
|
||||
onPress={() => (unclaimedBalance ? claim() : navigation.navigate(ROUTES.SCREENS.BOOST))}
|
||||
>
|
||||
<View style={styles.mainButtonWrapper}>
|
||||
<Text style={styles.unclaimedText}>
|
||||
{unclaimedBalance > 0
|
||||
{unclaimedBalance
|
||||
? unclaimedBalance
|
||||
: intl.formatMessage({ id: `wallet.${type}.buy` })}
|
||||
</Text>
|
||||
@ -126,18 +124,3 @@ const 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>
|
||||
// );
|
||||
|
@ -45,6 +45,7 @@
|
||||
"to": "To",
|
||||
"estimated_value_desc": "*determined by purchase value",
|
||||
"estimated_value": "Estimated value",
|
||||
"estimated_amount": "Vote value",
|
||||
"amount_information": "Drag the slider to adjust the amount",
|
||||
"amount": "Amount",
|
||||
"memo": "Memo",
|
||||
|
@ -16,6 +16,7 @@ import { groomingWalletData, groomingTransactionData } from '../utils/wallet';
|
||||
import parseToken from '../utils/parseToken';
|
||||
import { vestsToSp } from '../utils/conversions';
|
||||
import { navigate } from '../navigation/service';
|
||||
import { getEstimatedAmount } from '../utils/vote';
|
||||
|
||||
// Constants
|
||||
import ROUTES from '../constants/routeNames';
|
||||
@ -48,9 +49,14 @@ const WalletContainer = ({
|
||||
const [steemSavingBalance, setSteemSavingBalance] = useState(0);
|
||||
const [estimatedValue, setEstimatedValue] = useState(0);
|
||||
const [unclaimedBalance, setUnclaimedBalance] = useState('');
|
||||
const [estimatedAmount, setEstimatedAmount] = useState(0);
|
||||
const intl = useIntl();
|
||||
const dispatch = useDispatch();
|
||||
|
||||
useEffect(() => {
|
||||
setEstimatedAmount(getEstimatedAmount(currentAccount, globalProps));
|
||||
}, [currentAccount, globalProps]);
|
||||
|
||||
useEffect(() => {
|
||||
_getWalletData(selectedUser);
|
||||
}, [_getWalletData, selectedUser]);
|
||||
@ -138,7 +144,7 @@ const WalletContainer = ({
|
||||
})
|
||||
.then(() => getAccount(currentAccount.name))
|
||||
.then(account => {
|
||||
_getWalletData(account && account[0]);
|
||||
_getWalletData(selectedUser);
|
||||
if (isHasUnclaimedRewards) {
|
||||
dispatch(
|
||||
toastNotification(
|
||||
@ -150,7 +156,7 @@ const WalletContainer = ({
|
||||
}
|
||||
})
|
||||
.then(account => {
|
||||
_getWalletData(account && account[0]);
|
||||
_getWalletData(selectedUser);
|
||||
setIsClaiming(false);
|
||||
})
|
||||
.catch(() => {
|
||||
@ -171,7 +177,7 @@ const WalletContainer = ({
|
||||
|
||||
getAccount(selectedUser.name)
|
||||
.then(account => {
|
||||
_getWalletData(account && account[0]);
|
||||
_getWalletData(selectedUser);
|
||||
setRefreshing(false);
|
||||
})
|
||||
.catch(() => {
|
||||
@ -245,7 +251,8 @@ const WalletContainer = ({
|
||||
savingSteemDropdown: SAVING_STEEM_DROPDOWN,
|
||||
savingSbdDropdown: SAVING_SBD_DROPDOWN,
|
||||
steemPowerDropdown: STEEM_POWER_DROPDOWN,
|
||||
unclaimedBalance: unclaimedBalance.trim(),
|
||||
unclaimedBalance: unclaimedBalance && unclaimedBalance.trim(),
|
||||
estimatedAmount,
|
||||
})
|
||||
);
|
||||
};
|
||||
|
@ -22,7 +22,7 @@ const EstmView = ({ handleOnSelected, index, currentIndex }) => (
|
||||
dropdownOptions,
|
||||
}) => (
|
||||
<WalletHeader
|
||||
componentDidUpdate={() => handleOnSelected(userActivities, 'estm')}
|
||||
componentDidUpdate={() => handleOnSelected(userActivities, 'estm', fetchUserActivity)}
|
||||
index={index}
|
||||
showIconList
|
||||
claim={claim}
|
||||
@ -31,7 +31,9 @@ const EstmView = ({ handleOnSelected, index, currentIndex }) => (
|
||||
isLoading={isLoading}
|
||||
refreshing={refreshing}
|
||||
userActivities={userActivities}
|
||||
unclaimedBalance={get(userPoints, 'unclaimed_points', 0)}
|
||||
unclaimedBalance={
|
||||
get(userPoints, 'unclaimed_points') > 0 && get(userPoints, 'unclaimed_points')
|
||||
}
|
||||
userBalance={[
|
||||
{ balance: get(userPoints, 'points'), nameKey: 'estm', options: dropdownOptions },
|
||||
]}
|
||||
|
@ -19,12 +19,11 @@ const SpView = ({ handleOnSelected, index, currentIndex }) => (
|
||||
userActivities,
|
||||
spBalance,
|
||||
isLoading,
|
||||
steemSavingBalance,
|
||||
estimatedValue,
|
||||
steemPowerDropdown,
|
||||
savingSteemDropdown,
|
||||
unclaimedBalance,
|
||||
navigate,
|
||||
estimatedAmount,
|
||||
}) => (
|
||||
<WalletHeader
|
||||
componentDidUpdate={() => handleOnSelected(userActivities, 'steem_power')}
|
||||
@ -50,8 +49,8 @@ const SpView = ({ handleOnSelected, index, currentIndex }) => (
|
||||
value: <FormatedCurrency isApproximate value={estimatedValue} />,
|
||||
},
|
||||
{
|
||||
textKey: 'estimated_value',
|
||||
value: <FormatedCurrency isApproximate value={estimatedValue} />,
|
||||
textKey: 'estimated_amount',
|
||||
value: <FormatedCurrency isApproximate value={estimatedAmount} />,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
@ -18,8 +18,9 @@ const WalletScreen = () => {
|
||||
const [selectedUserActivities, setSelectedUserActivities] = useState(null);
|
||||
const [selectedType, setSelectedType] = useState('points');
|
||||
const [currentIndex, setCurrentIndex] = useState(0);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
|
||||
const _handleSwipeItemChange = (userActivities, type) => {
|
||||
const _handleSwipeItemChange = (userActivities, type, xx) => {
|
||||
setSelectedUserActivities(userActivities);
|
||||
setSelectedType(type);
|
||||
};
|
||||
@ -40,21 +41,29 @@ const WalletScreen = () => {
|
||||
<EstmView
|
||||
index={0}
|
||||
handleOnSelected={_handleSwipeItemChange}
|
||||
refreshing={refreshing}
|
||||
currentIndex={currentIndex}
|
||||
/>
|
||||
<SteemView
|
||||
index={1}
|
||||
handleOnSelected={_handleSwipeItemChange}
|
||||
refreshing={refreshing}
|
||||
currentIndex={currentIndex}
|
||||
/>
|
||||
<SpView
|
||||
index={2}
|
||||
refreshing={refreshing}
|
||||
handleOnSelected={_handleSwipeItemChange}
|
||||
currentIndex={currentIndex}
|
||||
/>
|
||||
</Swiper>
|
||||
|
||||
<Transaction type="wallet" transactions={selectedUserActivities} />
|
||||
<Transaction
|
||||
type="wallet"
|
||||
transactions={selectedUserActivities}
|
||||
refreshing={refreshing}
|
||||
setRefreshing={setRefreshing}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</LoggedInContainer>
|
||||
|
16
src/utils/vote.js
Normal file
16
src/utils/vote.js
Normal 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);
|
||||
};
|
Loading…
Reference in New Issue
Block a user