From 1d86a43406fdeff30abdd564f0b64585843d8472 Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Fri, 19 Sep 2025 13:44:11 +0530 Subject: [PATCH] fix: non-ens wallets engagement, syncing hydration --- app/src/components/CreateCellDialog.tsx | 2 +- app/src/components/PostDetail.tsx | 2 +- app/src/components/PostList.tsx | 8 ++-- app/src/pages/FeedPage.tsx | 2 +- packages/core/src/lib/forum/ForumActions.ts | 12 +++--- .../src/lib/waku/services/MessageService.ts | 1 + packages/react/src/contexts/AuthContext.tsx | 42 +++++++++++++++++++ packages/react/src/contexts/ForumContext.tsx | 8 ++++ packages/react/src/hooks/useForum.ts | 22 +++++----- 9 files changed, 75 insertions(+), 24 deletions(-) diff --git a/app/src/components/CreateCellDialog.tsx b/app/src/components/CreateCellDialog.tsx index 7b3641c..429e615 100644 --- a/app/src/components/CreateCellDialog.tsx +++ b/app/src/components/CreateCellDialog.tsx @@ -81,7 +81,7 @@ export function CreateCellDialog({ if (!canCreateCell) { toast({ title: 'Permission Denied', - description: 'You need to verify Ordinal ownership to create cells.', + description: 'Only verified ENS or Logos Ordinal owners can create cells.', variant: 'destructive', }); return; diff --git a/app/src/components/PostDetail.tsx b/app/src/components/PostDetail.tsx index 8e8e990..e997259 100644 --- a/app/src/components/PostDetail.tsx +++ b/app/src/components/PostDetail.tsx @@ -297,7 +297,7 @@ const PostDetail = () => { {!permissions.canComment && (

- Connect wallet and verify Ordinal ownership to comment + Connect your wallet to comment

) : ( @@ -273,7 +273,7 @@ const PostList = () => { onClick={() => handleVotePost(post.id, true)} disabled={!canVote || isVoting} title={ - canVote ? 'Upvote' : 'Connect wallet and verify to vote' + canVote ? 'Upvote' : 'Connect your wallet to vote' } > @@ -286,7 +286,7 @@ const PostList = () => { onClick={() => handleVotePost(post.id, false)} disabled={!canVote || isVoting} title={ - canVote ? 'Downvote' : 'Connect wallet and verify to vote' + canVote ? 'Downvote' : 'Connect your wallet to vote' } > diff --git a/app/src/pages/FeedPage.tsx b/app/src/pages/FeedPage.tsx index ae1d336..0c4fed8 100644 --- a/app/src/pages/FeedPage.tsx +++ b/app/src/pages/FeedPage.tsx @@ -167,7 +167,7 @@ const FeedPage: React.FC = () => { {verificationStatus !== EVerificationStatus.ENS_ORDINAL_VERIFIED && (

- Connect your wallet and verify Ordinal ownership to + Connect your wallet to start posting

)} diff --git a/packages/core/src/lib/forum/ForumActions.ts b/packages/core/src/lib/forum/ForumActions.ts index c33d35b..254fabf 100644 --- a/packages/core/src/lib/forum/ForumActions.ts +++ b/packages/core/src/lib/forum/ForumActions.ts @@ -363,7 +363,7 @@ export class ForumActions { return { success: false, error: - 'Authentication required. You need to verify Ordinal ownership to moderate posts.', + 'Authentication required. Connect your wallet to moderate posts.', }; } if (currentUser.address !== cellOwner) { @@ -437,7 +437,7 @@ export class ForumActions { return { success: false, error: - 'Authentication required. You need to verify Ordinal ownership to moderate comments.', + 'Authentication required. Connect your wallet to moderate comments.', }; } if (currentUser.address !== cellOwner) { @@ -511,7 +511,7 @@ export class ForumActions { return { success: false, error: - 'Authentication required. You need to verify Ordinal ownership to moderate users.', + 'Authentication required. Connect your wallet to moderate users.', }; } if (currentUser.address !== cellOwner) { @@ -579,7 +579,7 @@ export class ForumActions { return { success: false, error: - 'Authentication required. You need to verify Ordinal ownership to unmoderate posts.', + 'Authentication required. Connect your wallet to unmoderate posts.', }; } if (currentUser.address !== cellOwner) { @@ -653,7 +653,7 @@ export class ForumActions { return { success: false, error: - 'Authentication required. You need to verify Ordinal ownership to unmoderate comments.', + 'Authentication required. Connect your wallet to unmoderate comments.', }; } if (currentUser.address !== cellOwner) { @@ -727,7 +727,7 @@ export class ForumActions { return { success: false, error: - 'Authentication required. You need to verify Ordinal ownership to unmoderate users.', + 'Authentication required. Connect your wallet to unmoderate users.', }; } if (currentUser.address !== cellOwner) { diff --git a/packages/core/src/lib/waku/services/MessageService.ts b/packages/core/src/lib/waku/services/MessageService.ts index 4db7d5f..51aa58d 100644 --- a/packages/core/src/lib/waku/services/MessageService.ts +++ b/packages/core/src/lib/waku/services/MessageService.ts @@ -55,6 +55,7 @@ export class MessageService { onSent: id => { console.log(`Message ${id} sent`); statusCallback?.onSent?.(id); + try { localDatabase.clearPending(message.id); } catch {} }, onAcknowledged: id => { console.log(`Message ${id} acknowledged`); diff --git a/packages/react/src/contexts/AuthContext.tsx b/packages/react/src/contexts/AuthContext.tsx index 05d4733..eac52a7 100644 --- a/packages/react/src/contexts/AuthContext.tsx +++ b/packages/react/src/contexts/AuthContext.tsx @@ -173,6 +173,48 @@ export const AuthProvider: React.FC<{ autoConnect(); }, [isWalletConnected, connectedAddress, walletType]); // Remove currentUser and verifyOwnership dependencies + // Ensure verificationStatus reflects a connected wallet even if a user was preloaded + useEffect(() => { + const syncConnectedStatus = async () => { + if (!isWalletConnected || !connectedAddress || !currentUser) return; + + const needsAddressSync = + currentUser.address !== connectedAddress || + currentUser.walletType !== (walletType as 'bitcoin' | 'ethereum'); + + const needsStatusUpgrade = + currentUser.verificationStatus === EVerificationStatus.WALLET_UNCONNECTED; + + if (needsAddressSync || needsStatusUpgrade) { + const nextStatus = + currentUser.verificationStatus === + EVerificationStatus.ENS_ORDINAL_VERIFIED + ? EVerificationStatus.ENS_ORDINAL_VERIFIED + : EVerificationStatus.WALLET_CONNECTED; + + const updatedUser: User = { + ...currentUser, + address: connectedAddress, + walletType: walletType as 'bitcoin' | 'ethereum', + verificationStatus: nextStatus, + lastChecked: Date.now(), + } as User; + + setCurrentUser(updatedUser); + await localDatabase.storeUser(updatedUser); + await localDatabase.upsertUserIdentity(connectedAddress, { + ensName: updatedUser.ensDetails?.ensName, + ordinalDetails: updatedUser.ordinalDetails, + verificationStatus: nextStatus, + lastUpdated: Date.now(), + }); + } + }; + + syncConnectedStatus(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [isWalletConnected, connectedAddress, walletType, currentUser]); + const connectWallet = useCallback(async (): Promise => { if (!isWalletConnected || !connectedAddress) return false; diff --git a/packages/react/src/contexts/ForumContext.tsx b/packages/react/src/contexts/ForumContext.tsx index 22d77d7..b86f306 100644 --- a/packages/react/src/contexts/ForumContext.tsx +++ b/packages/react/src/contexts/ForumContext.tsx @@ -131,6 +131,14 @@ export const ForumProvider: React.FC<{ }; }, [client, updateFromCache]); + // 2b) Pending state wiring – rehydrate when local pending queue changes + useEffect(() => { + const off = localDatabase.onPendingChange(async () => { + try { await updateFromCache(); } catch {} + }); + return () => { try { off && off(); } catch {} }; + }, [updateFromCache]); + // 3) Visibility change: re-check connection immediately when tab becomes active useEffect(() => { const handleVisibility = async () => { diff --git a/packages/react/src/hooks/useForum.ts b/packages/react/src/hooks/useForum.ts index 8f3985a..5cdd6a8 100644 --- a/packages/react/src/hooks/useForum.ts +++ b/packages/react/src/hooks/useForum.ts @@ -394,7 +394,7 @@ export function useForumApi(): UseForumApi { currentUser, isAuthenticated: !!currentUser, }, - async () => {} // updateStateFromCache handled by ForumProvider + async () => { await refreshData(); } ); return result.data || null; } catch { @@ -403,7 +403,7 @@ export function useForumApi(): UseForumApi { }, createPost: async (input: { cellId: string; title: string; content: string }) => { if (!permissions.canPost) { - throw new Error('You need to verify Ordinal ownership to create posts.'); + throw new Error('Connect your wallet to create posts.'); } if (!input.title.trim() || !input.content.trim()) { throw new Error('Please provide both a title and content for the post.'); @@ -417,7 +417,7 @@ export function useForumApi(): UseForumApi { currentUser, isAuthenticated: !!currentUser, }, - async () => {} + async () => { await refreshData(); } ); return result.data || null; } catch { @@ -439,7 +439,7 @@ export function useForumApi(): UseForumApi { currentUser, isAuthenticated: !!currentUser, }, - async () => {} + async () => { await refreshData(); } ); return result.data || null; } catch { @@ -460,7 +460,7 @@ export function useForumApi(): UseForumApi { currentUser, isAuthenticated: !!currentUser, }, - async () => {} + async () => { await refreshData(); } ); return result.success; } catch { @@ -472,7 +472,7 @@ export function useForumApi(): UseForumApi { try { const result = await client.forumActions.moderatePost( { cellId, postId, reason, currentUser, isAuthenticated: !!currentUser, cellOwner: currentUser?.address || '' }, - async () => {} + async () => { await refreshData(); } ); return result.success; } catch { return false; } @@ -481,7 +481,7 @@ export function useForumApi(): UseForumApi { try { const result = await client.forumActions.unmoderatePost( { cellId, postId, reason, currentUser, isAuthenticated: !!currentUser, cellOwner: currentUser?.address || '' }, - async () => {} + async () => { await refreshData(); } ); return result.success; } catch { return false; } @@ -490,7 +490,7 @@ export function useForumApi(): UseForumApi { try { const result = await client.forumActions.moderateComment( { cellId, commentId, reason, currentUser, isAuthenticated: !!currentUser, cellOwner: currentUser?.address || '' }, - async () => {} + async () => { await refreshData(); } ); return result.success; } catch { return false; } @@ -499,7 +499,7 @@ export function useForumApi(): UseForumApi { try { const result = await client.forumActions.unmoderateComment( { cellId, commentId, reason, currentUser, isAuthenticated: !!currentUser, cellOwner: currentUser?.address || '' }, - async () => {} + async () => { await refreshData(); } ); return result.success; } catch { return false; } @@ -508,7 +508,7 @@ export function useForumApi(): UseForumApi { try { const result = await client.forumActions.moderateUser( { cellId, userAddress, reason, currentUser, isAuthenticated: !!currentUser, cellOwner: currentUser?.address || '' }, - async () => {} + async () => { await refreshData(); } ); return result.success; } catch { return false; } @@ -517,7 +517,7 @@ export function useForumApi(): UseForumApi { try { const result = await client.forumActions.unmoderateUser( { cellId, userAddress, reason, currentUser, isAuthenticated: !!currentUser, cellOwner: currentUser?.address || '' }, - async () => {} + async () => { await refreshData(); } ); return result.success; } catch { return false; }