Skip to content

Commit

Permalink
Fix excluded currency and countries
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham1206agra committed Jan 4, 2025
1 parent da88626 commit c07ec58
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6490,6 +6490,8 @@ const CONST = {
},

CORPAY_FIELDS: {
EXCLUDED_COUNTRIES: ['IR', 'CU', 'SY', 'UA', 'KP', 'RU'] as string[],
EXCLUDED_CURRENCIES: ['IRR', 'CUP', 'SYP', 'UAH', 'KPW', 'RUB'] as string[],
BANK_ACCOUNT_DETAILS_FIELDS: ['accountNumber', 'localAccountNumber', 'routingCode', 'localRoutingCode', 'swiftBicCode'] as string[],
ACCOUNT_TYPE_KEY: 'BeneficiaryAccountType',
BANK_INFORMATION_FIELDS: ['bankName', 'bankAddressLine1', 'bankAddressLine2', 'bankCity', 'bankRegion', 'bankPostal', 'BeneficiaryBankBranchName'] as string[],
Expand Down
6 changes: 5 additions & 1 deletion src/components/CurrencyPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ type CurrencyPickerProps = {

/** Form Error description */
errorText?: string;

/** List of currencies to exclude from the list */
excludeCurrencies?: string[];
};

function CurrencyPicker({value, errorText, headerContent, onInputChange = () => {}}: CurrencyPickerProps) {
function CurrencyPicker({value, errorText, headerContent, excludeCurrencies, onInputChange = () => {}}: CurrencyPickerProps) {
const {translate} = useLocalize();
const [isPickerVisible, setIsPickerVisible] = useState(false);
const styles = useThemeStyles();
Expand Down Expand Up @@ -75,6 +78,7 @@ function CurrencyPicker({value, errorText, headerContent, onInputChange = () =>
initiallySelectedCurrencyCode={value}
onSelect={updateInput}
searchInputLabel={translate('common.search')}
excludedCurrencies={excludeCurrencies}
/>
</ScreenWrapper>
</Modal>
Expand Down
5 changes: 3 additions & 2 deletions src/components/CurrencySelectionList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function CurrencySelectionList({
selectedCurrencies = [],
canSelectMultiple = false,
recentlyUsedCurrencies,
excludedCurrencies = [],
}: CurrencySelectionListProps) {
const [currencyList] = useOnyx(ONYXKEYS.CURRENCY_LIST);
const [searchValue, setSearchValue] = useState('');
Expand All @@ -25,7 +26,7 @@ function CurrencySelectionList({
const {sections, headerMessage} = useMemo(() => {
const currencyOptions: CurrencyListItem[] = Object.entries(currencyList ?? {}).reduce((acc, [currencyCode, currencyInfo]) => {
const isSelectedCurrency = currencyCode === initiallySelectedCurrencyCode || selectedCurrencies.includes(currencyCode);
if (isSelectedCurrency || !currencyInfo?.retired) {
if (!excludedCurrencies.includes(currencyCode) && (isSelectedCurrency || !currencyInfo?.retired)) {
acc.push({
currencyName: currencyInfo?.name ?? '',
text: `${currencyCode} - ${CurrencyUtils.getCurrencySymbol(currencyCode)}`,
Expand Down Expand Up @@ -86,7 +87,7 @@ function CurrencySelectionList({
}

return {sections: result, headerMessage: isEmpty ? translate('common.noResultsFound') : ''};
}, [currencyList, searchValue, translate, initiallySelectedCurrencyCode, selectedCurrencies, getUnselectedOptions, recentlyUsedCurrencies]);
}, [currencyList, recentlyUsedCurrencies, searchValue, getUnselectedOptions, translate, initiallySelectedCurrencyCode, selectedCurrencies, excludedCurrencies]);

return (
<SelectionList
Expand Down
3 changes: 3 additions & 0 deletions src/components/CurrencySelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type CurrencySelectionListProps = {

/** Whether this is a multi-select list */
canSelectMultiple?: boolean;

/** List of excluded currency codes */
excludedCurrencies?: string[];
};

export type {CurrencyListItem, CurrencySelectionListProps};
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function BankAccountDetails({isEditing, onNext, resetScreenIndex, formValues, fi
value={formValues.bankCurrency}
onInputChange={onCurrencySelected}
headerContent={currencyHeaderContent}
excludeCurrencies={CONST.CORPAY_FIELDS.EXCLUDED_CURRENCIES}
/>
</View>
{Object.values(fieldsMap[CONST.CORPAY_FIELDS.STEPS_NAME.BANK_ACCOUNT_DETAILS] ?? {}).map((field) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@ function CountrySelection({isEditing, onNext, formValues, resetScreenIndex}: Cus

const countries = useMemo(
() =>
Object.keys(CONST.ALL_COUNTRIES).map((countryISO) => {
const countryName = translate(`allCountries.${countryISO}` as TranslationPaths);
return {
value: countryISO,
keyForList: countryISO,
text: countryName,
isSelected: currentCountry === countryISO,
searchValue: StringUtils.sanitizeString(`${countryISO}${countryName}`),
};
}),
Object.keys(CONST.ALL_COUNTRIES)
.filter((countryISO) => !CONST.CORPAY_FIELDS.EXCLUDED_COUNTRIES.includes(countryISO))
.map((countryISO) => {
const countryName = translate(`allCountries.${countryISO}` as TranslationPaths);
return {
value: countryISO,
keyForList: countryISO,
text: countryName,
isSelected: currentCountry === countryISO,
searchValue: StringUtils.sanitizeString(`${countryISO}${countryName}`),
};
}),
[translate, currentCountry],
);

Expand Down

0 comments on commit c07ec58

Please sign in to comment.