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();
|
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
|
|
|
|
);
|