Skip to content

Currency conversion fails with empty GBP rate causing zero amount conversions #105

@osw282

Description

@osw282

Issue Description

The currencyservice is experiencing critical conversion errors that result in zero amounts when converting from/to certain currencies. The logs show multiple instances of:

Currency conversion resulted in zero amount, switching back to original currency

Root Cause Analysis

After examining the source code in src/currencyservice/server.js and the currency data in src/currencyservice/data/currency_conversion.json, I've identified the root cause:

The GBP (British Pound) conversion rate is an empty string ("") instead of a numeric value.

In the currency_conversion.json file:

"GBP": "",

When the conversion function attempts to divide by an empty string, JavaScript coerces it to 0, which causes the mathematical operations to result in zero amounts:

const euros = _carry({
  units: from.units / data[from.currency_code],  // Division by empty string = 0
  nanos: from.nanos / data[from.currency_code]   // Division by empty string = 0
});

Impact

  • Currency conversions involving GBP fail and fallback to original currency
  • User experience is degraded when attempting GBP conversions
  • Error logs are generated repeatedly, potentially causing alert fatigue
  • The service attempts to send Slack notifications (with cooldown) for each failed conversion

Recommended Fix

Update the currency_conversion.json file to include a valid numeric conversion rate for GBP. Based on typical EUR to GBP rates, a value around 0.85 to 0.90 would be appropriate:

"GBP": "0.8631",

Additionally, consider implementing input validation in the conversion function to:

  1. Check for empty or invalid conversion rates before performing calculations
  2. Log warnings about invalid conversion data
  3. Gracefully handle missing or invalid currency rates

Files to Modify

  • src/currencyservice/data/currency_conversion.json - Fix the empty GBP rate
  • src/currencyservice/server.js - (Optional) Add input validation for conversion rates

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions