Skip to content

Commit 1de748e

Browse files
can authorize status and logs for nomodal
1 parent 835c309 commit 1de748e

File tree

23 files changed

+50
-24
lines changed

23 files changed

+50
-24
lines changed

packages/no-modal/src/base/connector/baseConnector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { SafeEventEmitter } from "@web3auth/auth";
33
import { CHAIN_NAMESPACES, CONNECTOR_NAMESPACES, ConnectorNamespaceType, CustomChainConfig } from "../chain/IChainInterface";
44
import { WalletInitializationError, WalletLoginError } from "../errors";
55
import { WALLET_CONNECTOR_TYPE, WALLET_CONNECTORS } from "../wallet";
6-
import { CONNECTED_STATUSES } from "./connectorStatus";
6+
import { CAN_AUTHORIZE_STATUSES, CONNECTED_STATUSES } from "./connectorStatus";
77
import { CONNECTOR_EVENTS, CONNECTOR_STATUS } from "./constants";
88
import type {
99
BaseConnectorLoginParams,
@@ -47,7 +47,7 @@ export abstract class BaseConnector<T> extends SafeEventEmitter<ConnectorEvents>
4747
}
4848

4949
get canAuthorize(): boolean {
50-
return ([CONNECTOR_STATUS.AUTHORIZING, CONNECTOR_STATUS.AUTHORIZED, CONNECTOR_STATUS.CONNECTED] as CONNECTOR_STATUS_TYPE[]).includes(this.status);
50+
return CAN_AUTHORIZE_STATUSES.includes(this.status);
5151
}
5252

5353
public abstract get provider(): IProvider | null;

packages/no-modal/src/base/connector/connectorStatus.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@ import { CONNECTOR_STATUS } from "./constants";
22
import { CONNECTOR_STATUS_TYPE } from "./interfaces";
33

44
export const CONNECTED_STATUSES: CONNECTOR_STATUS_TYPE[] = [CONNECTOR_STATUS.CONNECTED, CONNECTOR_STATUS.AUTHORIZED];
5+
6+
export const CAN_AUTHORIZE_STATUSES: CONNECTOR_STATUS_TYPE[] = [
7+
CONNECTOR_STATUS.AUTHORIZING,
8+
CONNECTOR_STATUS.AUTHORIZED,
9+
CONNECTOR_STATUS.CONNECTED,
10+
];

packages/no-modal/src/connectors/injected-solana-connector/walletStandardConnector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export class WalletStandardConnector extends BaseSolanaConnector<void> {
151151
}
152152

153153
async getUserInfo(): Promise<Partial<UserInfo>> {
154-
if (!this.isWalletConnected) throw WalletLoginError.notConnectedError("Not connected with wallet, Please login/connect first");
154+
if (!this.canAuthorize) throw WalletLoginError.notConnectedError("Not connected with wallet, Please login/connect first");
155155
return {};
156156
}
157157

packages/no-modal/src/connectors/wallet-connect-v2-connector/walletConnectV2Connector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class WalletConnectV2Connector extends BaseConnector<void> {
242242
}
243243

244244
async getUserInfo(): Promise<Partial<UserInfo>> {
245-
if (!this.connected) throw WalletLoginError.notConnectedError("Not connected with wallet, Please login/connect first");
245+
if (!this.canAuthorize) throw WalletLoginError.notConnectedError("Not connected with wallet, Please login/connect first");
246246
return {};
247247
}
248248

packages/no-modal/src/noModal.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
ANALYTICS_SDK_TYPE,
1212
AuthLoginParams,
1313
AUTHORIZED_EVENT_DATA,
14+
CAN_AUTHORIZE_STATUSES,
1415
CHAIN_NAMESPACES,
1516
type ChainNamespaceType,
1617
type CONNECTED_EVENT_DATA,
@@ -441,7 +442,7 @@ export class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEvents> imp
441442

442443
async getUserInfo(): Promise<Partial<UserInfo>> {
443444
log.debug("Getting user info", this.status, this.connectedConnector?.name);
444-
if (!CONNECTED_STATUSES.includes(this.status) || !this.connectedConnector) throw WalletLoginError.notConnectedError(`No wallet is connected`);
445+
if (!CAN_AUTHORIZE_STATUSES.includes(this.status) || !this.connectedConnector) throw WalletLoginError.notConnectedError(`No wallet is connected`);
445446
return this.connectedConnector.getUserInfo();
446447
}
447448

@@ -484,8 +485,7 @@ export class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEvents> imp
484485
}
485486

486487
async getIdentityToken(): Promise<IdentityTokenInfo> {
487-
if (![...CONNECTED_STATUSES, CONNECTOR_STATUS.AUTHORIZING].includes(this.status) || !this.connectedConnector)
488-
throw WalletLoginError.notConnectedError(`No wallet is connected`);
488+
if (!CAN_AUTHORIZE_STATUSES.includes(this.status) || !this.connectedConnector) throw WalletLoginError.notConnectedError(`No wallet is connected`);
489489

490490
const trackData = { connector: this.connectedConnector.name };
491491
try {
@@ -891,7 +891,7 @@ export class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEvents> imp
891891

892892
this.status = CONNECTOR_STATUS.CONNECTED;
893893
log.debug("connected", this.status, this.connectedConnectorName);
894-
this.connectToPlugins({ connector: data.connector as WALLET_CONNECTOR_TYPE });
894+
this.connectToPlugins({ ...data, connector: data.connector as WALLET_CONNECTOR_TYPE });
895895
this.emit(CONNECTOR_EVENTS.CONNECTED, { ...data, loginMode: this.loginMode });
896896
});
897897

packages/no-modal/src/plugins/wallet-services-plugin/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import WsEmbed from "@web3auth/ws-embed";
55
import {
66
type Analytics,
77
ANALYTICS_EVENTS,
8+
CAN_AUTHORIZE_STATUSES,
89
CHAIN_NAMESPACES,
910
ChainNamespaceType,
10-
CONNECTED_STATUSES,
1111
EVM_PLUGINS,
1212
IPlugin,
1313
IProvider,
@@ -91,7 +91,7 @@ class WalletServicesPlugin extends SafeEventEmitter implements IPlugin {
9191
}
9292
}
9393

94-
if (!CONNECTED_STATUSES.includes(this.web3auth.status)) {
94+
if (!CAN_AUTHORIZE_STATUSES.includes(this.web3auth.status)) {
9595
throw WalletServicesPluginError.web3AuthNotConnected();
9696
} else if (!this.web3auth.provider) {
9797
throw WalletServicesPluginError.providerRequired();

packages/no-modal/src/vue/Web3AuthProvider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
CONNECTOR_STATUS,
77
type CONNECTOR_STATUS_TYPE,
88
type IProvider,
9+
log,
910
WalletInitializationError,
1011
Web3AuthContextKey,
1112
} from "../base";
@@ -82,6 +83,7 @@ export const Web3AuthProvider = defineComponent({
8283
isInitializing.value = true;
8384
await newWeb3Auth.init({ signal: controller.signal });
8485
} catch (error) {
86+
log.error("Error initializing web3auth", error);
8587
initError.value = error as Error;
8688
} finally {
8789
isInitializing.value = false;

packages/no-modal/src/vue/composables/useCheckout.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BaseEmbedControllerState } from "@toruslabs/base-controllers";
22
import { Ref, ref } from "vue";
33

4-
import { WalletServicesPluginError, Web3AuthError } from "../../base";
4+
import { log, WalletServicesPluginError, Web3AuthError } from "../../base";
55
import { useWalletServicesPlugin } from "./useWalletServicesPlugin";
66

77
export interface IUseCheckout {
@@ -24,6 +24,7 @@ export const useCheckout = (): IUseCheckout => {
2424

2525
await plugin.value.showCheckout(showCheckoutParams);
2626
} catch (err) {
27+
log.error("Error showing checkout", err);
2728
error.value = err as Web3AuthError;
2829
} finally {
2930
loading.value = false;

packages/no-modal/src/vue/composables/useEnableMFA.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Ref, ref } from "vue";
22

3-
import { WalletInitializationError, Web3AuthError } from "../../base";
3+
import { log, WalletInitializationError, Web3AuthError } from "../../base";
44
import { useWeb3AuthInner } from "./useWeb3AuthInner";
55

66
export interface IUseEnableMFA {
@@ -21,6 +21,7 @@ export const useEnableMFA = (): IUseEnableMFA => {
2121
loading.value = true;
2222
await web3Auth.value.enableMFA();
2323
} catch (err) {
24+
log.error("Error enabling MFA", err);
2425
error.value = err as Web3AuthError;
2526
} finally {
2627
loading.value = false;

packages/no-modal/src/vue/composables/useFunding.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BaseEmbedControllerState } from "@toruslabs/base-controllers";
22
import { Ref, ref } from "vue";
33

4-
import { WalletServicesPluginError, Web3AuthError } from "../../base";
4+
import { log, WalletServicesPluginError, Web3AuthError } from "../../base";
55
import { useWalletServicesPlugin } from "./useWalletServicesPlugin";
66

77
export interface IUseFunding {
@@ -24,6 +24,7 @@ export const useFunding = (): IUseFunding => {
2424

2525
await plugin.value.showFunding(showFundingParams);
2626
} catch (err) {
27+
log.error("Error showing funding", err);
2728
error.value = err as Web3AuthError;
2829
} finally {
2930
loading.value = false;

0 commit comments

Comments
 (0)