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