on 4c8c607 help sign in
bridge/src/store/hosting.js
37 lines 1.1 kB history raw
1import React, { createContext, useContext, forwardRef } from 'react';
3import useHostingStore from './lib/useHostingStore';
5import { NETWORK_TYPES } from '../lib/network';
7import { useNetwork } from 'store/network';
9export const HostingContext = createContext(null);
11const HOSTING_DETAILS = {
12 DEV: { url: '', domain: 'liam.tlon.network', disabled: true },
13 MAINNET: { url: '', domain: '', disabled: true },
14};
16export function HostingProvider({ children }) {
17 const { networkType } = useNetwork();
18 const { url, domain, disabled } =
19 networkType === NETWORK_TYPES.MAINNET
20 ? HOSTING_DETAILS.MAINNET
21 : HOSTING_DETAILS.DEV;
22 const store = useHostingStore(url, domain, disabled);
23 return (
24 <HostingContext.Provider value={store}>{children}</HostingContext.Provider>
25 );
28export function useHosting() {
29 return useContext(HostingContext);
32export const withHosting = Component =>
33 forwardRef((props, ref) => (
34 <HostingContext.Consumer>
35 {store => <Component ref={ref} {...store} {...props} />}
36 </HostingContext.Consumer>
37 ));