1 import { type MutableRefObject, createContext, useContext } from 'react';
3 import { ChargebeeEnabled } from '@proton/shared/lib/interfaces';
5 export type CalledKillSwitchString = 'called' | 'not-called';
7 export type ChargebeeContext = {
8 enableChargebeeRef: MutableRefObject<ChargebeeEnabled>;
9 calledKillSwitch: CalledKillSwitchString;
10 setCalledKillSwitch: (value: CalledKillSwitchString) => unknown;
13 export const PaymentSwitcherContext = createContext<ChargebeeContext>({
15 current: ChargebeeEnabled.CHARGEBEE_FORCED,
17 calledKillSwitch: 'not-called',
18 setCalledKillSwitch: () => {},
21 export const useChargebeeContext = () => {
22 return useContext(PaymentSwitcherContext);
25 export const useChargebeeEnabledCache = () => {
26 const chargebeeContext = useChargebeeContext();
27 return (): ChargebeeEnabled => chargebeeContext.enableChargebeeRef.current;