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.
Releases
Version: 1.0.0
Framework Version: 10.12.0
Release Notes: Initial Functional State
Basic Features:
Supported conversion between two hardcoded currencies (USD and INR).
Allowed users to input the amount to be converted and displayed the converted value.
Fetched exchange rates dynamically from the Exchange Rates API.
Default source (fromCurrency) and target (toCurrency) currencies were predefined as USD and INR.
Functional Limitations:
Hardcoded currency selection; no dropdown for choosing different currencies.
Minimal error handling for API failures or invalid user inputs.
Lack of dynamic feedback for loading states or unsuccessful conversions.
Corrections Made
Error Handling:
Added console error logging for issues during API calls to aid in debugging.
Addressed scenarios where the fetched exchange rate might be undefined or unavailable.
Ensured the input amount defaults to a valid value if left empty or set to an invalid number.
Dynamic Defaults:
Allowed flexibility in overriding the default fromCurrency, toCurrency, and amount values by passing them as props.
Changes Made
Enhanced Currency Selection:
Introduced dropdown menus populated with a full list of currencies fetched from the API.
Enabled users to select both source and target currencies dynamically.
Conversion Logic:
Refined the exchange rate calculation to ensure accuracy using the formula:
Exchange Rate = ToCurrency Rate / FromCurrency Rate.
Improved UI/UX:
Grouped input fields into well-structured form sections.
Added a button to trigger conversion, ensuring clear user interaction points.
Enhancements Made
Support for Multiple Currencies:
Extended functionality to support conversion between any two currencies available in the API.
Dynamic Updates:
Automatically updated the exchange rate and conversion results when the user changed currencies or input values.
Integration Capability:
Added an optional onConvertedAmount callback to pass the converted amount back to the parent Mendix application for further use or integration.
Error Feedback:
Incorporated visual feedback for users to handle scenarios like missing data or unsuccessful API calls.
User-Friendly Defaults:
Ensured the widget initializes with reasonable default values for currencies and amounts, even if props are not provided.