How to get consistent exchange rates that work with Hydrogen

As Shopify app developers, we aim to create applications that provide a consistent interface for both Liquid-based stores and Hydrogen-based storefronts. However, we face significant issues when it comes to handling currency conversion:

Currency Conversion in Liquid

  • In Liquid themes, Shopify.currency.rate is available for use in JavaScript. This is implicitly provided by Shopify through {{ content_for_header }}.
  • While this is not ideal (as it is only accessible on the client side), it allows us to convert simple numerical values, such as custom prices stored in metafields, into the store’s display currency.
  • This enables us to align the currency display of custom prices defined by the app (such as bundle discounts or option prices) with the currency display of standard products when “local currency display” is enabled.

Issues in Hydrogen

  • In Hydrogen, there is no equivalent to Shopify.currency.rate.
  • As a result, developers are forced to use external APIs or implement custom solutions. This approach may lead to discrepancies between the currency display of custom prices and that of regular products when using @inContext for currency conversion.

Why This Matters

  • Due to strict limitations in Shopify Functions, we as app developers often want to store store owners’ configured values as JSON-type metafields. Specifically, in this context, we frequently incorporate these values as “simple numbers” within a JSON structure rather than as “money type” values.

What We Are Looking For

We believe that if we could access exchange rates that shopify is using through the GraphQL Storefront API, this issue could be resolved.

Importance of a Solution

Without such a solution, building apps that function similarly across both platforms becomes unnecessarily complex and prone to inconsistencies. If Hydrogen could also access Shopify’s exchange rates, it would greatly enhance the consistency and efficiency of app development across platforms.