created wallet refresh feature

This commit is contained in:
ue 2019-12-09 21:15:27 +03:00
parent f7dc850be1
commit ed7a238b1e
9 changed files with 37 additions and 19 deletions

View File

@ -29,6 +29,9 @@ const WalletHeaderView = ({
valueDescriptions, valueDescriptions,
showBuyButton, showBuyButton,
index, index,
fetchUserActivity,
reload,
refreshing,
}) => { }) => {
const intl = useIntl(); const intl = useIntl();
const dropdownRef = useRef(); const dropdownRef = useRef();
@ -39,6 +42,18 @@ const WalletHeaderView = ({
} }
}, [componentDidUpdate, currentIndex, index]); }, [componentDidUpdate, currentIndex, index]);
useEffect(() => {
if (reload && fetchUserActivity && index === currentIndex) {
fetchUserActivity();
}
}, [reload, currentIndex, index]);
useEffect(() => {
if (reload && !refreshing && index === currentIndex) {
componentDidUpdate();
}
}, [reload]);
const _getBalanceItem = (balance, options, key) => const _getBalanceItem = (balance, options, key) =>
balance !== undefined && ( balance !== undefined && (
<View style={styles.balanceWrapper}> <View style={styles.balanceWrapper}>

View File

@ -130,7 +130,7 @@ const PointsContainer = ({
}), }),
); );
const _fetchUserPointActivities = useCallback(async _username => { const _fetchUserPointActivities = useCallback(async (_username = username) => {
if (!_username) { if (!_username) {
return; return;
} }

View File

@ -189,6 +189,7 @@ const WalletContainer = ({
}; };
const _handleOnWalletRefresh = () => { const _handleOnWalletRefresh = () => {
if (refreshing) return;
setRefreshing(true); setRefreshing(true);
getAccount(selectedUser.name) getAccount(selectedUser.name)

View File

@ -7,7 +7,7 @@ import { PointsContainer } from '../../../containers';
import globalStyles from '../../../globalStyles'; import globalStyles from '../../../globalStyles';
const EstmView = ({ handleOnSelected, index, currentIndex }) => ( const EstmView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) => (
<View style={globalStyles.swipeItemWrapper}> <View style={globalStyles.swipeItemWrapper}>
<PointsContainer> <PointsContainer>
{({ {({
@ -24,6 +24,7 @@ const EstmView = ({ handleOnSelected, index, currentIndex }) => (
<WalletHeader <WalletHeader
componentDidUpdate={() => handleOnSelected(userActivities, isLoading, fetchUserActivity)} componentDidUpdate={() => handleOnSelected(userActivities, isLoading, fetchUserActivity)}
index={index} index={index}
reload={reload}
showIconList showIconList
claim={claim} claim={claim}
fetchUserActivity={fetchUserActivity} fetchUserActivity={fetchUserActivity}

View File

@ -6,7 +6,7 @@ import { SteemWalletContainer, AccountContainer } from '../../../containers';
import globalStyles from '../../../globalStyles'; import globalStyles from '../../../globalStyles';
const SbdView = ({ handleOnSelected, index, currentIndex }) => ( const SbdView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) => (
<View style={globalStyles.swipeItemWrapper}> <View style={globalStyles.swipeItemWrapper}>
<AccountContainer> <AccountContainer>
{({ currentAccount }) => ( {({ currentAccount }) => (
@ -29,6 +29,7 @@ const SbdView = ({ handleOnSelected, index, currentIndex }) => (
componentDidUpdate={() => handleOnSelected(transferHistory, isLoading)} componentDidUpdate={() => handleOnSelected(transferHistory, isLoading)}
index={index} index={index}
claim={claimRewardBalance} claim={claimRewardBalance}
reload={reload}
fetchUserActivity={handleOnWalletRefresh} fetchUserActivity={handleOnWalletRefresh}
isClaiming={isClaiming} isClaiming={isClaiming}
isLoading={isLoading} isLoading={isLoading}

View File

@ -6,7 +6,7 @@ import { SteemWalletContainer, AccountContainer } from '../../../containers';
import globalStyles from '../../../globalStyles'; import globalStyles from '../../../globalStyles';
const SpView = ({ handleOnSelected, index, currentIndex }) => ( const SpView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) => (
<View style={globalStyles.swipeItemWrapper}> <View style={globalStyles.swipeItemWrapper}>
<AccountContainer> <AccountContainer>
{({ currentAccount }) => ( {({ currentAccount }) => (
@ -29,6 +29,7 @@ const SpView = ({ handleOnSelected, index, currentIndex }) => (
componentDidUpdate={() => handleOnSelected(userActivities, isLoading)} componentDidUpdate={() => handleOnSelected(userActivities, isLoading)}
index={index} index={index}
claim={claimRewardBalance} claim={claimRewardBalance}
reload={reload}
fetchUserActivity={handleOnWalletRefresh} fetchUserActivity={handleOnWalletRefresh}
isClaiming={isClaiming} isClaiming={isClaiming}
isLoading={isLoading} isLoading={isLoading}

View File

@ -6,7 +6,7 @@ import { SteemWalletContainer, AccountContainer } from '../../../containers';
import globalStyles from '../../../globalStyles'; import globalStyles from '../../../globalStyles';
const SteemView = ({ handleOnSelected, index, currentIndex }) => ( const SteemView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) => (
<View style={globalStyles.swipeItemWrapper}> <View style={globalStyles.swipeItemWrapper}>
<AccountContainer> <AccountContainer>
{({ currentAccount }) => ( {({ currentAccount }) => (
@ -30,6 +30,7 @@ const SteemView = ({ handleOnSelected, index, currentIndex }) => (
index={index} index={index}
claim={claimRewardBalance} claim={claimRewardBalance}
fetchUserActivity={handleOnWalletRefresh} fetchUserActivity={handleOnWalletRefresh}
reload={reload}
isClaiming={isClaiming} isClaiming={isClaiming}
isLoading={isLoading} isLoading={isLoading}
refreshing={refreshing} refreshing={refreshing}

View File

@ -1,6 +1,7 @@
/* eslint-disable react/jsx-wrap-multilines */
import React, { Fragment, useState } from 'react'; import React, { Fragment, useState } from 'react';
import Swiper from 'react-native-swiper'; import Swiper from 'react-native-swiper';
import { SafeAreaView, Animated, ScrollView } from 'react-native'; import { SafeAreaView, Animated, ScrollView, RefreshControl } from 'react-native';
// Containers // Containers
import { LoggedInContainer } from '../../../containers'; import { LoggedInContainer } from '../../../containers';
@ -21,7 +22,7 @@ const HEADER_COLLAPSED_HEIGHT = 20;
const WalletScreen = () => { const WalletScreen = () => {
const [selectedUserActivities, setSelectedUserActivities] = useState(null); const [selectedUserActivities, setSelectedUserActivities] = useState(null);
const [isLoading, setIsLoading] = useState('points'); const [isLoading, setIsLoading] = useState(false);
const [currentIndex, setCurrentIndex] = useState(0); const [currentIndex, setCurrentIndex] = useState(0);
const [refreshing, setRefreshing] = useState(false); const [refreshing, setRefreshing] = useState(false);
const [scrollY] = useState(new Animated.Value(0)); const [scrollY] = useState(new Animated.Value(0));
@ -29,6 +30,7 @@ const WalletScreen = () => {
const _handleSwipeItemChange = (userActivities, _isLoading) => { const _handleSwipeItemChange = (userActivities, _isLoading) => {
setSelectedUserActivities(userActivities); setSelectedUserActivities(userActivities);
setIsLoading(_isLoading); setIsLoading(_isLoading);
setRefreshing(false);
}; };
const headerHeight = scrollY.interpolate({ const headerHeight = scrollY.interpolate({
@ -79,6 +81,13 @@ const WalletScreen = () => {
</Animated.View> </Animated.View>
<ScrollView <ScrollView
contentContainerStyle={styles.scrollContainer} contentContainerStyle={styles.scrollContainer}
refreshControl={
<RefreshControl
refreshing={refreshing}
tintColor={!true ? '#357ce6' : '#96c0ff'}
onRefresh={() => setRefreshing(true)}
/>
}
onScroll={Animated.event([ onScroll={Animated.event([
{ {
nativeEvent: { nativeEvent: {
@ -93,7 +102,7 @@ const WalletScreen = () => {
<Transaction <Transaction
type="wallet" type="wallet"
transactions={selectedUserActivities} transactions={selectedUserActivities}
refreshing={refreshing} refreshing={false}
setRefreshing={setRefreshing} setRefreshing={setRefreshing}
isLoading={isLoading} isLoading={isLoading}
/> />

View File

@ -1,21 +1,10 @@
import EStyleSheet from 'react-native-extended-stylesheet'; import EStyleSheet from 'react-native-extended-stylesheet';
import { Dimensions } from 'react-native';
const HEADER_EXPANDED_HEIGHT = 260;
const { width: SCREEN_WIDTH } = Dimensions.get('screen');
export default EStyleSheet.create({ export default EStyleSheet.create({
scrollContainer: { scrollContainer: {
padding: 0, padding: 0,
paddingTop: HEADER_EXPANDED_HEIGHT,
}, },
header: { header: {
position: 'absolute',
width: SCREEN_WIDTH,
backgroundColor: '$primaryBackgroundColor', backgroundColor: '$primaryBackgroundColor',
top: 0,
left: 0,
zIndex: 9999,
}, },
}); });