mirror of
https://github.com/logos-messaging/OpChan.git
synced 2026-01-07 07:13:11 +00:00
fix: ens
This commit is contained in:
parent
539c596974
commit
c0497610c3
@ -31,6 +31,7 @@ import { AppKitProvider } from "@reown/appkit/react";
|
|||||||
// Create a client
|
// Create a client
|
||||||
const queryClient = new QueryClient();
|
const queryClient = new QueryClient();
|
||||||
|
|
||||||
|
|
||||||
const App = () => (
|
const App = () => (
|
||||||
<WagmiProvider config={config}>
|
<WagmiProvider config={config}>
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
|
|||||||
@ -104,10 +104,15 @@ export class AuthService {
|
|||||||
|
|
||||||
// Add ENS info for Ethereum wallets (if available)
|
// Add ENS info for Ethereum wallets (if available)
|
||||||
if (walletType === 'ethereum') {
|
if (walletType === 'ethereum') {
|
||||||
// Note: ENS resolution would need to be implemented separately
|
try {
|
||||||
// For now, we'll leave it as undefined
|
const walletInfo = await this.walletService.getWalletInfo();
|
||||||
user.ensName = undefined;
|
user.ensName = walletInfo?.ensName;
|
||||||
user.ensOwnership = false;
|
user.ensOwnership = !!(walletInfo?.ensName);
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to resolve ENS during wallet connection:', error);
|
||||||
|
user.ensName = undefined;
|
||||||
|
user.ensOwnership = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -190,21 +195,40 @@ export class AuthService {
|
|||||||
* Verify Ethereum ENS ownership
|
* Verify Ethereum ENS ownership
|
||||||
*/
|
*/
|
||||||
private async verifyEthereumENS(user: User): Promise<AuthResult> {
|
private async verifyEthereumENS(user: User): Promise<AuthResult> {
|
||||||
// Note: ENS resolution would need to be implemented separately
|
try {
|
||||||
// For now, we'll assume no ENS ownership
|
// Get wallet info with ENS resolution
|
||||||
const hasENS = false;
|
const walletInfo = await this.walletService.getWalletInfo();
|
||||||
|
|
||||||
|
const hasENS = !!(walletInfo?.ensName);
|
||||||
|
const ensName = walletInfo?.ensName;
|
||||||
|
|
||||||
const updatedUser = {
|
const updatedUser = {
|
||||||
...user,
|
...user,
|
||||||
ensOwnership: hasENS,
|
ensOwnership: hasENS,
|
||||||
ensName: undefined,
|
ensName: ensName,
|
||||||
lastChecked: Date.now(),
|
lastChecked: Date.now(),
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
user: updatedUser
|
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
|
* Get current wallet info
|
||||||
*/
|
*/
|
||||||
async getWalletInfo() {
|
async getWalletInfo() {
|
||||||
// Return basic wallet info based on what's available
|
// Use the wallet service to get detailed wallet info including ENS
|
||||||
const isBitcoinConnected = this.walletService.isWalletAvailable('bitcoin');
|
return await this.walletService.getWalletInfo();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,9 +1,18 @@
|
|||||||
import { UseAppKitAccountReturn } from '@reown/appkit/react';
|
import { UseAppKitAccountReturn } from '@reown/appkit/react';
|
||||||
import { KeyDelegation } from '../signatures/key-delegation';
|
import { KeyDelegation } from '../signatures/key-delegation';
|
||||||
import { AppKit } from '@reown/appkit';
|
import { AppKit } from '@reown/appkit';
|
||||||
|
import { getEnsName } from '@wagmi/core';
|
||||||
import { ChainNamespace } from '@reown/appkit-common';
|
import { ChainNamespace } from '@reown/appkit-common';
|
||||||
|
import { config } from './appkit';
|
||||||
import { Provider} from '@reown/appkit-controllers';
|
import { Provider} from '@reown/appkit-controllers';
|
||||||
|
|
||||||
|
export interface WalletInfo {
|
||||||
|
address: string;
|
||||||
|
walletType: 'bitcoin' | 'ethereum';
|
||||||
|
ensName?: string;
|
||||||
|
isConnected: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export class ReOwnWalletService {
|
export class ReOwnWalletService {
|
||||||
private keyDelegation: KeyDelegation;
|
private keyDelegation: KeyDelegation;
|
||||||
private bitcoinAccount?: UseAppKitAccountReturn;
|
private bitcoinAccount?: UseAppKitAccountReturn;
|
||||||
@ -207,4 +216,40 @@ export class ReOwnWalletService {
|
|||||||
clearDelegation(walletType: 'bitcoin' | 'ethereum'): void {
|
clearDelegation(walletType: 'bitcoin' | 'ethereum'): void {
|
||||||
this.keyDelegation.clearDelegation();
|
this.keyDelegation.clearDelegation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get wallet connection info with ENS resolution for Ethereum
|
||||||
|
*/
|
||||||
|
async getWalletInfo(): Promise<WalletInfo | null> {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user