hyperswitch-web
hyperswitch-web copied to clipboard
[FEATURE] add a mapping of countries in CountryAlpha2 enum to countries in human readable format for payout links #6083
Type of Change
- [ ] Bugfix
- [X] New feature
- [ ] Enhancement
- [ ] Refactoring
- [ ] Dependency updates
- [ ] Documentation
- [ ] CI/CD
Description
This PR implements country code to human-readable name conversion for the payout widget, allowing users to see country names like "United States of America" instead of ISO codes like "US" in dropdown menus.
Enhanced the existing Country module with mapping functions to convert CountryAlpha2 codes to human-readable country names for display, while maintaining backend compatibility.
Changes Made
src/Country.res
- Updated US country name to "United States of America" for consistency with backend
- Added
getCountryNameFromAlpha2()- converts ISO alpha-2 codes (e.g., "US") to human-readable names (e.g., "United States of America") - Added
getAlpha2FromCountryName()- reverse conversion for form submission - Implemented robust versions with case-insensitive matching and trimming for better error handling
- Added
getAllCountriesWithMapping()utility for complete country data access
src/Payments/PaymentMethodsRecord.res
- Added
getCountryOptionsFromAlpha2Codes()- batch converts arrays of country codes to names with O(n+m) performance using Set-based lookups - Added
getAlpha2CodeFromCountryName()- delegates to Country module for consistency
Details*
- Bidirectional mapping: Converts between ISO alpha-2 codes and human-readable names in both directions
- Robust error handling: Case-insensitive matching with fallback values
- Single source of truth: All country mapping centralized in Country module
Example
Before: Dropdown shows ["US", "GB", "IN"]
After: Dropdown shows ["United States of America", "United Kingdom", "India"]
Usage
The payout widget can now display country dropdowns with human-readable names while maintaining ISO alpha-2 codes for API communication, matching the pattern used in backend utilities like list_countries_currencies_for_connector_payment_method_util.
Fixes: #6083
How did you test it?
Checklist
- [X] I ran
npm run re:build - [X] I reviewed submitted code
- [X] I added unit tests for my changes where possible