-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add simple loader to payment method list #11592
Changes from all commits
1f84770
af531b9
915c04d
e692e77
e5d35d1
60cb33e
e6bad98
c3649a1
7493545
749b39e
77fc08d
62c732d
5a0f2a4
b459d16
bf77918
d0e6659
7d5b8fa
1ec9ea3
a17ff69
44423a2
9eb2f09
ca94daa
e457b3d
f1ce0ba
a6eb9a3
6c19440
00e70dd
d94f29b
f87d9b7
c04fe5a
dd3e741
7c5e6b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import React from 'react'; | ||
import { | ||
View, InteractionManager, LayoutAnimation, | ||
ActivityIndicator, View, InteractionManager, LayoutAnimation, | ||
} from 'react-native'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import _ from 'underscore'; | ||
|
@@ -33,6 +33,7 @@ import * as PaymentUtils from '../../../../libs/PaymentUtils'; | |
import OfflineWithFeedback from '../../../../components/OfflineWithFeedback'; | ||
import ConfirmContent from '../../../../components/ConfirmContent'; | ||
import Button from '../../../../components/Button'; | ||
import themeColors from '../../../../styles/themes/default'; | ||
|
||
class BasePaymentsPage extends React.Component { | ||
constructor(props) { | ||
|
@@ -42,6 +43,7 @@ class BasePaymentsPage extends React.Component { | |
shouldShowAddPaymentMenu: false, | ||
shouldShowDefaultDeleteMenu: false, | ||
shouldShowPasswordPrompt: false, | ||
shouldShowLoadingSpinner: false, | ||
isSelectedPaymentMethodDefault: false, | ||
selectedPaymentMethod: {}, | ||
formattedSelectedPaymentMethod: { | ||
|
@@ -65,6 +67,8 @@ class BasePaymentsPage extends React.Component { | |
this.navigateToTransferBalancePage = this.navigateToTransferBalancePage.bind(this); | ||
this.setMenuPosition = this.setMenuPosition.bind(this); | ||
this.listHeaderComponent = this.listHeaderComponent.bind(this); | ||
|
||
this.debounceSetShouldShowLoadingSpinner = _.debounce(this.setShouldShowLoadingSpinner.bind(this), CONST.TIMING.SHOW_LOADING_SPINNER_DEBOUNCE_TIME); | ||
} | ||
|
||
componentDidMount() { | ||
|
@@ -76,12 +80,29 @@ class BasePaymentsPage extends React.Component { | |
this.setMenuPosition(); | ||
} | ||
|
||
// If the user was previously offline, skip debouncing showing the loader | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to skip debouncing? If we come back online we should fetch data again and show a loader if it takes a while. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue is that we also grey out the wallet amount when offline, so it does a strange thing where, the number will go from grey to white, then the loader will take over There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok that makes sense. I'm a bit confused still because if you are on the page and go online->offline->online (slow 3g) then you don't see the loader right away. I would say this is NAB at this point but would be nice to fix. Screen.Recording.2023-01-19.at.10.41.53.AM.mov |
||
if (prevProps.network.isOffline && !this.props.network.isOffline) { | ||
this.setShouldShowLoadingSpinner(); | ||
} else { | ||
this.debounceSetShouldShowLoadingSpinner(); | ||
} | ||
|
||
// previously online OR currently offline, skip fetch | ||
if (!prevProps.network.isOffline || this.props.network.isOffline) { | ||
return; | ||
} | ||
|
||
this.fetchData(); | ||
} | ||
|
||
setShouldShowLoadingSpinner() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is being called in a loop. Edit: Hmm my previous explanation was wrong, but if I put a console.log here I see it getting called repeatedly. |
||
// In order to prevent a loop, only update state of the spinner if there is a change | ||
const shouldShowLoadingSpinner = this.props.isLoadingPaymentMethods || false; | ||
if (shouldShowLoadingSpinner !== this.state.shouldShowLoadingSpinner) { | ||
this.setState({shouldShowLoadingSpinner: this.props.isLoadingPaymentMethods && !this.props.network.isOffline}); | ||
} | ||
} | ||
|
||
setMenuPosition() { | ||
if (!this.state.addPaymentMethodButton) { | ||
return; | ||
|
@@ -268,14 +289,18 @@ class BasePaymentsPage extends React.Component { | |
{Permissions.canUseWallet(this.props.betas) && ( | ||
<> | ||
<View style={[styles.mv5]}> | ||
<OfflineWithFeedback | ||
pendingAction={CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD} | ||
errors={this.props.walletTerms.errors} | ||
onClose={PaymentMethods.clearWalletTermsError} | ||
errorRowStyles={[styles.ml10, styles.mr2]} | ||
> | ||
<CurrentWalletBalance /> | ||
</OfflineWithFeedback> | ||
{this.state.shouldShowLoadingSpinner ? ( | ||
<ActivityIndicator color={themeColors.spinner} size="large" /> | ||
) : ( | ||
<OfflineWithFeedback | ||
pendingAction={CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD} | ||
errors={this.props.walletTerms.errors} | ||
onClose={PaymentMethods.clearWalletTermsError} | ||
errorRowStyles={[styles.ml10, styles.mr2]} | ||
> | ||
<CurrentWalletBalance /> | ||
</OfflineWithFeedback> | ||
)} | ||
</View> | ||
{this.props.userWallet.currentBalance > 0 && ( | ||
<KYCWall | ||
|
@@ -497,5 +522,8 @@ export default compose( | |
walletTerms: { | ||
key: ONYXKEYS.WALLET_TERMS, | ||
}, | ||
isLoadingPaymentMethods: { | ||
key: ONYXKEYS.IS_LOADING_PAYMENT_METHODS, | ||
}, | ||
}), | ||
)(BasePaymentsPage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB - was
isLoadingPayments
ever passed by anything? I don't see it anywhere else in the code...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it was.