Skip to content

Commit 8ee340a

Browse files
committed
Show non-USD bank accounts as incomplete instead of pending
1 parent 6695479 commit 8ee340a

4 files changed

Lines changed: 58 additions & 10 deletions

File tree

src/libs/BankAccountUtils.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,38 @@ function hasBankAccountAllowDebit(accountData: AccountData | undefined): boolean
6565
return !!accountData.allowDebit;
6666
}
6767

68-
function getBankAccountConnectionStatus(state: string | undefined): BankAccountConnectionStatus | undefined {
68+
function getIncompleteBankAccountStatus(): BankAccountConnectionStatus {
69+
return {
70+
labelKey: 'walletPage.bankAccountStatus.incomplete',
71+
messageKey: 'walletPage.bankAccountStatus.finishAddingBankAccount',
72+
actionKey: 'walletPage.bankAccountStatus.finish',
73+
tone: 'danger',
74+
brickRoadIndicator: CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR,
75+
};
76+
}
77+
78+
/**
79+
* Only the USD flow has a test transaction step, and the backend puts non-USD accounts in PENDING while they are still
80+
* being set up. So for those, PENDING means the setup is incomplete rather than waiting on the user to confirm test
81+
* transactions.
82+
*
83+
* This keys off currency rather than country because currency is what selects the flow everywhere else — see
84+
* ReimbursementAccountPage, which routes a PENDING account to the validation (test transaction) step only when the
85+
* currency is USD. An absent currency is treated as USD, matching BankAccount.getCurrency().
86+
*/
87+
function getBankAccountConnectionStatus(state: string | undefined, currency?: string): BankAccountConnectionStatus | undefined {
88+
if (state === CONST.BANK_ACCOUNT.STATE.PENDING && !!currency && currency !== CONST.CURRENCY.USD) {
89+
return getIncompleteBankAccountStatus();
90+
}
91+
6992
switch (state) {
7093
case CONST.BANK_ACCOUNT.STATE.OPEN:
7194
return {
7295
labelKey: 'walletPage.bankAccountStatus.active',
7396
tone: 'success',
7497
};
7598
case CONST.BANK_ACCOUNT.STATE.SETUP:
76-
return {
77-
labelKey: 'walletPage.bankAccountStatus.incomplete',
78-
messageKey: 'walletPage.bankAccountStatus.finishAddingBankAccount',
79-
actionKey: 'walletPage.bankAccountStatus.finish',
80-
tone: 'danger',
81-
brickRoadIndicator: CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR,
82-
};
99+
return getIncompleteBankAccountStatus();
83100
case CONST.BANK_ACCOUNT.STATE.PENDING:
84101
return {
85102
labelKey: 'walletPage.bankAccountStatus.pending',

src/pages/settings/Wallet/PaymentMethodList.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,9 @@ function PaymentMethodList({
580580
};
581581
const existingBrickRoadIndicator = (paymentMethod as Partial<PaymentMethodItem>).brickRoadIndicator;
582582
const isMissingPersonalInfo = isPersonalBankAccountMissingInfo(paymentMethod.accountData);
583-
const bankConnectionStatus = shouldShowConnectionStatus && !isMissingPersonalInfo ? getBankAccountConnectionStatus(getBankAccountState(paymentMethod.accountData)) : undefined;
583+
const bankAccountCurrency = ('bankCurrency' in paymentMethod ? paymentMethod.bankCurrency : undefined) ?? paymentMethod.accountData?.additionalData?.currency;
584+
const bankConnectionStatus =
585+
shouldShowConnectionStatus && !isMissingPersonalInfo ? getBankAccountConnectionStatus(getBankAccountState(paymentMethod.accountData), bankAccountCurrency) : undefined;
584586
const paymentMethodPress = (e: GestureResponderEvent | KeyboardEvent | undefined) =>
585587
pressHandler({
586588
event: e,

src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,10 @@ function WorkspaceWorkflowsPage({policy, route}: WorkspaceWorkflowsPageProps) {
484484
return undefined;
485485
}
486486
};
487-
const bankConnectionStatus = canAccessWalletConnectionStatusFeatures ? getBankAccountConnectionStatus(state) : undefined;
487+
// Read the currency off the same account `state` comes from, so a workspace whose currency no longer matches its
488+
// connected account can't flip the status to the wrong one.
489+
const bankAccountCurrency = bankAccountConnectedToWorkspace?.bankCurrency ?? bankAccountConnectedToWorkspace?.accountData?.additionalData?.currency;
490+
const bankConnectionStatus = canAccessWalletConnectionStatusFeatures ? getBankAccountConnectionStatus(state, bankAccountCurrency) : undefined;
488491
const bankConnectionBrickRoadIndicator = bankConnectionStatus?.brickRoadIndicator ?? (hasReimburserError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined);
489492
const bankConnectionStatusAddon = bankConnectionStatus ? (
490493
<ConnectionStatusBadge

tests/unit/BankAccountUtilsTest.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,32 @@ describe('BankAccountUtils', () => {
322322
});
323323
});
324324

325+
it.each([CONST.CURRENCY.USD, undefined])('keeps the confirm action for a PENDING account in currency "%s"', (currency) => {
326+
expect(getBankAccountConnectionStatus(CONST.BANK_ACCOUNT.STATE.PENDING, currency)).toEqual(
327+
expect.objectContaining({
328+
labelKey: 'walletPage.bankAccountStatus.pending',
329+
actionKey: 'common.confirm',
330+
}),
331+
);
332+
});
333+
334+
it.each(['GBP', 'EUR', 'AUD'])('maps a PENDING account in currency "%s" to Incomplete, since only USD accounts have test transactions', (currency) => {
335+
expect(getBankAccountConnectionStatus(CONST.BANK_ACCOUNT.STATE.PENDING, currency)).toEqual({
336+
labelKey: 'walletPage.bankAccountStatus.incomplete',
337+
messageKey: 'walletPage.bankAccountStatus.finishAddingBankAccount',
338+
actionKey: 'walletPage.bankAccountStatus.finish',
339+
tone: 'danger',
340+
brickRoadIndicator: CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR,
341+
});
342+
});
343+
344+
it.each([CONST.BANK_ACCOUNT.STATE.OPEN, CONST.BANK_ACCOUNT.STATE.SETUP, CONST.BANK_ACCOUNT.STATE.VERIFYING, CONST.BANK_ACCOUNT.STATE.LOCKED])(
345+
'is unaffected by a non-USD currency in state "%s"',
346+
(state) => {
347+
expect(getBankAccountConnectionStatus(state, 'GBP')).toEqual(getBankAccountConnectionStatus(state));
348+
},
349+
);
350+
325351
it.each([undefined, '', 'UNKNOWN'])('returns undefined for unsupported state "%s"', (state) => {
326352
expect(getBankAccountConnectionStatus(state)).toBeUndefined();
327353
});

0 commit comments

Comments
 (0)