diff --git a/framework/swell/const.ts b/framework/swell/const.ts index 669194298..16d493896 100644 --- a/framework/swell/const.ts +++ b/framework/swell/const.ts @@ -4,8 +4,6 @@ export const SWELL_CHECKOUT_URL_COOKIE = 'swell_checkoutUrl' export const SWELL_CUSTOMER_TOKEN_COOKIE = 'swell_customerToken' -export const STORE_DOMAIN = process.env.NEXT_PUBLIC_SWELL_STORE_DOMAIN - export const SWELL_COOKIE_EXPIRE = 30 export const SWELL_STORE_ID = process.env.NEXT_PUBLIC_SWELL_STORE_ID diff --git a/framework/swell/index.tsx b/framework/swell/index.tsx index 28f60b394..b64df6d48 100644 --- a/framework/swell/index.tsx +++ b/framework/swell/index.tsx @@ -1,47 +1,9 @@ -import * as React from 'react' -import swell from 'swell-js' -import { ReactNode } from 'react' - -import { - CommerceConfig, - CommerceProvider as CoreCommerceProvider, - useCommerce as useCoreCommerce, -} from '@commerce' - +import { getCommerceProvider, useCommerce as useCoreCommerce } from '@commerce' import { swellProvider, SwellProvider } from './provider' -import { - SWELL_CHECKOUT_ID_COOKIE, - SWELL_STORE_ID, - SWELL_PUBLIC_KEY, -} from './const' -swell.init(SWELL_STORE_ID, SWELL_PUBLIC_KEY) export { swellProvider } export type { SwellProvider } -export const swellConfig: any = { - locale: 'en-us', - cartCookie: SWELL_CHECKOUT_ID_COOKIE, - swell, -} +export const CommerceProvider = getCommerceProvider(swellProvider) -export type SwellConfig = Partial - -export type SwellProps = { - children?: ReactNode - locale: string -} & SwellConfig - -export function CommerceProvider({ children, ...config }: SwellProps) { - return ( - - {children} - - ) -} - -export const useCommerce = () => useCoreCommerce() +export const useCommerce = () => useCoreCommerce() diff --git a/framework/swell/provider.ts b/framework/swell/provider.ts index aa7be31d4..1b221c05f 100644 --- a/framework/swell/provider.ts +++ b/framework/swell/provider.ts @@ -1,6 +1,10 @@ +import swell from 'swell-js' import { Provider } from '@commerce' - -import { SWELL_CHECKOUT_URL_COOKIE, STORE_DOMAIN } from './const' +import { + SWELL_CHECKOUT_ID_COOKIE, + SWELL_STORE_ID, + SWELL_PUBLIC_KEY, +} from './const' import { handler as useCart } from './cart/use-cart' import { handler as useAddItem } from './cart/use-add-item' @@ -16,10 +20,12 @@ import { handler as useSignup } from './auth/use-signup' import fetcher from './fetcher' -export const swellProvider: Provider = { +swell.init(SWELL_STORE_ID, SWELL_PUBLIC_KEY) + +export const swellProvider: Provider & { swell: any } = { locale: 'en-us', - cartCookie: SWELL_CHECKOUT_URL_COOKIE, - // storeDomain: STORE_DOMAIN, + cartCookie: SWELL_CHECKOUT_ID_COOKIE, + swell, fetcher, cart: { useCart, useAddItem, useUpdateItem, useRemoveItem }, customer: { useCustomer },