mirror of
https://github.com/logos-messaging/OpChan.git
synced 2026-01-04 05:43:10 +00:00
chore: remove client prop
This commit is contained in:
parent
0385a267f5
commit
466f98b76b
@ -10,15 +10,11 @@ import { MessageService } from '../lib/services/MessageService';
|
||||
|
||||
export interface OpChanClientConfig {
|
||||
ordiscanApiKey: string;
|
||||
debug?: boolean;
|
||||
isDevelopment?: boolean;
|
||||
isProduction?: boolean;
|
||||
}
|
||||
|
||||
export class OpChanClient {
|
||||
readonly config: OpChanClientConfig;
|
||||
|
||||
// Exposed subsystems
|
||||
readonly messageManager: DefaultMessageManager = messageManager;
|
||||
readonly database: LocalDatabase = localDatabase;
|
||||
readonly forumActions = new ForumActions();
|
||||
@ -32,8 +28,7 @@ export class OpChanClient {
|
||||
this.config = config;
|
||||
|
||||
const env: EnvironmentConfig = {
|
||||
isDevelopment: config.isDevelopment ?? config.debug ?? false,
|
||||
isProduction: config.isProduction ?? !config.debug,
|
||||
|
||||
apiKeys: {
|
||||
ordiscan: config.ordiscanApiKey,
|
||||
},
|
||||
|
||||
@ -4,31 +4,19 @@
|
||||
*/
|
||||
|
||||
export interface EnvironmentConfig {
|
||||
isDevelopment?: boolean;
|
||||
isProduction?: boolean;
|
||||
apiKeys?: {
|
||||
ordiscan?: string;
|
||||
};
|
||||
}
|
||||
|
||||
class Environment {
|
||||
class Environment {
|
||||
private config: EnvironmentConfig = {
|
||||
isDevelopment: false,
|
||||
isProduction: true,
|
||||
};
|
||||
|
||||
public configure(config: EnvironmentConfig): void {
|
||||
this.config = { ...this.config, ...config };
|
||||
}
|
||||
|
||||
public get isDev(): boolean {
|
||||
return this.config.isDevelopment || false;
|
||||
}
|
||||
|
||||
public get isProduction(): boolean {
|
||||
return this.config.isProduction ?? true;
|
||||
}
|
||||
|
||||
public get ordiscanApiKey(): string | undefined {
|
||||
return this.config.apiKeys?.ordiscan;
|
||||
}
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
||||
import { User, EVerificationStatus, OpChanClient, EDisplayPreference } from '@opchan/core';
|
||||
import { walletManager, delegationManager, messageManager, LocalDatabase, localDatabase, WalletManager } from '@opchan/core';
|
||||
import { User, EVerificationStatus, EDisplayPreference } from '@opchan/core';
|
||||
import { delegationManager, type messageManager, localDatabase } from '@opchan/core';
|
||||
import { DelegationDuration } from '@opchan/core';
|
||||
import { useAppKitAccount } from '@reown/appkit/react';
|
||||
import { useClient } from './ClientContext';
|
||||
|
||||
export interface AuthContextValue {
|
||||
currentUser: User | null;
|
||||
@ -24,10 +25,8 @@ export interface AuthContextValue {
|
||||
|
||||
const AuthContext = createContext<AuthContextValue | null>(null);
|
||||
|
||||
export const AuthProvider: React.FC<{
|
||||
client: OpChanClient;
|
||||
children: React.ReactNode
|
||||
}> = ({ client, children }) => {
|
||||
export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
const client = useClient();
|
||||
const [currentUser, setCurrentUser] = useState<User | null>(null);
|
||||
const [isAuthenticating, setIsAuthenticating] = useState(false);
|
||||
|
||||
@ -78,7 +77,7 @@ export const AuthProvider: React.FC<{
|
||||
await localDatabase.storeUser(updatedUser);
|
||||
return false;
|
||||
}
|
||||
}, [client.userIdentityService, currentUser]);
|
||||
}, [client, currentUser]);
|
||||
|
||||
// Hydrate user from LocalDatabase on mount
|
||||
useEffect(() => {
|
||||
@ -307,10 +306,10 @@ export const AuthProvider: React.FC<{
|
||||
delegateKey,
|
||||
getDelegationStatus,
|
||||
clearDelegation,
|
||||
signMessage: messageManager.sendMessage.bind(messageManager),
|
||||
signMessage: client.messageManager.sendMessage.bind(client.messageManager),
|
||||
verifyMessage,
|
||||
};
|
||||
}, [currentUser, isAuthenticating, connectWallet, disconnectWallet, verifyOwnership, delegateKey, getDelegationStatus, clearDelegation, verifyMessage]);
|
||||
}, [client, currentUser, isAuthenticating, connectWallet, disconnectWallet, verifyOwnership, delegateKey, getDelegationStatus, clearDelegation, verifyMessage]);
|
||||
|
||||
return <AuthContext.Provider value={ctx}>{children}</AuthContext.Provider>;
|
||||
};
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
||||
import { localDatabase, ForumActions, OpChanClient, getDataFromCache } from '@opchan/core';
|
||||
import { transformCell, transformPost, transformComment } from '@opchan/core';
|
||||
import { localDatabase, getDataFromCache } from '@opchan/core';
|
||||
import { useAuth } from './AuthContext';
|
||||
import { Cell, Post, Comment, UserVerificationStatus, EVerificationStatus } from '@opchan/core';
|
||||
import { useClient } from './ClientContext';
|
||||
import type { ForumActions } from '@opchan/core';
|
||||
|
||||
export interface ForumContextValue {
|
||||
cells: Cell[];
|
||||
@ -24,10 +25,8 @@ export interface ForumContextValue {
|
||||
|
||||
const ForumContext = createContext<ForumContextValue | null>(null);
|
||||
|
||||
export const ForumProvider: React.FC<{
|
||||
client: OpChanClient;
|
||||
children: React.ReactNode
|
||||
}> = ({ client, children }) => {
|
||||
export const ForumProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
const client = useClient();
|
||||
const { currentUser } = useAuth();
|
||||
const [cells, setCells] = useState<Cell[]>([]);
|
||||
const [posts, setPosts] = useState<Post[]>([]);
|
||||
@ -38,7 +37,7 @@ export const ForumProvider: React.FC<{
|
||||
const [isNetworkConnected, setIsNetworkConnected] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const actions = useMemo(() => new ForumActions(), []);
|
||||
const actions = useMemo(() => client.forumActions, [client]);
|
||||
|
||||
const updateFromCache = useCallback(async () => {
|
||||
try {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { OpChanClient } from '@opchan/core';
|
||||
import { localDatabase, messageManager } from '@opchan/core';
|
||||
import { localDatabase } from '@opchan/core';
|
||||
import { ClientProvider } from '../contexts/ClientContext';
|
||||
import { AuthProvider } from '../contexts/AuthContext';
|
||||
import { ForumProvider } from '../contexts/ForumContext';
|
||||
@ -30,8 +30,6 @@ export const OpChanProvider: React.FC<OpChanProviderProps> = ({
|
||||
// Configure environment and create client
|
||||
const client = new OpChanClient({
|
||||
ordiscanApiKey,
|
||||
debug: !!debug,
|
||||
isDevelopment: !!debug,
|
||||
});
|
||||
clientRef.current = client;
|
||||
|
||||
@ -59,9 +57,9 @@ export const OpChanProvider: React.FC<OpChanProviderProps> = ({
|
||||
return (
|
||||
<ClientProvider client={clientRef.current}>
|
||||
<IdentityProvider client={clientRef.current}>
|
||||
<AuthProvider client={clientRef.current}>
|
||||
<AuthProvider>
|
||||
<ModerationProvider>
|
||||
<ForumProvider client={clientRef.current}>{children}</ForumProvider>
|
||||
<ForumProvider>{children}</ForumProvider>
|
||||
</ModerationProvider>
|
||||
</AuthProvider>
|
||||
</IdentityProvider>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user