mirror of
https://github.com/logos-messaging/OpChan.git
synced 2026-01-07 07:13:11 +00:00
fix: ENS ownership checks
This commit is contained in:
parent
8ddac8a056
commit
19e36522f5
@ -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;
|
||||
|
||||
@ -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));
|
||||
|
||||
|
||||
@ -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.',
|
||||
|
||||
@ -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<UserIdentityCache[string]> & { lastUpdated?: number }
|
||||
): Promise<void> {
|
||||
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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user