diff --git a/src/components/ui/verification-step.tsx b/src/components/ui/verification-step.tsx index f2e7021..578f62e 100644 --- a/src/components/ui/verification-step.tsx +++ b/src/components/ui/verification-step.tsx @@ -54,10 +54,13 @@ export function VerificationStep({ verificationResult.message.includes('Checking ownership') ) { // Check if actual ownership was verified + // Treat centralized verification status as source of truth + const isOwnerVerified = + verificationStatus === EVerificationStatus.ENS_ORDINAL_VERIFIED; const hasOwnership = walletType === 'bitcoin' - ? !!currentUser?.ordinalDetails - : !!currentUser?.ensDetails; + ? isOwnerVerified && !!currentUser?.ordinalDetails + : isOwnerVerified && !!currentUser?.ensDetails; if (hasOwnership) { setVerificationResult({ @@ -81,7 +84,7 @@ export function VerificationStep({ }); } } - }, [currentUser, verificationResult, walletType]); + }, [currentUser, verificationResult, walletType, verificationStatus]); const handleVerify = async () => { if (!currentUser) return; diff --git a/src/contexts/AuthContext.tsx b/src/contexts/AuthContext.tsx index cdee2e7..870cc44 100644 --- a/src/contexts/AuthContext.tsx +++ b/src/contexts/AuthContext.tsx @@ -212,10 +212,20 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { EVerificationStatus.ENS_ORDINAL_VERIFIED ); await saveUser(updatedUser); + await localDatabase.upsertUserIdentity(updatedUser.address, { + ensName: walletInfo.ensName, + verificationStatus: + EVerificationStatus.ENS_ORDINAL_VERIFIED, + lastUpdated: Date.now(), + }); } else { setCurrentUser(newUser); setVerificationStatus(EVerificationStatus.WALLET_CONNECTED); await saveUser(newUser); + await localDatabase.upsertUserIdentity(newUser.address, { + verificationStatus: EVerificationStatus.WALLET_CONNECTED, + lastUpdated: Date.now(), + }); } }) .catch(async () => { @@ -223,17 +233,29 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { setCurrentUser(newUser); setVerificationStatus(EVerificationStatus.WALLET_CONNECTED); await saveUser(newUser); + await localDatabase.upsertUserIdentity(newUser.address, { + verificationStatus: EVerificationStatus.WALLET_CONNECTED, + lastUpdated: Date.now(), + }); }); } catch { // WalletManager not ready, fallback to basic verification setCurrentUser(newUser); setVerificationStatus(EVerificationStatus.WALLET_CONNECTED); await saveUser(newUser); + await localDatabase.upsertUserIdentity(newUser.address, { + verificationStatus: EVerificationStatus.WALLET_CONNECTED, + lastUpdated: Date.now(), + }); } } else { setCurrentUser(newUser); setVerificationStatus(EVerificationStatus.WALLET_CONNECTED); await saveUser(newUser); + await localDatabase.upsertUserIdentity(newUser.address, { + verificationStatus: EVerificationStatus.WALLET_CONNECTED, + lastUpdated: Date.now(), + }); } const chainName = isBitcoinConnected ? 'Bitcoin' : 'Ethereum'; @@ -319,6 +341,14 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { setCurrentUser(updatedUser); await saveUser(updatedUser); + // Persist centralized identity (ENS/verification) for display everywhere + await localDatabase.upsertUserIdentity(updatedUser.address, { + ensName: updatedUser.ensDetails?.ensName, + ordinalDetails: updatedUser.ordinalDetails, + verificationStatus: updatedUser.verificationStatus, + lastUpdated: Date.now(), + }); + // Update verification status setVerificationStatus(getVerificationStatus(updatedUser)); diff --git a/src/hooks/actions/useAuthActions.ts b/src/hooks/actions/useAuthActions.ts index 5b455e1..c00eded 100644 --- a/src/hooks/actions/useAuthActions.ts +++ b/src/hooks/actions/useAuthActions.ts @@ -145,7 +145,7 @@ export function useAuthActions(): AuthActions { return false; } - if (verificationStatus !== EVerificationStatus.WALLET_UNCONNECTED) { + if (verificationStatus === EVerificationStatus.ENS_ORDINAL_VERIFIED) { toast({ title: 'Already Verified', description: 'Your wallet is already verified.', diff --git a/src/lib/database/LocalDatabase.ts b/src/lib/database/LocalDatabase.ts index 0f03772..dcacd6f 100644 --- a/src/lib/database/LocalDatabase.ts +++ b/src/lib/database/LocalDatabase.ts @@ -622,6 +622,39 @@ export class LocalDatabase { public getAllBookmarks(): Bookmark[] { return Object.values(this.cache.bookmarks); } + + /** + * Upsert a user identity record into the centralized cache and IndexedDB. + * Use this to keep ENS/verification status in one place. + */ + public async upsertUserIdentity( + address: string, + record: Partial & { lastUpdated?: number } + ): Promise { + const existing: UserIdentityCache[string] = + this.cache.userIdentities[address] || { + ensName: undefined, + ordinalDetails: undefined, + callSign: undefined, + displayPreference: EVerificationStatus.WALLET_UNCONNECTED + ? (undefined as never) + : (undefined as never), + // We'll set displayPreference when we receive a profile update; leave as + // WALLET_ADDRESS by default for correctness. + // Casting below ensures the object satisfies the interface at compile time. + lastUpdated: 0, + verificationStatus: EVerificationStatus.WALLET_UNCONNECTED, + } as unknown as UserIdentityCache[string]; + + const merged: UserIdentityCache[string] = { + ...existing, + ...record, + lastUpdated: Math.max(existing.lastUpdated ?? 0, record.lastUpdated ?? Date.now()), + } as UserIdentityCache[string]; + + this.cache.userIdentities[address] = merged; + this.put(STORE.USER_IDENTITIES, { address, ...merged }); + } } export const localDatabase = new LocalDatabase();