Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/payment-context.tsx
2498 views
1
/**
2
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import React, { createContext, useContext, useMemo, useState } from "react";
8
9
export type Currency = "USD" | "EUR";
10
11
const PaymentContext = createContext<{
12
currency: Currency;
13
setCurrency: React.Dispatch<Currency>;
14
}>({
15
currency: "USD",
16
setCurrency: () => null,
17
});
18
19
const PaymentContextProvider: React.FC = ({ children }) => {
20
const [currency, setCurrency] = useState<Currency>("USD");
21
22
const ctx = useMemo(
23
() => ({
24
currency,
25
setCurrency,
26
}),
27
[currency],
28
);
29
30
return <PaymentContext.Provider value={ctx}>{children}</PaymentContext.Provider>;
31
};
32
33
export { PaymentContext, PaymentContextProvider };
34
35
export const useCurrency = () => {
36
return useContext(PaymentContext);
37
};
38
39