From 10df90821b473fd668907cf3e447dfe3825317fc Mon Sep 17 00:00:00 2001 From: amanraj1608 Date: Wed, 13 Sep 2023 19:56:23 -0400 Subject: [PATCH] fix: more lint issues --- .eslintrc.js | 1 + packages/bundler/src/Bundler.ts | 1 + packages/bundler/src/utils/Constants.ts | 1 + packages/bundler/src/utils/Types.ts | 1 + packages/common/src/Constants.ts | 1 + .../modules/src/SessionKeyManagerModule.ts | 4 +- .../src/interfaces/IValidationModule.ts | 4 +- packages/modules/src/utils/Uid.ts | 2 +- packages/web3-auth-native/src/SocialLogin.ts | 8 ++- .../web3-auth-native/src/types/IWebBrowser.ts | 6 +-- packages/web3-auth-native/src/types/sdk.ts | 2 +- packages/web3-auth/src/SocialLogin.tsx | 52 +++++++++---------- packages/web3-auth/src/UI.tsx | 4 +- .../web3-auth/src/types/Web3AuthConfig.ts | 2 +- 14 files changed, 48 insertions(+), 41 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 8511d52f7..78d998dfd 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -24,6 +24,7 @@ module.exports = { "security/detect-object-injection": "warn", "security/detect-unsafe-regex": "error", "import/extensions": "off", + "security/detect-object-injection": "off", // turning off Injection Sink rule "@typescript-eslint/no-throw-literal": "off", // temp deactivated needs to be removed once fixed }, settings: {}, diff --git a/packages/bundler/src/Bundler.ts b/packages/bundler/src/Bundler.ts index 0fc8668a5..24399febf 100644 --- a/packages/bundler/src/Bundler.ts +++ b/packages/bundler/src/Bundler.ts @@ -23,6 +23,7 @@ import { JsonRpcProvider } from "@ethersproject/providers"; * Checkout the proposal for more details on Bundlers. */ export class Bundler implements IBundler { + // eslint-disable-next-line no-unused-vars UserOpReceiptIntervals: { [key in ChainId]?: number }; constructor(readonly bundlerConfig: Bundlerconfig) { diff --git a/packages/bundler/src/utils/Constants.ts b/packages/bundler/src/utils/Constants.ts index 5f4c74c7a..92e95cd1f 100644 --- a/packages/bundler/src/utils/Constants.ts +++ b/packages/bundler/src/utils/Constants.ts @@ -1,5 +1,6 @@ import { ChainId } from "@biconomy/core-types"; +// eslint-disable-next-line no-unused-vars export const UserOpReceiptIntervals: { [key in ChainId]?: number } = { [ChainId.MAINNET]: 10000, [ChainId.GOERLI]: 5000, diff --git a/packages/bundler/src/utils/Types.ts b/packages/bundler/src/utils/Types.ts index f3bad34e1..7fbda2c18 100644 --- a/packages/bundler/src/utils/Types.ts +++ b/packages/bundler/src/utils/Types.ts @@ -5,6 +5,7 @@ export type Bundlerconfig = { bundlerUrl: string; entryPointAddress?: string; chainId: ChainId; + // eslint-disable-next-line no-unused-vars userOpReceiptIntervals?: { [key in ChainId]?: number }; }; diff --git a/packages/common/src/Constants.ts b/packages/common/src/Constants.ts index 17745f6cd..1be9c427f 100644 --- a/packages/common/src/Constants.ts +++ b/packages/common/src/Constants.ts @@ -2,6 +2,7 @@ import { ChainId } from "@biconomy/core-types"; export const NODE_CLIENT_URL = "https://sdk-backend.prod.biconomy.io/v1"; +// eslint-disable-next-line no-unused-vars export const RPC_PROVIDER_URLS: { [key in ChainId]?: string } = { [ChainId.MAINNET]: "https://rpc.ankr.com/eth", [ChainId.GOERLI]: "https://rpc.ankr.com/eth_goerli", diff --git a/packages/modules/src/SessionKeyManagerModule.ts b/packages/modules/src/SessionKeyManagerModule.ts index 776d6bbb9..6ee8ca2bb 100644 --- a/packages/modules/src/SessionKeyManagerModule.ts +++ b/packages/modules/src/SessionKeyManagerModule.ts @@ -217,7 +217,7 @@ export class SessionKeyManagerModule extends BaseValidationModule { * @param status The status to be updated * @returns */ - async updateSessionStatus(param: SessionSearchParam, status: SessionStatus) { + async updateSessionStatus(param: SessionSearchParam, status: SessionStatus): Promise { this.sessionStorageClient.updateSessionStatus(param, status); } @@ -225,7 +225,7 @@ export class SessionKeyManagerModule extends BaseValidationModule { * @remarks This method is used to clear all the pending sessions * @returns */ - async clearPendingSessions() { + async clearPendingSessions(): Promise { this.sessionStorageClient.clearPendingSessions(); } diff --git a/packages/modules/src/interfaces/IValidationModule.ts b/packages/modules/src/interfaces/IValidationModule.ts index cc94e4187..150b08cc7 100644 --- a/packages/modules/src/interfaces/IValidationModule.ts +++ b/packages/modules/src/interfaces/IValidationModule.ts @@ -5,7 +5,7 @@ export interface IValidationModule { getAddress(): string; getInitData(): Promise; getSigner(): Promise; - signUserOpHash(userOpHash: string): Promise; - signMessage(message: Bytes | string): Promise; + signUserOpHash(_userOpHash: string): Promise; + signMessage(_message: Bytes | string): Promise; getDummySignature(): Promise; } diff --git a/packages/modules/src/utils/Uid.ts b/packages/modules/src/utils/Uid.ts index db4ff03ab..5cf4a6cca 100644 --- a/packages/modules/src/utils/Uid.ts +++ b/packages/modules/src/utils/Uid.ts @@ -1,5 +1,5 @@ // small uid generator, hex: 0-9, a-f (10 chars) -export const generateRandomHex = () => { +export const generateRandomHex = (): string => { const hexChars = "0123456789abcdef"; let result = ""; diff --git a/packages/web3-auth-native/src/SocialLogin.ts b/packages/web3-auth-native/src/SocialLogin.ts index 79288fc3d..a85530f1e 100644 --- a/packages/web3-auth-native/src/SocialLogin.ts +++ b/packages/web3-auth-native/src/SocialLogin.ts @@ -3,7 +3,7 @@ import base64url from 'base64url' import log from 'loglevel' import { URL } from 'react-native-url-polyfill' -import { IWebBrowser } from './types/IWebBrowser' +import { IWebBrowser, WebBrowserAuthSessionResult } from './types/IWebBrowser' import { SdkInitParams, SdkLoginParams, SdkLogoutParams, SocialLoginDto } from './types/sdk' import { State } from './types/State' @@ -59,7 +59,11 @@ class SocialLogin { } } - private async request(path: string, redirectUrl: string, params: Record = {}) { + private async request( + path: string, + redirectUrl: string, + params: Record = {} + ): Promise { const initParams = { ...this.initParams, clientId: this.clientId, diff --git a/packages/web3-auth-native/src/types/IWebBrowser.ts b/packages/web3-auth-native/src/types/IWebBrowser.ts index 45676d8d6..fcc51728c 100644 --- a/packages/web3-auth-native/src/types/IWebBrowser.ts +++ b/packages/web3-auth-native/src/types/IWebBrowser.ts @@ -271,9 +271,9 @@ export interface IWebBrowser { * the Promise fulfills with `{ type: 'dismiss' }` object. */ openAuthSessionAsync( - url: string, - redirectUrl: string, - browserParams?: WebBrowserOpenOptions + _url: string, + _redirectUrl: string, + _browserParams?: WebBrowserOpenOptions ): Promise // dismissAuthSession(): void; /** diff --git a/packages/web3-auth-native/src/types/sdk.ts b/packages/web3-auth-native/src/types/sdk.ts index 24b285b27..4f6bc16cb 100644 --- a/packages/web3-auth-native/src/types/sdk.ts +++ b/packages/web3-auth-native/src/types/sdk.ts @@ -16,7 +16,7 @@ export type SocialLoginDto = { } export type IOriginData = { - [P in string]: string + [P: string]: string } export type SdkInitParams = Omit< diff --git a/packages/web3-auth/src/SocialLogin.tsx b/packages/web3-auth/src/SocialLogin.tsx index 8d0cdab6e..306bdc95c 100644 --- a/packages/web3-auth/src/SocialLogin.tsx +++ b/packages/web3-auth/src/SocialLogin.tsx @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ import React from "react"; import { createRoot } from "react-dom/client"; import { ethers } from "ethers"; @@ -12,7 +13,7 @@ import NodeClient, { WhiteListSignatureResponse } from "@biconomy/node-client"; import UI from "./UI"; import { DefaultSocialLoginConfig, SocialLoginDTO, WhiteLabelDataType } from "./types/Web3AuthConfig"; -function createLoginModal(socialLogin: SocialLogin) { +function createLoginModal(socialLogin: SocialLogin): void { /* eslint-disable @typescript-eslint/no-explicit-any */ const root = createRoot((document as any).getElementById("w3a-modal")); root.render(); @@ -66,11 +67,10 @@ class SocialLogin { async whitelistUrl(origin: string): Promise { const whiteListUrlResponse: WhiteListSignatureResponse = await this.nodeClient.whitelistUrl(origin); - console.log(whiteListUrlResponse.data); return whiteListUrlResponse.data; } - async init(socialLoginDTO?: Partial) { + async init(socialLoginDTO?: Partial): Promise { const finalDTO: SocialLoginDTO = { chainId: "0x1", whitelistUrls: {}, @@ -84,7 +84,6 @@ class SocialLogin { if (socialLoginDTO.whteLableData) this.whiteLabel = socialLoginDTO.whteLableData; } try { - console.log("SocialLogin init"); const web3AuthCore = new Web3AuthCore({ clientId: this.clientId, chainConfig: { @@ -132,12 +131,12 @@ class SocialLogin { } } - getProvider() { + getProvider(): SafeEventEmitterProvider | null { return this.provider; } /* eslint-disable @typescript-eslint/no-explicit-any */ - private _createIframe(iframeContainerDiv: any) { + private _createIframe(iframeContainerDiv: any): void { this.walletIframe = document.createElement("iframe"); this.walletIframe.style.display = "none"; this.walletIframe.style.display = "relative"; @@ -148,7 +147,7 @@ class SocialLogin { iframeContainerDiv.appendChild(this.walletIframe); } - private createWalletDiv() { + private createWalletDiv(): void { // create a fixed div into html but keep it hidden initially const walletDiv = document.createElement("div"); walletDiv.id = "w3a-modal"; @@ -167,7 +166,7 @@ class SocialLogin { this._createIframe(walletDiv); } - showWallet() { + showWallet(): void { this.walletDiv.style.display = "block"; this.walletIframe.style.display = "block"; // Set height and width of the iframe to 600x341 @@ -179,13 +178,12 @@ class SocialLogin { el?.dispatchEvent(new Event("show-modal")); } - hideWallet() { - console.log("hide wallet"); + hideWallet(): void { this.walletDiv.style.display = "none"; this.walletIframe.style.display = "none"; } - async getUserInfo() { + async getUserInfo(): Promise | null> { if (this.web3auth) { const userInfo = await this.web3auth.getUserInfo(); this.userInfo = userInfo; @@ -194,20 +192,20 @@ class SocialLogin { return null; } - async getPrivateKey() { + async getPrivateKey(): Promise { if (this.web3auth && this.web3auth.provider) { const privateKey = await this.web3auth.provider.request({ method: "eth_private_key", }); - return privateKey; + return privateKey as string; } return null; } - async socialLogin(loginProvider: string) { + async socialLogin(loginProvider: string): Promise { if (!this.web3auth) { console.info("web3auth not initialized yet"); - return; + return null; } try { const web3authProvider = await this.web3auth.connectTo(WALLET_ADAPTERS.OPENLOGIN, { @@ -226,14 +224,14 @@ class SocialLogin { return web3authProvider; } catch (error) { console.error(error); - return error; + return null; } } - async emailLogin(email: string) { + async emailLogin(email: string): Promise { if (!this.web3auth) { console.info("web3auth not initialized yet"); - return; + return null; } try { const web3authProvider = await this.web3auth.connectTo(WALLET_ADAPTERS.OPENLOGIN, { @@ -253,14 +251,14 @@ class SocialLogin { return web3authProvider; } catch (error) { console.error(error); - return error; + return null; } } - async metamaskLogin() { + async metamaskLogin(): Promise { if (!this.web3auth) { console.log("web3auth not initialized yet"); - return; + return null; } try { const web3authProvider = await this.web3auth.connectTo(WALLET_ADAPTERS.METAMASK); @@ -277,14 +275,14 @@ class SocialLogin { return web3authProvider; } catch (error) { console.error(error); - return error; + return null; } } - async walletConnectLogin() { + async walletConnectLogin(): Promise { if (!this.web3auth) { console.log("web3auth not initialized yet"); - return; + return null; } try { const web3authProvider = await this.web3auth.connectTo(WALLET_ADAPTERS.WALLET_CONNECT_V1); @@ -301,11 +299,11 @@ class SocialLogin { return web3authProvider; } catch (error) { console.error(error); - return error; + return null; } } - async logout() { + async logout(): Promise { if (!this.web3auth) { console.log("web3auth not initialized yet"); return; @@ -322,7 +320,7 @@ const socialLoginSDK: SocialLogin = new SocialLogin(); export default SocialLogin; let initializedSocialLogin: SocialLogin | null = null; -const getSocialLoginSDK = async (socialLoginDTO?: Partial) => { +const getSocialLoginSDK = async (socialLoginDTO?: Partial): Promise => { if (initializedSocialLogin) { return initializedSocialLogin; } diff --git a/packages/web3-auth/src/UI.tsx b/packages/web3-auth/src/UI.tsx index ee8c30df2..2fd8e5187 100644 --- a/packages/web3-auth/src/UI.tsx +++ b/packages/web3-auth/src/UI.tsx @@ -22,12 +22,12 @@ const container = { const UI: React.FC = ({ socialLogin }) => { const [email, setEmail] = useState(""); - function handleEmailSubmit(event: React.SyntheticEvent) { + function handleEmailSubmit(event: React.SyntheticEvent): void { event.preventDefault(); socialLogin.emailLogin(email); } - function handleEmailChange(event: React.FormEvent) { + function handleEmailChange(event: React.FormEvent): void { setEmail(event.currentTarget.value); } diff --git a/packages/web3-auth/src/types/Web3AuthConfig.ts b/packages/web3-auth/src/types/Web3AuthConfig.ts index 8caee797c..404c7ef6e 100644 --- a/packages/web3-auth/src/types/Web3AuthConfig.ts +++ b/packages/web3-auth/src/types/Web3AuthConfig.ts @@ -9,7 +9,7 @@ export type WhiteLabelDataType = { export type SocialLoginDTO = { chainId: string; - whitelistUrls: { [P in string]: string }; + whitelistUrls: { [P: string]: string }; network: "mainnet" | "testnet"; whteLableData: WhiteLabelDataType; };