Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 7 additions & 11 deletions src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, {useCallback, useContext, useMemo} from 'react';
import type {GestureResponderEvent} from 'react-native';
import type {TupleToUnion} from 'type-fest';
import ButtonWithDropdownMenu from '@components/ButtonWithDropdownMenu';
import type {DropdownOption} from '@components/ButtonWithDropdownMenu/types';
// eslint-disable-next-line no-restricted-imports
import * as Expensicons from '@components/Icon/Expensicons';
// eslint-disable-next-line no-restricted-imports
Expand Down Expand Up @@ -238,7 +239,7 @@ function SettlementButton({
const latestBankItem = getLatestBankAccountItem();

const paymentButtonOptions = useMemo(() => {
const buttonOptions = [];
const buttonOptions: Array<DropdownOption<string>> = [];
const paymentMethods = getSettlementButtonPaymentMethods(icons, hasActivatedWallet, translate);

const shortFormPayElsewhereButton = {
Expand Down Expand Up @@ -295,7 +296,7 @@ function SettlementButton({
buttonOptions.push({
text: latestBankItem.at(0)?.text ?? '',
icon: latestBankItem.at(0)?.icon,
iconStyles: latestBankItem.at(0)?.iconStyles,
additionalIconStyles: latestBankItem.at(0)?.iconStyles,
iconWidth: latestBankItem.at(0)?.iconSize,
iconHeight: latestBankItem.at(0)?.iconSize,
value: CONST.PAYMENT_METHODS.BUSINESS_BANK_ACCOUNT,
Expand All @@ -307,16 +308,15 @@ function SettlementButton({
}

if ((hasMultiplePolicies || hasSinglePolicy) && canUseWallet && !isPersonalOnlyOption) {
// eslint-disable-next-line unicorn/no-array-for-each
activeAdminPolicies.forEach((p) => {
for (const p of activeAdminPolicies) {
const policyName = p.name;
buttonOptions.push({
text: translate('iou.payWithPolicy', {policyName: truncate(policyName, {length: CONST.ADDITIONAL_ALLOWED_CHARACTERS}), formattedAmount: ''}),
icon: icons.Building,
value: p.id,
shouldUpdateSelectedIndex: false,
});
});
}
}

if (shouldShowPayElsewhereOption) {
Expand Down Expand Up @@ -545,11 +545,7 @@ function SettlementButton({
return undefined;
};

const handlePaymentSelection = (
event: GestureResponderEvent | KeyboardEvent | undefined,
selectedOption: PaymentMethodType | PaymentMethod,
triggerKYCFlow: (params: ContinueActionParams) => void,
) => {
const handlePaymentSelection = (event: GestureResponderEvent | KeyboardEvent | undefined, selectedOption: string, triggerKYCFlow: (params: ContinueActionParams) => void) => {
if (checkForNecessaryAction()) {
return;
}
Expand Down Expand Up @@ -603,7 +599,7 @@ function SettlementButton({
currency={currency}
>
{(triggerKYCFlow, buttonRef) => (
<ButtonWithDropdownMenu<PaymentMethodType | PaymentMethod>
<ButtonWithDropdownMenu<string>
onOptionsMenuShow={onPaymentOptionsShow}
onOptionsMenuHide={onPaymentOptionsHide}
buttonRef={buttonRef}
Expand Down
32 changes: 16 additions & 16 deletions src/hooks/useDuplicateTransactionsAndViolations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {useMemo} from 'react';
import type {OnyxCollection} from 'react-native-onyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Transaction, TransactionViolations} from '@src/types/onyx';
import type {Transaction, TransactionViolation, TransactionViolations} from '@src/types/onyx';
import useOnyx from './useOnyx';

/**
Expand All @@ -21,30 +21,30 @@ function selectViolationsWithDuplicates(transactionIDs: string[], allTransaction

for (const transactionID of transactionIDs) {
const key = `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`;
const transactionViolations = allTransactionsViolations[key];
const transactionViolations: TransactionViolations | undefined = allTransactionsViolations[key];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added undefined to this variable’s type because the value it retrieves can possibly be undefined.

Type inference isn’t working for some reason, even though OnyxCollection is typed like this:

type OnyxCollection<TOnyxValue> = OnyxEntry<Record<string, TOnyxValue | undefined>>;


if (!transactionViolations) {
continue;
}

result[key] = transactionViolations;

transactionViolations
.filter((violations) => violations.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION)
.flatMap((violations) => violations?.data?.duplicates ?? [])
// eslint-disable-next-line unicorn/no-array-for-each
.forEach((duplicateID) => {
if (!duplicateID) {
return;
}
const duplicateTransactionIDs = transactionViolations
.filter((violation: TransactionViolation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added type to this callback argument/parameter to fix eslint error implicitly has type 'any'

.flatMap((violation) => violation.data?.duplicates ?? []);

for (const duplicateID of duplicateTransactionIDs) {
if (!duplicateID) {
continue;
}

const duplicateKey = `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${duplicateID}`;
const duplicateViolations = allTransactionsViolations[duplicateKey];
const duplicateKey = `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${duplicateID}`;
const duplicateViolations: TransactionViolations | undefined = allTransactionsViolations[duplicateKey];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added undefined to this variable’s type because the value it retrieves can possibly be undefined.

Type inference isn’t working for some reason, even though OnyxCollection is typed like this:

type OnyxCollection<TOnyxValue> = OnyxEntry<Record<string, TOnyxValue | undefined>>;


if (duplicateViolations) {
result[duplicateKey] = duplicateViolations;
}
});
if (duplicateViolations) {
result[duplicateKey] = duplicateViolations;
}
}
}

return result;
Expand Down
Loading