@@ -24,6 +24,7 @@ import {
2424 initializeEthereumProviders ,
2525} from "./ethereumProviders" ;
2626import { EIP1193Provider } from "mipd" ;
27+ import { createPath } from "react-router-dom" ;
2728
2829export interface EthereumWalletAuthCredentials extends AuthCredentials {
2930 inviteCode ?: string ;
@@ -240,11 +241,17 @@ export class EthereumWalletAuthProvider implements AuthProvider<EthereumWalletAu
240241 indexerService : IndexerService ,
241242 onError ?: WalletErrorCallback
242243 ) {
243- const accountInfo = await indexerService . getAccountInfo ( username ) ;
244- if ( accountInfo ) {
245- const error = `Account with username "${ username } " already exists.` ;
246- onError ?.( new Error ( error ) ) ;
247- throw new Error ( error ) ;
244+ try {
245+ const accountInfo = await indexerService . getAccountInfo ( username ) ;
246+ if ( accountInfo ) {
247+ const error = `Account with username "${ username } " already exists.` ;
248+ onError ?.( new Error ( error ) ) ;
249+ throw new Error ( error ) ;
250+ }
251+ } catch ( error : any ) {
252+ // Any failure from the indexer means the account is not registered yet.
253+ // We ignore 404 and network errors to allow registration to proceed.
254+ return ;
248255 }
249256
250257 if ( ! inviteCode ) {
@@ -266,12 +273,6 @@ export class EthereumWalletAuthProvider implements AuthProvider<EthereumWalletAu
266273
267274 const identity = `${ username } @${ walletContractName } ` ;
268275
269- onWalletEvent ?.( {
270- account : identity ,
271- type : "checking_password" ,
272- message : "Requesting Ethereum wallet signature…" ,
273- } ) ;
274-
275276 const indexerService = IndexerService . getInstance ( ) ;
276277 const accountInfo = await indexerService . getAccountInfo ( username ) ;
277278 if ( ! ( "Ethereum" in accountInfo . auth_method ) ) {
@@ -281,30 +282,28 @@ export class EthereumWalletAuthProvider implements AuthProvider<EthereumWalletAu
281282 const storedAddress = this . normalizeEthereumAddress (
282283 `${ accountInfo . auth_method . Ethereum . address ?? "" } ` ,
283284 ) ;
285+
286+ const ethereum = this . getEthereum ( credentials . providerId ) ;
287+ const ethAddr = await this . getPrimaryAccount ( ethereum ) ;
288+
289+ const walletAddress = this . normalizeEthereumAddress ( ethAddr [ 0 ] ) ;
290+
291+ if ( walletAddress !== storedAddress ) {
292+ // onError?.(new Error("Ethereum account does not match registered wallet address"));
293+ return { success : false , error : "Ethereum account does not match registered wallet address" } ;
294+ }
295+
284296 const nonce = Date . now ( ) ;
285297 const message = this . buildSigningMessage ( identity , nonce ) ;
286298
287- let ethAddr : string [ ] ;
299+ // let ethAddr: string[];
288300 let signature : string ;
289301 try {
290302 const result = await this . signWithEthereumWallet ( message , credentials . providerId ) ;
291- ethAddr = result . ethAddr ;
292303 signature = result . signature ;
293304 } catch ( error : any ) {
294- // Handle wallet specific errors
295- if ( error . code === 4001 ) {
296- return { success : false , error : "Wallet signature request was rejected by user" } ;
297- }
298- if ( error . message . includes ( "User rejected" ) || error . message . includes ( "User denied" ) ) {
299- return { success : false , error : "Wallet signature request was rejected by user" } ;
300- }
301- throw error ; // Re-throw other errors
302- }
303-
304- const walletAddress = this . normalizeEthereumAddress ( ethAddr [ 0 ] ) ;
305-
306- if ( walletAddress !== storedAddress ) {
307- return { success : false , error : "Ethereum account does not match registered wallet address" } ;
305+ // onError?.(new Error("Wallet signature request was rejected by user: " + (error.message || error)));
306+ return { success : false , error : "Wallet signature request was rejected by user" } ;
308307 }
309308
310309 const digest = this . buildEthereumMessageDigest ( message ) ;
@@ -444,14 +443,7 @@ export class EthereumWalletAuthProvider implements AuthProvider<EthereumWalletAu
444443 ethAddr = result . ethAddr ;
445444 signature = result . signature ;
446445 } catch ( error : any ) {
447- // Handle wallet specific errors
448- if ( error . code === 4001 ) {
449- return { success : false , error : "Wallet signature request was rejected by user" } ;
450- }
451- if ( error . message . includes ( "User rejected" ) || error . message . includes ( "User denied" ) ) {
452- return { success : false , error : "Wallet signature request was rejected by user" } ;
453- }
454- throw error ; // Re-throw other errors
446+ return { success : false , error : "Wallet signature request was rejected by user" } ;
455447 }
456448
457449 const walletAddress = this . normalizeEthereumAddress ( ethAddr [ 0 ] ) ;
@@ -461,7 +453,7 @@ export class EthereumWalletAuthProvider implements AuthProvider<EthereumWalletAu
461453 this . buildSecp256k1SignatureComponents ( digest , signature ) ;
462454
463455 if ( recoveredAddress !== walletAddress ) {
464- throw new Error ( "Recovered public key does not match wallet address" ) ;
456+ return { success : false , error : "Recovered public key does not match wallet address" } ;
465457 }
466458 let inviteCodeBlob ;
467459 try {
0 commit comments