-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add ChooseTransferAccountPage and allow selecting accounts for wallet transfer #7200
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
Changes from all commits
97c8e99
8660d64
05f8a7c
ff85915
967e4ba
00f4106
93fdbb6
12c62e0
e3f1b4f
b480379
ec1782c
cc5e4a5
c43bd3a
0136230
7751d73
0bb65ca
cd1ddba
0dcf5f8
8eacf33
39b6327
41feaa9
0043cec
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,27 +1,100 @@ | ||||
| import React from 'react'; | ||||
| import {withOnyx} from 'react-native-onyx'; | ||||
| import {View} from 'react-native'; | ||||
| import HeaderWithCloseButton from '../../../components/HeaderWithCloseButton'; | ||||
| import ScreenWrapper from '../../../components/ScreenWrapper'; | ||||
| import Navigation from '../../../libs/Navigation/Navigation'; | ||||
| import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize'; | ||||
| import KeyboardAvoidingView from '../../../components/KeyboardAvoidingView'; | ||||
| import CONST from '../../../CONST'; | ||||
| import PaymentMethodList from './PaymentMethodList'; | ||||
| import * as PaymentMethods from '../../../libs/actions/PaymentMethods'; | ||||
| import ROUTES from '../../../ROUTES'; | ||||
| import MenuItem from '../../../components/MenuItem'; | ||||
| import * as Expensicons from '../../../components/Icon/Expensicons'; | ||||
| import compose from '../../../libs/compose'; | ||||
| import ONYXKEYS from '../../../ONYXKEYS'; | ||||
| import walletTransferPropTypes from './walletTransferPropTypes'; | ||||
| import styles from '../../../styles/styles'; | ||||
|
|
||||
| const propTypes = { | ||||
| /** Wallet transfer propTypes */ | ||||
| walletTransfer: walletTransferPropTypes, | ||||
|
|
||||
| ...withLocalizePropTypes, | ||||
| }; | ||||
|
|
||||
| const ChooseTransferAccountPage = props => ( | ||||
| <ScreenWrapper> | ||||
| <KeyboardAvoidingView> | ||||
| <HeaderWithCloseButton | ||||
| title={props.translate('chooseTransferAccountPage.chooseAccount')} | ||||
| shouldShowBackButton | ||||
| onBackButtonPress={() => Navigation.goBack()} | ||||
| onCloseButtonPress={() => Navigation.dismissModal()} | ||||
| /> | ||||
| </KeyboardAvoidingView> | ||||
| </ScreenWrapper> | ||||
| ); | ||||
| const defaultProps = { | ||||
| walletTransfer: {}, | ||||
| }; | ||||
|
|
||||
| const ChooseTransferAccountPage = (props) => { | ||||
| /** | ||||
| * Go back to transfer balance screen with the selected bank account set | ||||
| * @param {Object} event Click event object | ||||
| * @param {String} accountType of the selected account type | ||||
| * @param {Object} account of the selected account data | ||||
| */ | ||||
| const selectAccountAndNavigateBack = (event, accountType, account) => { | ||||
| PaymentMethods.saveWalletTransferAccountTypeAndID( | ||||
| accountType, | ||||
| accountType === CONST.PAYMENT_METHODS.BANK_ACCOUNT | ||||
| ? account.bankAccountID | ||||
| : account.fundID, | ||||
| ); | ||||
| Navigation.navigate(ROUTES.SETTINGS_PAYMENTS_TRANSFER_BALANCE); | ||||
|
Contributor
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. If we are going back can we just do
Contributor
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. Whatever we do maybe it should be consistent because we are using
|
||||
| }; | ||||
|
Contributor
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. NAB, this method isn't using
Member
Author
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. Yeah, I agree but I didn't see any example of such a functional component. Where should I move this. Outside the component in the same file?
Contributor
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. Yeah outside the component in the same file would work. Also maybe a good sign that it should be an action instead of a component method. |
||||
|
|
||||
| /** | ||||
| * @param {String} paymentType | ||||
| */ | ||||
| const navigateToAddPaymentMethodPage = () => { | ||||
| if (props.walletTransfer.filterPaymentMethodType === CONST.PAYMENT_METHODS.DEBIT_CARD) { | ||||
| Navigation.navigate(ROUTES.SETTINGS_ADD_DEBIT_CARD); | ||||
| return; | ||||
| } | ||||
| Navigation.navigate(ROUTES.SETTINGS_ADD_BANK_ACCOUNT); | ||||
| }; | ||||
|
|
||||
| return ( | ||||
| <ScreenWrapper> | ||||
| <KeyboardAvoidingView> | ||||
| <HeaderWithCloseButton | ||||
| title={props.translate('chooseTransferAccountPage.chooseAccount')} | ||||
| shouldShowBackButton | ||||
| onBackButtonPress={() => Navigation.goBack()} | ||||
| onCloseButtonPress={() => Navigation.dismissModal()} | ||||
| /> | ||||
| <View style={[styles.mt6, styles.flexShrink1, styles.flexBasisAuto]}> | ||||
| <PaymentMethodList | ||||
| onPress={selectAccountAndNavigateBack} | ||||
| shouldShowSelectedState | ||||
| filterType={props.walletTransfer.filterPaymentMethodType} | ||||
| selectedMethodID={props.walletTransfer.selectedAccountID} | ||||
| shouldShowAddPaymentMethodButton={false} | ||||
|
Contributor
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. NAB, but it would be better to eventually find the case where we DO want to show an add payment method button and show one next to the list instead of inside of it. Now we have this list that must specify "no thanks, I don't need this". And in this case we just shows a very similar button below which could be confusing. Maybe a good follow up issue to create and have someone fix up.
Member
Author
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. Yeah, I was thinking th same but then it would unnecessary refactor for this PR so I left it as it is. |
||||
| /> | ||||
| </View> | ||||
| <MenuItem | ||||
| onPress={navigateToAddPaymentMethodPage} | ||||
| title={props.walletTransfer.filterPaymentMethodType === CONST.PAYMENT_METHODS.BANK_ACCOUNT | ||||
| ? props.translate('paymentMethodList.addNewBankAccount') | ||||
| : props.translate('paymentMethodList.addNewDebitCard')} | ||||
| icon={Expensicons.Plus} | ||||
| /> | ||||
| </KeyboardAvoidingView> | ||||
| </ScreenWrapper> | ||||
| ); | ||||
| }; | ||||
|
|
||||
| ChooseTransferAccountPage.propTypes = propTypes; | ||||
| ChooseTransferAccountPage.defaultProps = defaultProps; | ||||
| ChooseTransferAccountPage.displayName = 'ChooseTransferAccountPage'; | ||||
|
|
||||
| export default withLocalize(ChooseTransferAccountPage); | ||||
| export default compose( | ||||
| withLocalize, | ||||
| withOnyx({ | ||||
| walletTransfer: { | ||||
| key: ONYXKEYS.WALLET_TRANSFER, | ||||
| }, | ||||
| }), | ||||
| )(ChooseTransferAccountPage); | ||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,6 @@ import React from 'react'; | |
| import {View, ScrollView} from 'react-native'; | ||
| import PropTypes from 'prop-types'; | ||
| import {withOnyx} from 'react-native-onyx'; | ||
| import lodashGet from 'lodash/get'; | ||
| import ONYXKEYS from '../../../ONYXKEYS'; | ||
| import HeaderWithCloseButton from '../../../components/HeaderWithCloseButton'; | ||
| import ScreenWrapper from '../../../components/ScreenWrapper'; | ||
|
|
@@ -24,6 +23,7 @@ import walletTransferPropTypes from './walletTransferPropTypes'; | |
| import * as PaymentMethods from '../../../libs/actions/PaymentMethods'; | ||
| import * as PaymentUtils from '../../../libs/PaymentUtils'; | ||
| import userWalletPropTypes from '../../EnablePayments/userWalletPropTypes'; | ||
| import ROUTES from '../../../ROUTES'; | ||
|
|
||
| const propTypes = { | ||
| /** User's wallet information */ | ||
|
|
@@ -96,35 +96,62 @@ class TransferBalancePage extends React.Component { | |
| }, | ||
| ]; | ||
|
|
||
| this.saveTransferAmountAndBalance = this.saveTransferAmountAndBalance.bind(this); | ||
| this.getSelectedPaymentMethodAccount = this.getSelectedPaymentMethodAccount.bind(this); | ||
|
|
||
| PaymentMethods.resetWalletTransferData(); | ||
| const selectedAccount = this.getSelectedPaymentMethodAccount(); | ||
| PaymentMethods.saveWalletTransferAccountAndResetData(selectedAccount ? selectedAccount.id : ''); | ||
|
|
||
| // Select the default payment account when page is opened, | ||
| // so that user can see that preselected on choose transfer account page | ||
| if (!selectedAccount || !selectedAccount.isDefault) { | ||
| return; | ||
| } | ||
|
|
||
| PaymentMethods.saveWalletTransferAccountTypeAndID( | ||
| selectedAccount.accountType, | ||
| selectedAccount.methodID, | ||
| ); | ||
|
Contributor
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. NAB, the more I look at this the more wrong it seems. We are saving data that can be derived from looking at other data and just sort of seems like stuff this component shouldn't be responsible for. Maybe it says "when I am first loaded then set the most likely default payment method", but I don't think it would be this component's responsibility to filter everything.
Member
Author
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. Yeah that is true. Let me see if I can clean this up bit. |
||
| } | ||
|
|
||
| /** | ||
| * Get the selected/default payment method account for wallet transfer | ||
| * @returns {Object|undefined} | ||
| */ | ||
| getSelectedPaymentMethodAccount() { | ||
| const paymentMethods = PaymentUtils.formatPaymentMethods(this.props.bankAccountList, this.props.cardList, '', this.props.userWallet); | ||
| const accountID = this.props.walletTransfer.selectedAccountID || lodashGet(this.props, 'userWallet.walletLinkedAccountID', ''); | ||
| return _.find(paymentMethods, method => method.methodID === accountID); | ||
| const paymentMethods = PaymentUtils.formatPaymentMethods( | ||
| this.props.bankAccountList, | ||
| this.props.cardList, | ||
| '', | ||
| this.props.userWallet, | ||
| ); | ||
|
|
||
| const defaultAccount = _.find(paymentMethods, method => method.isDefault); | ||
| const selectedAccount = _.find( | ||
| paymentMethods, | ||
| method => method.accountType === this.props.walletTransfer.selectedAccountType | ||
| && method.methodID === this.props.walletTransfer.selectedAccountID, | ||
| ); | ||
| return selectedAccount || defaultAccount; | ||
| } | ||
|
|
||
| /** | ||
| * @param {Number} transferAmount | ||
| * @param {Object} selectedAccount | ||
| */ | ||
| saveTransferAmountAndBalance(transferAmount, selectedAccount) { | ||
| saveTransferAmountAndStartTransfer(transferAmount, selectedAccount) { | ||
| PaymentMethods.saveWalletTransferAmount(transferAmount); | ||
| PaymentMethods.transferWalletBalance(selectedAccount); | ||
|
marcaaron marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** | ||
| * @param {String} filterPaymentMethodType | ||
| */ | ||
| navigateToChooseTransferAccount(filterPaymentMethodType) { | ||
| PaymentMethods.saveWalletTransferMethodType(filterPaymentMethodType); | ||
| Navigation.navigate(ROUTES.SETTINGS_PAYMENTS_CHOOSE_TRANSFER_ACCOUNT); | ||
| } | ||
|
|
||
| render() { | ||
| const selectedAccount = this.getSelectedPaymentMethodAccount(); | ||
|
Contributor
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. NAB, feels like we are unnecessarily filtering through all the payment methods to derive this and giving a lot of responsibility to this component.
Contributor
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. e.g. if we are initializing the payment method type in
Member
Author
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. When we come back from Choose Transfer Account screen. This helps in picking the selected method. Either we should do that in componentDidUpdate or here.
Contributor
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. Yeah I'm not sure that's easy to see or why that would be the case. It maybe works, but the whole interaction between the different sets of data and why we are filtering them on every render is confusing. |
||
| const selectedPaymentType = selectedAccount && selectedAccount.type === CONST.PAYMENT_METHODS.BANK_ACCOUNT | ||
| const selectedPaymentType = selectedAccount && selectedAccount.accountType === CONST.PAYMENT_METHODS.BANK_ACCOUNT | ||
| ? CONST.WALLET.TRANSFER_METHOD_TYPE.ACH | ||
| : CONST.WALLET.TRANSFER_METHOD_TYPE.INSTANT; | ||
|
|
||
|
|
@@ -162,6 +189,7 @@ class TransferBalancePage extends React.Component { | |
| ...(selectedPaymentType === paymentType.key | ||
| && styles.transferBalanceSelectedPayment), | ||
| }} | ||
| onPress={() => this.navigateToChooseTransferAccount(paymentType.type)} | ||
| /> | ||
| ))} | ||
| <Text | ||
|
|
@@ -182,6 +210,7 @@ class TransferBalancePage extends React.Component { | |
| ...styles.mrn5, | ||
| ...styles.ph0, | ||
| }} | ||
| onPress={() => this.navigateToChooseTransferAccount(selectedAccount.accountType)} | ||
| /> | ||
| )} | ||
| <Text | ||
|
|
@@ -210,7 +239,7 @@ class TransferBalancePage extends React.Component { | |
| pressOnEnter | ||
| isLoading={this.props.walletTransfer.loading} | ||
| isDisabled={isButtonDisabled} | ||
| onPress={() => this.saveTransferAmountAndBalance(transferAmount, selectedAccount)} | ||
| onPress={() => this.saveTransferAmountAndStartTransfer(transferAmount, selectedAccount)} | ||
| text={this.props.translate( | ||
| 'transferAmountPage.transfer', | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.