woocommerce/plugins/woocommerce-admin/client/lib/currency-context.js

32 lines
700 B
JavaScript

/**
* External dependencies
*/
import { createContext } from '@wordpress/element';
import { applyFilters } from '@wordpress/hooks';
/**
* WooCommerce dependencies
*/
import CurrencyFactory from '@woocommerce/currency';
/**
* Internal dependencies
*/
import { CURRENCY } from '@woocommerce/wc-admin-settings';
const appCurrency = CurrencyFactory( CURRENCY );
export const getFilteredCurrencyInstance = ( query ) => {
const config = appCurrency.getCurrencyConfig();
const filteredConfig = applyFilters(
'woocommerce_admin_report_currency',
config,
query
);
return CurrencyFactory( filteredConfig );
};
export const CurrencyContext = createContext(
appCurrency // default value
);