From f2058f811e580098c20dac23b584d128a25ffd28 Mon Sep 17 00:00:00 2001 From: Tung Du Date: Mon, 16 Oct 2023 15:13:16 +0700 Subject: [PATCH] avoid using hard coded url --- assets/js/blocks/mini-cart/utils/data.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/assets/js/blocks/mini-cart/utils/data.ts b/assets/js/blocks/mini-cart/utils/data.ts index 70fe9cdb9ed..28ec68f0dc0 100644 --- a/assets/js/blocks/mini-cart/utils/data.ts +++ b/assets/js/blocks/mini-cart/utils/data.ts @@ -13,6 +13,7 @@ import { } from '@woocommerce/types'; import { getSettingWithCoercion } from '@woocommerce/settings'; import type { ColorPaletteOption } from '@woocommerce/editor-components/color-panel/types'; +import apiFetch from '@wordpress/api-fetch'; /** * Internal dependencies @@ -128,15 +129,9 @@ export const getMiniCartTotalsFromLocalStorage = (): export const getMiniCartTotalsFromServer = async (): Promise< [ CartResponseTotals, number ] | undefined > => { - return fetch( '/wp-json/wc/store/v1/cart/' ) - .then( ( response ) => { - // Check if the response was successful. - if ( ! response.ok ) { - throw new Error(); - } - - return response.json(); - } ) + return apiFetch< CartResponse >( { + path: '/wc/store/v1/cart', + } ) .then( ( data: CartResponse ) => { // Save server data to local storage, so we can re-fetch it faster // on the next page load.