2020-04-02 21:54:38 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { createContext } from '@wordpress/element';
|
|
|
|
import { applyFilters } from '@wordpress/hooks';
|
2020-06-17 23:33:40 +00:00
|
|
|
import CurrencyFactory from '@woocommerce/currency';
|
2022-01-06 12:53:30 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { CURRENCY } from '~/utils/admin-settings';
|
2020-04-02 21:54:38 +00:00
|
|
|
|
2020-06-17 23:33:40 +00:00
|
|
|
const appCurrency = CurrencyFactory( CURRENCY );
|
2020-04-02 21:54:38 +00:00
|
|
|
|
|
|
|
export const getFilteredCurrencyInstance = ( query ) => {
|
2020-06-17 23:33:40 +00:00
|
|
|
const config = appCurrency.getCurrencyConfig();
|
2022-02-11 14:38:38 +00:00
|
|
|
/**
|
|
|
|
* Filter the currency context. This affects all WooCommerce Admin currency formatting.
|
|
|
|
*
|
|
|
|
* @filter woocommerce_admin_report_currency
|
|
|
|
* @param {Object} config Currency configuration.
|
2022-03-18 11:45:14 +00:00
|
|
|
* @param {Object} query Url query parameters.
|
2022-02-11 14:38:38 +00:00
|
|
|
*/
|
2020-04-02 21:54:38 +00:00
|
|
|
const filteredConfig = applyFilters(
|
|
|
|
'woocommerce_admin_report_currency',
|
|
|
|
config,
|
|
|
|
query
|
|
|
|
);
|
2020-06-17 23:33:40 +00:00
|
|
|
return CurrencyFactory( filteredConfig );
|
2020-04-02 21:54:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const CurrencyContext = createContext(
|
|
|
|
appCurrency // default value
|
|
|
|
);
|