2021-03-02 21:05:13 -06:00
|
|
|
import * as React from 'react'
|
2021-03-27 15:54:32 -06:00
|
|
|
import swell from 'swell-js'
|
2021-03-02 21:05:13 -06:00
|
|
|
import { ReactNode } from 'react'
|
|
|
|
|
|
|
|
import {
|
|
|
|
CommerceConfig,
|
|
|
|
CommerceProvider as CoreCommerceProvider,
|
|
|
|
useCommerce as useCoreCommerce,
|
|
|
|
} from '@commerce'
|
|
|
|
|
2021-03-27 15:54:32 -06:00
|
|
|
import { swellProvider, SwellProvider } from './provider'
|
|
|
|
import {
|
|
|
|
SHOPIFY_CHECKOUT_ID_COOKIE,
|
|
|
|
SWELL_STORE_ID,
|
|
|
|
SWELL_PUBLIC_KEY,
|
|
|
|
} from './const'
|
|
|
|
swell.init(SWELL_STORE_ID, SWELL_PUBLIC_KEY)
|
2021-03-02 21:05:13 -06:00
|
|
|
|
2021-03-27 15:54:32 -06:00
|
|
|
export { swellProvider }
|
|
|
|
export type { SwellProvider }
|
2021-03-02 21:05:13 -06:00
|
|
|
|
2021-03-27 15:54:32 -06:00
|
|
|
export const swellConfig: any = {
|
2021-03-02 21:05:13 -06:00
|
|
|
locale: 'en-us',
|
|
|
|
cartCookie: SHOPIFY_CHECKOUT_ID_COOKIE,
|
2021-03-27 15:54:32 -06:00
|
|
|
swell,
|
2021-03-02 21:05:13 -06:00
|
|
|
}
|
|
|
|
|
2021-03-27 15:54:32 -06:00
|
|
|
export type SwellConfig = Partial<CommerceConfig>
|
2021-03-02 21:05:13 -06:00
|
|
|
|
2021-03-27 15:54:32 -06:00
|
|
|
export type SwellProps = {
|
2021-03-02 21:05:13 -06:00
|
|
|
children?: ReactNode
|
|
|
|
locale: string
|
2021-03-27 15:54:32 -06:00
|
|
|
} & SwellConfig
|
2021-03-02 21:05:13 -06:00
|
|
|
|
2021-03-27 15:54:32 -06:00
|
|
|
export function CommerceProvider({ children, ...config }: SwellProps) {
|
2021-03-02 21:05:13 -06:00
|
|
|
return (
|
|
|
|
<CoreCommerceProvider
|
|
|
|
// TODO: Fix this type
|
2021-03-27 15:54:32 -06:00
|
|
|
provider={swellProvider as any}
|
|
|
|
config={{ ...swellConfig, ...config }}
|
2021-03-02 21:05:13 -06:00
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</CoreCommerceProvider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const useCommerce = () => useCoreCommerce()
|