From ed7a238b1e15523395938fc533541560f7eb4023 Mon Sep 17 00:00:00 2001 From: ue Date: Mon, 9 Dec 2019 21:15:27 +0300 Subject: [PATCH] created wallet refresh feature --- .../walletHeader/view/walletHeaderView.js | 15 +++++++++++++++ src/containers/pointsContainer.js | 2 +- src/containers/steemWalletContainer.js | 1 + src/screens/wallet/screen/estmView.js | 3 ++- src/screens/wallet/screen/sbdView.js | 3 ++- src/screens/wallet/screen/spView.js | 3 ++- src/screens/wallet/screen/steemView.js | 3 ++- src/screens/wallet/screen/walletScreen.js | 15 ++++++++++++--- src/screens/wallet/screen/walletScreenStyles.js | 11 ----------- 9 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/components/walletHeader/view/walletHeaderView.js b/src/components/walletHeader/view/walletHeaderView.js index 42a51632c..562897543 100644 --- a/src/components/walletHeader/view/walletHeaderView.js +++ b/src/components/walletHeader/view/walletHeaderView.js @@ -29,6 +29,9 @@ const WalletHeaderView = ({ valueDescriptions, showBuyButton, index, + fetchUserActivity, + reload, + refreshing, }) => { const intl = useIntl(); const dropdownRef = useRef(); @@ -39,6 +42,18 @@ const WalletHeaderView = ({ } }, [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) => balance !== undefined && ( diff --git a/src/containers/pointsContainer.js b/src/containers/pointsContainer.js index 38ea3747b..67130c4c6 100644 --- a/src/containers/pointsContainer.js +++ b/src/containers/pointsContainer.js @@ -130,7 +130,7 @@ const PointsContainer = ({ }), ); - const _fetchUserPointActivities = useCallback(async _username => { + const _fetchUserPointActivities = useCallback(async (_username = username) => { if (!_username) { return; } diff --git a/src/containers/steemWalletContainer.js b/src/containers/steemWalletContainer.js index 194a1641d..35276c260 100644 --- a/src/containers/steemWalletContainer.js +++ b/src/containers/steemWalletContainer.js @@ -189,6 +189,7 @@ const WalletContainer = ({ }; const _handleOnWalletRefresh = () => { + if (refreshing) return; setRefreshing(true); getAccount(selectedUser.name) diff --git a/src/screens/wallet/screen/estmView.js b/src/screens/wallet/screen/estmView.js index 51e5713b9..8af179091 100644 --- a/src/screens/wallet/screen/estmView.js +++ b/src/screens/wallet/screen/estmView.js @@ -7,7 +7,7 @@ import { PointsContainer } from '../../../containers'; import globalStyles from '../../../globalStyles'; -const EstmView = ({ handleOnSelected, index, currentIndex }) => ( +const EstmView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) => ( {({ @@ -24,6 +24,7 @@ const EstmView = ({ handleOnSelected, index, currentIndex }) => ( handleOnSelected(userActivities, isLoading, fetchUserActivity)} index={index} + reload={reload} showIconList claim={claim} fetchUserActivity={fetchUserActivity} diff --git a/src/screens/wallet/screen/sbdView.js b/src/screens/wallet/screen/sbdView.js index 6d9611b11..ddce55e4d 100644 --- a/src/screens/wallet/screen/sbdView.js +++ b/src/screens/wallet/screen/sbdView.js @@ -6,7 +6,7 @@ import { SteemWalletContainer, AccountContainer } from '../../../containers'; import globalStyles from '../../../globalStyles'; -const SbdView = ({ handleOnSelected, index, currentIndex }) => ( +const SbdView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) => ( {({ currentAccount }) => ( @@ -29,6 +29,7 @@ const SbdView = ({ handleOnSelected, index, currentIndex }) => ( componentDidUpdate={() => handleOnSelected(transferHistory, isLoading)} index={index} claim={claimRewardBalance} + reload={reload} fetchUserActivity={handleOnWalletRefresh} isClaiming={isClaiming} isLoading={isLoading} diff --git a/src/screens/wallet/screen/spView.js b/src/screens/wallet/screen/spView.js index 08763a8a7..fb664ad6a 100644 --- a/src/screens/wallet/screen/spView.js +++ b/src/screens/wallet/screen/spView.js @@ -6,7 +6,7 @@ import { SteemWalletContainer, AccountContainer } from '../../../containers'; import globalStyles from '../../../globalStyles'; -const SpView = ({ handleOnSelected, index, currentIndex }) => ( +const SpView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) => ( {({ currentAccount }) => ( @@ -29,6 +29,7 @@ const SpView = ({ handleOnSelected, index, currentIndex }) => ( componentDidUpdate={() => handleOnSelected(userActivities, isLoading)} index={index} claim={claimRewardBalance} + reload={reload} fetchUserActivity={handleOnWalletRefresh} isClaiming={isClaiming} isLoading={isLoading} diff --git a/src/screens/wallet/screen/steemView.js b/src/screens/wallet/screen/steemView.js index 90876568e..bf0fcc31b 100644 --- a/src/screens/wallet/screen/steemView.js +++ b/src/screens/wallet/screen/steemView.js @@ -6,7 +6,7 @@ import { SteemWalletContainer, AccountContainer } from '../../../containers'; import globalStyles from '../../../globalStyles'; -const SteemView = ({ handleOnSelected, index, currentIndex }) => ( +const SteemView = ({ handleOnSelected, index, currentIndex, refreshing: reload }) => ( {({ currentAccount }) => ( @@ -30,6 +30,7 @@ const SteemView = ({ handleOnSelected, index, currentIndex }) => ( index={index} claim={claimRewardBalance} fetchUserActivity={handleOnWalletRefresh} + reload={reload} isClaiming={isClaiming} isLoading={isLoading} refreshing={refreshing} diff --git a/src/screens/wallet/screen/walletScreen.js b/src/screens/wallet/screen/walletScreen.js index 3927c1797..4d906b97f 100644 --- a/src/screens/wallet/screen/walletScreen.js +++ b/src/screens/wallet/screen/walletScreen.js @@ -1,6 +1,7 @@ +/* eslint-disable react/jsx-wrap-multilines */ import React, { Fragment, useState } from 'react'; import Swiper from 'react-native-swiper'; -import { SafeAreaView, Animated, ScrollView } from 'react-native'; +import { SafeAreaView, Animated, ScrollView, RefreshControl } from 'react-native'; // Containers import { LoggedInContainer } from '../../../containers'; @@ -21,7 +22,7 @@ const HEADER_COLLAPSED_HEIGHT = 20; const WalletScreen = () => { const [selectedUserActivities, setSelectedUserActivities] = useState(null); - const [isLoading, setIsLoading] = useState('points'); + const [isLoading, setIsLoading] = useState(false); const [currentIndex, setCurrentIndex] = useState(0); const [refreshing, setRefreshing] = useState(false); const [scrollY] = useState(new Animated.Value(0)); @@ -29,6 +30,7 @@ const WalletScreen = () => { const _handleSwipeItemChange = (userActivities, _isLoading) => { setSelectedUserActivities(userActivities); setIsLoading(_isLoading); + setRefreshing(false); }; const headerHeight = scrollY.interpolate({ @@ -79,6 +81,13 @@ const WalletScreen = () => { setRefreshing(true)} + /> + } onScroll={Animated.event([ { nativeEvent: { @@ -93,7 +102,7 @@ const WalletScreen = () => { diff --git a/src/screens/wallet/screen/walletScreenStyles.js b/src/screens/wallet/screen/walletScreenStyles.js index dcd51921b..0b96bac35 100644 --- a/src/screens/wallet/screen/walletScreenStyles.js +++ b/src/screens/wallet/screen/walletScreenStyles.js @@ -1,21 +1,10 @@ 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({ scrollContainer: { padding: 0, - paddingTop: HEADER_EXPANDED_HEIGHT, }, header: { - position: 'absolute', - width: SCREEN_WIDTH, backgroundColor: '$primaryBackgroundColor', - top: 0, - left: 0, - zIndex: 9999, }, });