@@ -3,6 +3,7 @@ import { SafeEventEmitter } from "@web3auth/auth";
33import { CHAIN_NAMESPACES , CONNECTOR_NAMESPACES , ConnectorNamespaceType , CustomChainConfig } from "../chain/IChainInterface" ;
44import { WalletInitializationError , WalletLoginError } from "../errors" ;
55import { WALLET_CONNECTOR_TYPE , WALLET_CONNECTORS } from "../wallet" ;
6+ import { CONNECTED_STATUSES } from "./connectorStatus" ;
67import { CONNECTOR_EVENTS , CONNECTOR_STATUS } from "./constants" ;
78import type {
89 BaseConnectorLoginParams ,
@@ -41,8 +42,12 @@ export abstract class BaseConnector<T> extends SafeEventEmitter<ConnectorEvents>
4142 this . coreOptions = options . coreOptions ;
4243 }
4344
44- get connnected ( ) : boolean {
45- return this . status === CONNECTOR_STATUS . CONNECTED ;
45+ get connected ( ) : boolean {
46+ return CONNECTED_STATUSES . includes ( this . status ) ;
47+ }
48+
49+ get canAuthorize ( ) : boolean {
50+ return ( [ CONNECTOR_STATUS . AUTHORIZING , CONNECTOR_STATUS . AUTHORIZED , CONNECTOR_STATUS . CONNECTED ] as CONNECTOR_STATUS_TYPE [ ] ) . includes ( this . status ) ;
4651 }
4752
4853 public abstract get provider ( ) : IProvider | null ;
@@ -53,7 +58,7 @@ export abstract class BaseConnector<T> extends SafeEventEmitter<ConnectorEvents>
5358 if ( this . name === WALLET_CONNECTORS . METAMASK && ! this . isInjected && this . status === CONNECTOR_STATUS . CONNECTING ) return ;
5459
5560 if ( this . status === CONNECTOR_STATUS . CONNECTING ) throw WalletInitializationError . notReady ( "Already connecting" ) ;
56- if ( this . status === CONNECTOR_STATUS . CONNECTED ) throw WalletLoginError . connectionError ( "Already connected" ) ;
61+ if ( this . connected ) throw WalletLoginError . connectionError ( "Already connected" ) ;
5762 if ( this . status !== CONNECTOR_STATUS . READY )
5863 throw WalletLoginError . connectionError (
5964 "Wallet connector is not ready yet, Please wait for init function to resolve before calling connect/connectTo function"
@@ -72,12 +77,12 @@ export abstract class BaseConnector<T> extends SafeEventEmitter<ConnectorEvents>
7277 if ( this . connectorNamespace !== CONNECTOR_NAMESPACES . MULTICHAIN && this . connectorNamespace !== chainConfig . chainNamespace )
7378 throw WalletInitializationError . invalidParams ( "Connector doesn't support this chain namespace" ) ;
7479 if ( this . status === CONNECTOR_STATUS . NOT_READY ) return ;
75- if ( this . status === CONNECTOR_STATUS . CONNECTED ) throw WalletInitializationError . notReady ( "Already connected" ) ;
80+ if ( this . connected ) throw WalletInitializationError . notReady ( "Already connected" ) ;
7681 if ( this . status === CONNECTOR_STATUS . READY ) throw WalletInitializationError . notReady ( "Connector is already initialized" ) ;
7782 }
7883
7984 checkDisconnectionRequirements ( ) : void {
80- if ( this . status !== CONNECTOR_STATUS . CONNECTED ) throw WalletLoginError . disconnectionError ( "Not connected with wallet" ) ;
85+ if ( ! this . connected ) throw WalletLoginError . disconnectionError ( "Not connected with wallet" ) ;
8186 }
8287
8388 checkSwitchChainRequirements ( params : { chainId : string } , init = false ) : void {
0 commit comments