Currency Convertor
Content Type: Widget
Categories: Extensions
Overview
Features
-
Dynamic Currency Selection:
- Provides dropdown menus for selecting both the source (from) and target (to) currencies.
- Automatically fetches a comprehensive list of available currencies from the API.
-
Real-Time Exchange Rate Fetching:
- Fetches live exchange rates from the Exchange Rates API to ensure accurate calculations.
- Updates exchange rates dynamically based on the selected currencies.
-
Customizable Inputs:
- Accepts default values for source currency, target currency, and amount, while allowing users to modify these inputs dynamically.
-
Conversion Logic:
- Calculates the converted amount using the formula:Converted Amount = Amount × (ToCurrency Rate / FromCurrency Rate)
- Displays the result in real-time after conversion.
-
Error Handling:
- Includes error logging for debugging issues related to API calls or data fetching.
-
User-Friendly Design:
- Clear labels and organized form groups for selecting currencies and inputting the amount.
- A dedicated button for performing the conversion.
Technical Workflow
-
Currency Fetching:
- On initial render, the widget fetches a list of currencies and their exchange rates using the fetch API.
- Populates dropdown menus with the fetched currencies.
-
State Management:
- Manages the selected source and target currencies, amount, exchange rate, and the converted amount using React's useState hooks.
-
Data Processing:
- Calculates the conversion rate by dividing the target currency's rate by the source currency's rate.
- Uses the computed rate to determine the final converted value.
-
Parent Integration:
- Includes an optional callback function (onConvertedAmount) to pass the converted amount back to the parent Mendix application or component, enhancing reusability.
Enhancements Over Previous Versions
-
Support for Any Currency:
- Extended support for all currencies available in the API, removing limitations to specific currency pairs.
-
Improved User Experience:
- Introduced structured form groups and intuitive UI components for better usability.
-
Dynamic Conversion Rates:
- Automatically updates the exchange rate when the user selects different currencies.
-
Integration Ready:
- Designed for easy integration with Mendix, with provisions for passing data back to the parent system.
Documentation
The Currency Converter Widget is designed for applications where real-time currency conversion is required. It simplifies the process of converting monetary values between different currencies, making it ideal for:
- Travel Management Systems: Helps users calculate travel expenses in their preferred currency.
- E-Commerce Platforms: Displays product prices in the user’s local currency, improving customer experience.
- Financial Applications: Assists in performing quick currency conversions for international transactions.
- Expense Management: Provides real-time conversion for budgeting and reporting across multiple currencies.
Problems Solved:
- Eliminates the need for manual currency conversions.
- Reduces errors in financial calculations.
- Offers real-time exchange rates to ensure accuracy.
Features and Limitations
Features:
- Real-Time Exchange Rate Fetching: Dynamically retrieves live exchange rates from the API.
- Multi-Currency Support: Converts between any two currencies available in the API.
- User-Friendly Interface: Intuitive dropdowns for selecting currencies and an input field for the amount.
- Customizable Defaults: Supports default values for source and target currencies and the amount.
- Integration Capability: Allows parent applications to retrieve the converted amount via a callback function.
- Dynamic Updates: Automatically recalculates the conversion when input values or selected currencies change.
Limitations:
- API Dependency: Requires a valid API key for accessing exchange rates.
- Internet Connection: Needs an active internet connection to fetch real-time data.
- Limited Error Feedback: Logs errors in the console but does not display user-friendly error messages for API failures.
Dependencies
- React Library: Used for creating and managing the widget’s UI.
- Exchange Rates API: Fetches live exchange rates.
- API Endpoint: http://api.exchangeratesapi.io/v1/latest
- API Key: Ensure you have a valid access key from Exchange Rates API.