diff --git a/src/App.tsx b/src/App.tsx index f603341..2070ab8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -31,6 +31,7 @@ import { AppKitProvider } from "@reown/appkit/react"; // Create a client const queryClient = new QueryClient(); + const App = () => ( diff --git a/src/lib/identity/services/AuthService.ts b/src/lib/identity/services/AuthService.ts index c2a1c74..c417efb 100644 --- a/src/lib/identity/services/AuthService.ts +++ b/src/lib/identity/services/AuthService.ts @@ -104,10 +104,15 @@ export class AuthService { // Add ENS info for Ethereum wallets (if available) if (walletType === 'ethereum') { - // Note: ENS resolution would need to be implemented separately - // For now, we'll leave it as undefined - user.ensName = undefined; - user.ensOwnership = false; + try { + const walletInfo = await this.walletService.getWalletInfo(); + user.ensName = walletInfo?.ensName; + user.ensOwnership = !!(walletInfo?.ensName); + } catch (error) { + console.warn('Failed to resolve ENS during wallet connection:', error); + user.ensName = undefined; + user.ensOwnership = false; + } } return { @@ -190,21 +195,40 @@ export class AuthService { * Verify Ethereum ENS ownership */ private async verifyEthereumENS(user: User): Promise { - // Note: ENS resolution would need to be implemented separately - // For now, we'll assume no ENS ownership - const hasENS = false; + try { + // Get wallet info with ENS resolution + const walletInfo = await this.walletService.getWalletInfo(); + + const hasENS = !!(walletInfo?.ensName); + const ensName = walletInfo?.ensName; - const updatedUser = { - ...user, - ensOwnership: hasENS, - ensName: undefined, - lastChecked: Date.now(), - }; + const updatedUser = { + ...user, + ensOwnership: hasENS, + ensName: ensName, + lastChecked: Date.now(), + }; - return { - success: true, - user: updatedUser - }; + return { + success: true, + user: updatedUser + }; + } catch (error) { + console.error('Error verifying ENS ownership:', error); + + // Fall back to no ENS ownership on error + const updatedUser = { + ...user, + ensOwnership: false, + ensName: undefined, + lastChecked: Date.now(), + }; + + return { + success: true, + user: updatedUser + }; + } } /** @@ -298,25 +322,8 @@ export class AuthService { * Get current wallet info */ async getWalletInfo() { - // Return basic wallet info based on what's available - const isBitcoinConnected = this.walletService.isWalletAvailable('bitcoin'); - const isEthereumConnected = this.walletService.isWalletAvailable('ethereum'); - - if (isBitcoinConnected) { - return { - address: this.getActiveAddress(), - walletType: 'bitcoin' as const, - isConnected: true - }; - } else if (isEthereumConnected) { - return { - address: this.getActiveAddress(), - walletType: 'ethereum' as const, - isConnected: true - }; - } - - return null; + // Use the wallet service to get detailed wallet info including ENS + return await this.walletService.getWalletInfo(); } /** diff --git a/src/lib/identity/wallets/ReOwnWalletService.ts b/src/lib/identity/wallets/ReOwnWalletService.ts index e206c17..6b5e4bd 100644 --- a/src/lib/identity/wallets/ReOwnWalletService.ts +++ b/src/lib/identity/wallets/ReOwnWalletService.ts @@ -1,9 +1,18 @@ import { UseAppKitAccountReturn } from '@reown/appkit/react'; import { KeyDelegation } from '../signatures/key-delegation'; import { AppKit } from '@reown/appkit'; +import { getEnsName } from '@wagmi/core'; import { ChainNamespace } from '@reown/appkit-common'; +import { config } from './appkit'; import { Provider} from '@reown/appkit-controllers'; +export interface WalletInfo { + address: string; + walletType: 'bitcoin' | 'ethereum'; + ensName?: string; + isConnected: boolean; +} + export class ReOwnWalletService { private keyDelegation: KeyDelegation; private bitcoinAccount?: UseAppKitAccountReturn; @@ -207,4 +216,40 @@ export class ReOwnWalletService { clearDelegation(walletType: 'bitcoin' | 'ethereum'): void { this.keyDelegation.clearDelegation(); } + + /** + * Get wallet connection info with ENS resolution for Ethereum + */ + async getWalletInfo(): Promise { + if (this.bitcoinAccount?.isConnected) { + return { + address: this.bitcoinAccount.address, + walletType: 'bitcoin', + isConnected: true + }; + } else if (this.ethereumAccount?.isConnected) { + // Use Wagmi to resolve ENS name + let ensName: string | undefined; + try { + const resolvedName = await getEnsName(config, { + address: this.ethereumAccount.address as `0x${string}` + }); + ensName = resolvedName || undefined; + } catch (error) { + console.warn('Failed to resolve ENS name:', error); + // Continue without ENS name + } + + return { + address: this.ethereumAccount.address, + walletType: 'ethereum', + ensName, + isConnected: true + }; + } + + return null; + } + + } \ No newline at end of file