Path: blob/main/components/dashboard/src/payment-context.tsx
2498 views
/**1* Copyright (c) 2022 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import React, { createContext, useContext, useMemo, useState } from "react";78export type Currency = "USD" | "EUR";910const PaymentContext = createContext<{11currency: Currency;12setCurrency: React.Dispatch<Currency>;13}>({14currency: "USD",15setCurrency: () => null,16});1718const PaymentContextProvider: React.FC = ({ children }) => {19const [currency, setCurrency] = useState<Currency>("USD");2021const ctx = useMemo(22() => ({23currency,24setCurrency,25}),26[currency],27);2829return <PaymentContext.Provider value={ctx}>{children}</PaymentContext.Provider>;30};3132export { PaymentContext, PaymentContextProvider };3334export const useCurrency = () => {35return useContext(PaymentContext);36};373839