/** * WordPress dependencies */ import apiFetch from '@safe-wordpress/api-fetch'; import { dispatch, resolveSelect } from '@safe-wordpress/data'; /** * External dependencies */ import { logError } from '@nelio-content/utils'; /** * Internal dependencies */ import type { State } from './config'; import { store as NC_DATA } from '../../store'; export async function getProducts(): Promise< void > { try { const products = await apiFetch< State[ 'products' ] >( { path: '/nelio-content/v1/products', } ); await dispatch( NC_DATA ).receiveFSCurrency( 'USD' ); await dispatch( NC_DATA ).receiveFSProducts( products ); } catch ( error ) { logError( error ); throw error; } } export const getCurrency = async (): Promise< void > => void ( await resolveSelect( NC_DATA ).getProducts() );