Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
avoid using hard coded url
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhtungdu committed Oct 16, 2023
1 parent 17d39e3 commit f2058f8
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions assets/js/blocks/mini-cart/utils/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit f2058f8

Please sign in to comment.