From 0439b299d4b96df9e0abcc964667ba02a221ab36 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 17 Sep 2024 19:04:29 +0530 Subject: [PATCH 01/11] refactor wallet bank transfer page to use SelectionList --- .../Wallet/ChooseTransferAccountPage.tsx | 59 +++++++++++++++---- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx index 71104f136e30..b001a9fb0866 100644 --- a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx +++ b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx @@ -1,14 +1,20 @@ -import React from 'react'; +import React, {useMemo} from 'react'; import type {GestureResponderEvent} from 'react-native'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx, withOnyx} from 'react-native-onyx'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; +import Icon from '@components/Icon'; +import getBankIcon from '@components/Icon/BankIcons'; import * as Expensicons from '@components/Icon/Expensicons'; import MenuItem from '@components/MenuItem'; import ScreenWrapper from '@components/ScreenWrapper'; +import SelectionList from '@components/SelectionList'; +import RadioListItem from '@components/SelectionList/RadioListItem'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; +import {getLastFourDigits} from '@libs/BankAccountUtils'; +import * as CardUtils from '@libs/CardUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as BankAccounts from '@userActions/BankAccounts'; import * as PaymentMethods from '@userActions/PaymentMethods'; @@ -16,6 +22,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {AccountData, WalletTransfer} from '@src/types/onyx'; +import type {BankName} from '@src/types/onyx/Bank'; import PaymentMethodList from './PaymentMethodList'; type ChooseTransferAccountPageOnyxProps = { @@ -50,6 +57,36 @@ function ChooseTransferAccountPage({walletTransfer = {}}: ChooseTransferAccountP BankAccounts.openPersonalBankAccountSetupView(); }; + const [bankAccountsList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); + + const data = useMemo(() => { + const options = Object.values(bankAccountsList || {}).map((bankAccount) => { + const bankName = (bankAccount.accountData?.additionalData?.bankName ?? '') as BankName; + const bankAccountNumber = bankAccount.accountData?.accountNumber ?? ''; + const bankAccountID = bankAccount.accountData?.bankAccountID ?? bankAccount.methodID; + const {icon, iconSize, iconStyles} = getBankIcon({bankName, styles}); + return { + value: bankAccountID, + text: bankAccount.title, + leftElement: icon && ( + + + + ), + alternateText: `${translate('workspace.expensifyCard.accountEndingIn')} ${getLastFourDigits(bankAccountNumber)}`, + keyForList: bankAccountID?.toString(), + isSelected: bankAccountID?.toString() === walletTransfer?.selectedAccountID, + bankAccount: bankAccount, + }; + }); + return options; + }, [bankAccountsList, walletTransfer?.selectedAccountID, styles, translate]); + return ( Navigation.goBack(ROUTES.SETTINGS_WALLET_TRANSFER_BALANCE)} /> - { + const accountType = value?.bankAccount?.accountType; + const accountData = value?.bankAccount?.accountData; + selectAccountAndNavigateBack(undefined, accountType, accountData); + }} + shouldSingleExecuteRowSelect + initiallyFocusedOptionKey={walletTransfer?.selectedAccountID?.toString()} /> Date: Tue, 17 Sep 2024 19:09:20 +0530 Subject: [PATCH 02/11] fix lint --- src/pages/settings/Wallet/ChooseTransferAccountPage.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx index b001a9fb0866..ca8084e956ea 100644 --- a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx +++ b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx @@ -14,7 +14,6 @@ import RadioListItem from '@components/SelectionList/RadioListItem'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import {getLastFourDigits} from '@libs/BankAccountUtils'; -import * as CardUtils from '@libs/CardUtils'; import Navigation from '@libs/Navigation/Navigation'; import * as BankAccounts from '@userActions/BankAccounts'; import * as PaymentMethods from '@userActions/PaymentMethods'; @@ -23,7 +22,6 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {AccountData, WalletTransfer} from '@src/types/onyx'; import type {BankName} from '@src/types/onyx/Bank'; -import PaymentMethodList from './PaymentMethodList'; type ChooseTransferAccountPageOnyxProps = { /** Wallet transfer propTypes */ @@ -60,7 +58,7 @@ function ChooseTransferAccountPage({walletTransfer = {}}: ChooseTransferAccountP const [bankAccountsList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); const data = useMemo(() => { - const options = Object.values(bankAccountsList || {}).map((bankAccount) => { + const options = Object.values(bankAccountsList ?? {}).map((bankAccount) => { const bankName = (bankAccount.accountData?.additionalData?.bankName ?? '') as BankName; const bankAccountNumber = bankAccount.accountData?.accountNumber ?? ''; const bankAccountID = bankAccount.accountData?.bankAccountID ?? bankAccount.methodID; @@ -81,7 +79,7 @@ function ChooseTransferAccountPage({walletTransfer = {}}: ChooseTransferAccountP alternateText: `${translate('workspace.expensifyCard.accountEndingIn')} ${getLastFourDigits(bankAccountNumber)}`, keyForList: bankAccountID?.toString(), isSelected: bankAccountID?.toString() === walletTransfer?.selectedAccountID, - bankAccount: bankAccount, + bankAccount, }; }); return options; From bcc3c953c21b1f2ac4cbac20b4af2b3c9adfd842 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 17 Sep 2024 19:17:26 +0530 Subject: [PATCH 03/11] use useOnyx --- .../Wallet/ChooseTransferAccountPage.tsx | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx index ca8084e956ea..5feeaaa8e71d 100644 --- a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx +++ b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx @@ -1,8 +1,7 @@ import React, {useMemo} from 'react'; import type {GestureResponderEvent} from 'react-native'; import {View} from 'react-native'; -import type {OnyxEntry} from 'react-native-onyx'; -import {useOnyx, withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import Icon from '@components/Icon'; import getBankIcon from '@components/Icon/BankIcons'; @@ -20,17 +19,11 @@ import * as PaymentMethods from '@userActions/PaymentMethods'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {AccountData, WalletTransfer} from '@src/types/onyx'; +import type {AccountData} from '@src/types/onyx'; import type {BankName} from '@src/types/onyx/Bank'; -type ChooseTransferAccountPageOnyxProps = { - /** Wallet transfer propTypes */ - walletTransfer: OnyxEntry; -}; - -type ChooseTransferAccountPageProps = ChooseTransferAccountPageOnyxProps; - -function ChooseTransferAccountPage({walletTransfer = {}}: ChooseTransferAccountPageProps) { +function ChooseTransferAccountPage() { + const [walletTransfer] = useOnyx(ONYXKEYS.WALLET_TRANSFER); const styles = useThemeStyles(); const {translate} = useLocalize(); /** @@ -119,8 +112,4 @@ function ChooseTransferAccountPage({walletTransfer = {}}: ChooseTransferAccountP ChooseTransferAccountPage.displayName = 'ChooseTransferAccountPage'; -export default withOnyx({ - walletTransfer: { - key: ONYXKEYS.WALLET_TRANSFER, - }, -})(ChooseTransferAccountPage); +export default ChooseTransferAccountPage; From 7e1ad70c9dd6cbf4192bc65a004e319e29c93794 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 17 Sep 2024 19:31:23 +0530 Subject: [PATCH 04/11] fix initial focus --- src/pages/settings/Wallet/ChooseTransferAccountPage.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx index 5feeaaa8e71d..062b30663448 100644 --- a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx +++ b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx @@ -94,6 +94,7 @@ function ChooseTransferAccountPage() { selectAccountAndNavigateBack(undefined, accountType, accountData); }} shouldSingleExecuteRowSelect + shouldUpdateFocusedIndex initiallyFocusedOptionKey={walletTransfer?.selectedAccountID?.toString()} /> From d6a368aee7c315ced2c7b234f5f0ebfe49871ad8 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 17 Sep 2024 21:10:02 +0530 Subject: [PATCH 05/11] fix useOnyx --- .../settings/Wallet/ChooseTransferAccountPage.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx index 062b30663448..a0fadb4be14f 100644 --- a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx +++ b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx @@ -2,6 +2,7 @@ import React, {useMemo} from 'react'; import type {GestureResponderEvent} from 'react-native'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; +import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import Icon from '@components/Icon'; import getBankIcon from '@components/Icon/BankIcons'; @@ -21,9 +22,11 @@ import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {AccountData} from '@src/types/onyx'; import type {BankName} from '@src/types/onyx/Bank'; +import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; function ChooseTransferAccountPage() { - const [walletTransfer] = useOnyx(ONYXKEYS.WALLET_TRANSFER); + const [walletTransfer, walletTransferResult] = useOnyx(ONYXKEYS.WALLET_TRANSFER); + const styles = useThemeStyles(); const {translate} = useLocalize(); /** @@ -49,7 +52,7 @@ function ChooseTransferAccountPage() { }; const [bankAccountsList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); - + const selectedAccountID = walletTransfer?.selectedAccountID; const data = useMemo(() => { const options = Object.values(bankAccountsList ?? {}).map((bankAccount) => { const bankName = (bankAccount.accountData?.additionalData?.bankName ?? '') as BankName; @@ -76,7 +79,11 @@ function ChooseTransferAccountPage() { }; }); return options; - }, [bankAccountsList, walletTransfer?.selectedAccountID, styles, translate]); + }, [bankAccountsList, selectedAccountID, styles, translate]); + + if (isLoadingOnyxValue(walletTransferResult)) { + return ; + } return ( From a7ce9d9cba7fa7a501adb4c547fafd2f422be26e Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 17 Sep 2024 21:20:47 +0530 Subject: [PATCH 06/11] hopefully fixed the compiler --- src/pages/settings/Wallet/ChooseTransferAccountPage.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx index a0fadb4be14f..2e0ce6271814 100644 --- a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx +++ b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx @@ -52,7 +52,6 @@ function ChooseTransferAccountPage() { }; const [bankAccountsList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); - const selectedAccountID = walletTransfer?.selectedAccountID; const data = useMemo(() => { const options = Object.values(bankAccountsList ?? {}).map((bankAccount) => { const bankName = (bankAccount.accountData?.additionalData?.bankName ?? '') as BankName; @@ -62,7 +61,7 @@ function ChooseTransferAccountPage() { return { value: bankAccountID, text: bankAccount.title, - leftElement: icon && ( + leftElement: icon ? ( - ), + ) : null, alternateText: `${translate('workspace.expensifyCard.accountEndingIn')} ${getLastFourDigits(bankAccountNumber)}`, keyForList: bankAccountID?.toString(), isSelected: bankAccountID?.toString() === walletTransfer?.selectedAccountID, @@ -79,7 +78,7 @@ function ChooseTransferAccountPage() { }; }); return options; - }, [bankAccountsList, selectedAccountID, styles, translate]); + }, [bankAccountsList, walletTransfer?.selectedAccountID, styles, translate]); if (isLoadingOnyxValue(walletTransferResult)) { return ; From a570c6d87d3dbfa1fe0ad63c582bc29bd91eeeb0 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 17 Sep 2024 23:22:52 +0530 Subject: [PATCH 07/11] try fix --- src/pages/settings/Wallet/ChooseTransferAccountPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx index 2e0ce6271814..6b0ca0d8645e 100644 --- a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx +++ b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx @@ -92,7 +92,7 @@ function ChooseTransferAccountPage() { /> { const accountType = value?.bankAccount?.accountType; From ec32225dc7d89bfe8958356ead4be1244e5cc7db Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 17 Sep 2024 23:49:09 +0530 Subject: [PATCH 08/11] fix compiler error --- src/pages/settings/Wallet/ChooseTransferAccountPage.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx index 6b0ca0d8645e..bbf1a7ab31b0 100644 --- a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx +++ b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx @@ -52,6 +52,7 @@ function ChooseTransferAccountPage() { }; const [bankAccountsList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST); + const selectedAccountID = walletTransfer?.selectedAccountID; const data = useMemo(() => { const options = Object.values(bankAccountsList ?? {}).map((bankAccount) => { const bankName = (bankAccount.accountData?.additionalData?.bankName ?? '') as BankName; @@ -73,12 +74,12 @@ function ChooseTransferAccountPage() { ) : null, alternateText: `${translate('workspace.expensifyCard.accountEndingIn')} ${getLastFourDigits(bankAccountNumber)}`, keyForList: bankAccountID?.toString(), - isSelected: bankAccountID?.toString() === walletTransfer?.selectedAccountID, + isSelected: bankAccountID?.toString() === selectedAccountID, bankAccount, }; }); return options; - }, [bankAccountsList, walletTransfer?.selectedAccountID, styles, translate]); + }, [bankAccountsList, selectedAccountID, styles, translate]); if (isLoadingOnyxValue(walletTransferResult)) { return ; @@ -92,7 +93,7 @@ function ChooseTransferAccountPage() { /> { const accountType = value?.bankAccount?.accountType; From b5967372c5f90dec2e39525d8b1b0f9ebbca2b5d Mon Sep 17 00:00:00 2001 From: Gandalf Date: Wed, 18 Sep 2024 00:27:01 +0530 Subject: [PATCH 09/11] use scrollView --- .../Wallet/ChooseTransferAccountPage.tsx | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx index bbf1a7ab31b0..327615187611 100644 --- a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx +++ b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx @@ -9,6 +9,7 @@ import getBankIcon from '@components/Icon/BankIcons'; import * as Expensicons from '@components/Icon/Expensicons'; import MenuItem from '@components/MenuItem'; import ScreenWrapper from '@components/ScreenWrapper'; +import ScrollView from '@components/ScrollView'; import SelectionList from '@components/SelectionList'; import RadioListItem from '@components/SelectionList/RadioListItem'; import useLocalize from '@hooks/useLocalize'; @@ -91,7 +92,7 @@ function ChooseTransferAccountPage() { title={translate('chooseTransferAccountPage.chooseAccount')} onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WALLET_TRANSFER_BALANCE)} /> - + - - + + ); } From 310212572061dfbf5ae468766fc3672b2016f24c Mon Sep 17 00:00:00 2001 From: Gandalf Date: Wed, 18 Sep 2024 13:48:26 +0530 Subject: [PATCH 10/11] implement suggestions --- src/pages/settings/Wallet/ChooseTransferAccountPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx index 327615187611..c6894d29fe63 100644 --- a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx +++ b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx @@ -36,7 +36,7 @@ function ChooseTransferAccountPage() { * @param accountType of the selected account type * @param account of the selected account data */ - const selectAccountAndNavigateBack = (event?: GestureResponderEvent | KeyboardEvent, accountType?: string, account?: AccountData) => { + const selectAccountAndNavigateBack = (accountType?: string, account?: AccountData) => { PaymentMethods.saveWalletTransferAccountTypeAndID( accountType ?? '', (accountType === CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT ? account?.bankAccountID?.toString() : account?.fundID?.toString()) ?? '', @@ -99,7 +99,7 @@ function ChooseTransferAccountPage() { onSelectRow={(value) => { const accountType = value?.bankAccount?.accountType; const accountData = value?.bankAccount?.accountData; - selectAccountAndNavigateBack(undefined, accountType, accountData); + selectAccountAndNavigateBack(accountType, accountData); }} shouldSingleExecuteRowSelect shouldUpdateFocusedIndex From 1260999542043d46d1456c6ead35c48f89f09582 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Wed, 18 Sep 2024 13:50:17 +0530 Subject: [PATCH 11/11] fix lint --- src/pages/settings/Wallet/ChooseTransferAccountPage.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx index c6894d29fe63..0bbcf957c31c 100644 --- a/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx +++ b/src/pages/settings/Wallet/ChooseTransferAccountPage.tsx @@ -1,5 +1,4 @@ import React, {useMemo} from 'react'; -import type {GestureResponderEvent} from 'react-native'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator';