Skip to content
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

Refactor TransferWalletBalance #9589

Merged
merged 54 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
6b71211
Use new API command: TransferBalance
MariaHCD Jun 28, 2022
2f7b9cc
Remove unnecessary saveWalletTransferAmount method
MariaHCD Jun 28, 2022
aec6865
Remove usage of deprecated API command
MariaHCD Jun 28, 2022
a4f35dd
Fix JSDoc and remove unused import
MariaHCD Jun 28, 2022
6f4c9bb
Add successful balance transfer page
MariaHCD Jun 30, 2022
3e5fee2
Fixes for successful transfer balance page
MariaHCD Jun 30, 2022
60eed1c
Show transfer success page
MariaHCD Jun 30, 2022
ae22a8b
Add showShouldTransferSuccess Onyx prop
MariaHCD Jun 30, 2022
eaed050
Import routes
MariaHCD Jun 30, 2022
8ede4a9
Add close button
MariaHCD Jun 30, 2022
93fe910
Allow success and failure data to be set for refactored commands
MariaHCD Jun 30, 2022
bd830bd
Style fixes
MariaHCD Jun 30, 2022
fea3749
Rename api command
MariaHCD Jun 30, 2022
79e80d9
Update success transfer message
MariaHCD Jun 30, 2022
de4847c
Update success message
MariaHCD Jun 30, 2022
217c071
Remove unused confirm modal
MariaHCD Jun 30, 2022
c70a5ea
Delete successful transfer balance page
MariaHCD Jul 1, 2022
a3aa6b1
Style fixes
MariaHCD Jul 1, 2022
7419781
Merge remote-tracking branch 'origin/main' into maria-refactor-transf…
MariaHCD Jul 6, 2022
ac8f06d
Merge remote-tracking branch 'origin/main' into maria-refactor-transf…
MariaHCD Jul 7, 2022
725900b
Rename method
MariaHCD Jul 7, 2022
93bbb80
Specify that we want the API to return onyxData
MariaHCD Jul 7, 2022
96ed727
Merge remote-tracking branch 'origin/main' into maria-refactor-transf…
MariaHCD Jul 8, 2022
114f2d5
Update transfer balance success screen
MariaHCD Jul 8, 2022
81ec21e
Update success text
MariaHCD Jul 8, 2022
247b557
Remove unused text and translations
MariaHCD Jul 8, 2022
bc8ad80
Fix capitalization
MariaHCD Jul 8, 2022
173255a
Add Spanish translations
MariaHCD Jul 8, 2022
3cb64a0
Add TadaBlue illustration
MariaHCD Jul 11, 2022
88f1a41
Use blue tada icon
MariaHCD Jul 11, 2022
6cd7456
Remove unused prop `transferAmount`
MariaHCD Jul 12, 2022
e794b9f
Remove unused `shouldShowConfirmModal` and `dismissWalletConfirmModal`
MariaHCD Jul 12, 2022
956cd08
Rename to `shouldShowSuccess`
MariaHCD Jul 12, 2022
2ed73e0
Remove unused `transferAmount` prop
MariaHCD Jul 13, 2022
7046e6c
Merge remote-tracking branch 'origin/main' into maria-refactor-transf…
MariaHCD Jul 13, 2022
76eb693
Add copy for debit card transfer success
MariaHCD Jul 15, 2022
6891d26
Show success message based on payment method type
MariaHCD Jul 15, 2022
9da172d
Style fix
MariaHCD Jul 15, 2022
0e766f1
Add translation
MariaHCD Jul 18, 2022
d900116
Disable transfer balance if offline
MariaHCD Jul 18, 2022
bdd1b55
Disable transfer button if offline
MariaHCD Jul 18, 2022
ec86579
Merge remote-tracking branch 'origin/main' into maria-refactor-transf…
MariaHCD Jul 18, 2022
7564b3c
Merge remote-tracking branch 'origin/main' into maria-refactor-transf…
MariaHCD Jul 19, 2022
193ed3f
Add containerStyles prop to OfflineIndicator
MariaHCD Jul 19, 2022
cc59b0a
Add OfflineIndicator to BasePaymentsPage and TransferBalancePage
MariaHCD Jul 19, 2022
1796df0
Adjust icon and styles for OfflineIndicator
MariaHCD Jul 20, 2022
1d50772
Merge remote-tracking branch 'origin/main' into maria-refactor-transf…
MariaHCD Jul 20, 2022
7909bbb
Fix styling of OfflineIndicator on TransferBalancePage
MariaHCD Jul 20, 2022
706d90b
Fix icon size for OfflineIndicator
MariaHCD Jul 21, 2022
84f9837
Merge remote-tracking branch 'origin/main' into maria-refactor-transf…
MariaHCD Jul 21, 2022
d34fd5c
Fix errors from merge conflicts
MariaHCD Jul 21, 2022
1eebd13
Optionally override default styles for OfflineIndicator
MariaHCD Jul 21, 2022
514e874
fix conflicts
ctkochan22 Jul 21, 2022
e4550d6
use new prop
ctkochan22 Jul 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions assets/images/product-illustrations/tada--blue.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/components/Icon/Illustrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import MoneyMousePink from '../../../assets/images/product-illustrations/money-m
import ReceiptYellow from '../../../assets/images/product-illustrations/receipt--yellow.svg';
import RocketOrange from '../../../assets/images/product-illustrations/rocket--orange.svg';
import TadaYellow from '../../../assets/images/product-illustrations/tada--yellow.svg';
import TadaBlue from '../../../assets/images/product-illustrations/tada--blue.svg';
import GpsTrackOrange from '../../../assets/images/product-illustrations/gps-track--orange.svg';

export {
Expand All @@ -33,5 +34,6 @@ export {
ReceiptYellow,
RocketOrange,
TadaYellow,
TadaBlue,
GpsTrackOrange,
};
26 changes: 15 additions & 11 deletions src/components/OfflineIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ const propTypes = {
/** Information about the network */
network: networkPropTypes.isRequired,

/** Additional styles to add after local styles. */
style: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.object),
PropTypes.object,
]),
/** Optional styles for container element that will override the default styling for the offline indicator */
containerStyles: PropTypes.arrayOf(PropTypes.object),

/** Is the window width narrow, like on a mobile device */
isSmallScreenWidth: PropTypes.bool.isRequired,
Expand All @@ -30,7 +27,14 @@ const propTypes = {
};

const defaultProps = {
style: [],
containerStyles: [],
};

const setStyles = (containerStyles, isSmallScreenWidth) => {
if (containerStyles.length) {
return containerStyles;
}
return isSmallScreenWidth ? styles.offlineIndicatorMobile : styles.offlineIndicator;
};

const OfflineIndicator = (props) => {
Expand All @@ -40,18 +44,18 @@ const OfflineIndicator = (props) => {

return (
<View style={[
props.isSmallScreenWidth ? styles.offlineIndicatorMobile : styles.offlineIndicator,
setStyles(props.containerStyles, props.isSmallScreenWidth),
styles.flexRow,
styles.alignItemsCenter,
...StyleUtils.parseStyleAsArray(props.style),
]}
>
<Icon
src={Expensicons.Offline}
width={variables.iconSizeExtraSmall}
height={variables.iconSizeExtraSmall}
src={Expensicons.OfflineCloud}
width={variables.iconSizeSmall}
height={variables.iconSizeSmall}
/>
<Text style={[styles.ml2, styles.chatItemComposeSecondaryRowSubText]}>
<Text style={[styles.ml3, styles.chatItemComposeSecondaryRowSubText]}>
{props.translate('common.youAppearToBeOffline')}
</Text>
</View>
Expand Down
6 changes: 3 additions & 3 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,6 @@ export default {
deleteBankAccountSuccess: 'Bank account successfully deleted',
deleteDebitCardSuccess: 'Debit Card successfully deleted',
deletePayPalSuccess: 'PayPal.me successfully deleted',
allSet: 'All Set!',
transferConfirmText: ({amount}) => `${amount} will hit your account shortly!`,
gotIt: 'Got it, Thanks!',
error: {
notOwnerOfBankAccount: 'There was an error setting this bank account as your default payment method.',
invalidBankAccount: 'This bank account is temporarily suspended.',
Expand All @@ -407,6 +404,9 @@ export default {
achSummary: 'No fee',
whichAccount: 'Which Account?',
fee: 'Fee',
transferSuccess: 'Transfer successful!',
transferDetailBankAccount: 'Your money should arrive in the next 1-3 business days.',
transferDetailDebitCard: 'Your money should arrive immediately.',
failedTransfer: 'Your balance isn’t fully settled. Please transfer to a bank account.',
},
chooseTransferAccountPage: {
Expand Down
6 changes: 3 additions & 3 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,6 @@ export default {
deleteBankAccountSuccess: 'Cuenta bancaria eliminada correctamente',
deleteDebitCardSuccess: 'Tarjeta de débito eliminada correctamente',
deletePayPalSuccess: 'PayPal.me eliminada correctamente',
allSet: 'Todo listo!',
transferConfirmText: ({amount}) => `${amount} llegará a tu cuenta en breve!`,
gotIt: 'Gracias!',
error: {
notOwnerOfBankAccount: 'Ha ocurrido un error al establecer esta cuenta bancaria como tu método de pago predeterminado.',
invalidBankAccount: 'Esta cuenta bancaria está temporalmente suspendida.',
Expand All @@ -407,6 +404,9 @@ export default {
achSummary: 'Sin cargo',
whichAccount: '¿Que cuenta?',
fee: 'Tarifa',
transferSuccess: '¡Transferencia exitosa!',
transferDetailBankAccount: 'Tu dinero debería llegar en 1-3 días laborables.',
transferDetailDebitCard: 'Tu dinero debería llegar de inmediato.',
failedTransfer: 'Tu saldo no se ha acreditado completamente. Por favor transfiere los fondos a una cuenta bancaria.',
},
chooseTransferAccountPage: {
Expand Down
66 changes: 40 additions & 26 deletions src/libs/actions/PaymentMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import Growl from '../Growl';
import * as Localize from '../Localize';
import Navigation from '../Navigation/Navigation';
import * as CardUtils from '../CardUtils';
import ROUTES from '../../ROUTES';
import * as User from './User';
import * as store from './ReimbursementAccount/store';
import ROUTES from '../../ROUTES';

/**
* Deletes a debit card
Expand Down Expand Up @@ -215,21 +215,42 @@ function transferWalletBalance(paymentMethod) {
: CONST.PAYMENT_METHOD_ID_KEYS.DEBIT_CARD;
const parameters = {
[paymentMethodIDKey]: paymentMethod.methodID,
shouldReturnOnyxData: true,
};
Onyx.merge(ONYXKEYS.WALLET_TRANSFER, {loading: true});

DeprecatedAPI.TransferWalletBalance(parameters)
.then((response) => {
if (response.jsonCode !== 200) {
throw new Error(response.message);
}
Onyx.merge(ONYXKEYS.USER_WALLET, {currentBalance: 0});
Onyx.merge(ONYXKEYS.WALLET_TRANSFER, {shouldShowConfirmModal: true, loading: false});
Navigation.navigate(ROUTES.SETTINGS_PAYMENTS);
}).catch(() => {
Growl.error(Localize.translateLocal('transferAmountPage.failedTransfer'));
Onyx.merge(ONYXKEYS.WALLET_TRANSFER, {loading: false});
});
API.write('TransferWalletBalance', parameters, {
optimisticData: [
{
onyxMethod: 'merge',
key: ONYXKEYS.WALLET_TRANSFER,
value: {
loading: true,
error: null,
},
},
],
successData: [
{
onyxMethod: 'merge',
key: ONYXKEYS.WALLET_TRANSFER,
value: {
loading: false,
shouldShowSuccess: true,
paymentMethodType: paymentMethod.accountType,
},
},
],
failureData: [
{
onyxMethod: 'merge',
key: ONYXKEYS.WALLET_TRANSFER,
value: {
loading: false,
shouldShowSuccess: false,
},
},
],
});
}

function resetWalletTransferData() {
Expand All @@ -238,17 +259,10 @@ function resetWalletTransferData() {
selectedAccountID: null,
filterPaymentMethodType: null,
loading: false,
shouldShowConfirmModal: false,
shouldShowSuccess: false,
});
}

/**
* @param {Number} transferAmount
*/
function saveWalletTransferAmount(transferAmount) {
Onyx.merge(ONYXKEYS.WALLET_TRANSFER, {transferAmount});
}

/**
* @param {String} selectedAccountType
* @param {String} selectedAccountID
Expand All @@ -265,8 +279,9 @@ function saveWalletTransferMethodType(filterPaymentMethodType) {
Onyx.merge(ONYXKEYS.WALLET_TRANSFER, {filterPaymentMethodType});
}

function dismissWalletConfirmModal() {
Onyx.merge(ONYXKEYS.WALLET_TRANSFER, {shouldShowConfirmModal: false});
function dismissSuccessfulTransferBalancePage() {
Onyx.merge(ONYXKEYS.WALLET_TRANSFER, {shouldShowSuccess: false});
Navigation.navigate(ROUTES.SETTINGS_PAYMENTS);
}

export {
Expand All @@ -278,11 +293,10 @@ export {
kycWallRef,
continueSetup,
clearDebitCardFormErrorAndSubmit,
dismissSuccessfulTransferBalancePage,
transferWalletBalance,
resetWalletTransferData,
saveWalletTransferAmount,
saveWalletTransferAccountTypeAndID,
saveWalletTransferMethodType,
dismissWalletConfirmModal,
cleanLocalReimbursementData,
};
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ class ReportActionCompose extends React.Component {
</View>
</View>
<View style={[styles.chatItemComposeSecondaryRow, styles.flexRow, styles.justifyContentBetween, styles.alignItemsCenter]}>
{!this.props.isSmallScreenWidth && <OfflineIndicator style={[styles.chatItemComposeSecondaryRowOffset]} />}
{!this.props.isSmallScreenWidth && <OfflineIndicator containerStyles={[styles.chatItemComposeSecondaryRowOffset]} />}
<ReportTypingIndicator reportID={this.props.reportID} />
<ExceededCommentLength commentLength={this.comment.length} />
</View>
Expand Down
17 changes: 3 additions & 14 deletions src/pages/settings/Payments/PaymentsPage/BasePaymentsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import ConfirmPopover from '../../../../components/ConfirmPopover';
import AddPaymentMethodMenu from '../../../../components/AddPaymentMethodMenu';
import CONST from '../../../../CONST';
import * as Expensicons from '../../../../components/Icon/Expensicons';
import ConfirmModal from '../../../../components/ConfirmModal';
import KYCWall from '../../../../components/KYCWall';
import {propTypes, defaultProps} from './paymentsPagePropTypes';
import {withNetwork} from '../../../../components/OnyxProvider';
import * as PaymentUtils from '../../../../libs/PaymentUtils';
import OfflineIndicator from '../../../../components/OfflineIndicator';

class BasePaymentsPage extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -291,6 +291,7 @@ class BasePaymentsPage extends React.Component {
icon={Expensicons.Transfer}
onPress={triggerKYCFlow}
shouldShowRightIcon
disabled={this.props.network.isOffline}
/>
)}
</KYCWall>
Expand Down Expand Up @@ -433,19 +434,7 @@ class BasePaymentsPage extends React.Component {
shouldShowCancelButton
danger
/>
<ConfirmModal
title={this.props.translate('paymentsPage.allSet')}
onConfirm={PaymentMethods.dismissWalletConfirmModal}
isVisible={this.props.walletTransfer.shouldShowConfirmModal}
prompt={this.props.translate('paymentsPage.transferConfirmText', {
amount: this.props.numberFormat(
this.props.walletTransfer.transferAmount / 100,
{style: 'currency', currency: 'USD'},
),
})}
confirmText={this.props.translate('paymentsPage.gotIt')}
shouldShowCancelButton={false}
/>
<OfflineIndicator containerStyles={[styles.ml5, styles.mv3]} />
</ScreenWrapper>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const propTypes = {

const defaultProps = {
walletTransfer: {
shouldShowConfirmModal: false,
shouldShowSuccess: false,
},
betas: [],
isLoadingPaymentMethods: true,
Expand Down
Loading