diff --git a/.changeset/dirty-peaches-beam.md b/.changeset/dirty-peaches-beam.md new file mode 100644 index 00000000..fffa8130 --- /dev/null +++ b/.changeset/dirty-peaches-beam.md @@ -0,0 +1,17 @@ +--- +'@rosen-bridge/shared-contexts': patch +'@rosen-ui/metamask-wallet': patch +'@rosen-ui/nautilus-wallet': patch +'@rosen-ui/eternl-wallet': patch +'@rosen-ui/flint-wallet': patch +'@rosen-ui/vespr-wallet': patch +'@rosen-ui/xdefi-wallet': patch +'@rosen-ui/lace-wallet': patch +'@rosen-ui/nami-wallet': patch +'@rosen-ui/swr-mock': patch +'@rosen-network/cardano': patch +'@rosen-bridge/ui-kit': patch +'@rosen-ui/types': patch +--- + +Update the source code to address the issues identified by the new ESLint rules configuration diff --git a/eslint.config.mjs b/eslint.config.mjs index e4b9a796..3173d489 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -7,52 +7,49 @@ import reactRefresh from 'eslint-plugin-react-refresh'; import globals from 'globals'; export default [ + // General Ignore Patterns { ignores: ['**/dist/*'], }, + + // Base Configuration for JS/TS Files { - files: [ - 'networks/**/*.{js,jsx,ts,tsx}', - 'packages/**/*.{js,jsx,ts,tsx}', - 'wallets/**/*.{js,jsx,ts,tsx}', - ], - rules: { - ...pluginJs.configs.recommended.rules, - ...typescriptEslint.configs.recommended.rules, - }, - plugins: { - '@typescript-eslint': typescriptEslint, - }, + files: ['{networks,packages,wallets}/**/*.{js,jsx,ts,tsx}'], languageOptions: { parser: typescriptParser, ecmaVersion: 'latest', sourceType: 'module', }, + plugins: { + '@typescript-eslint': typescriptEslint, + }, + rules: { + ...pluginJs.configs.recommended.rules, + ...typescriptEslint.configs.recommended.rules, + }, }, + + // Browser-Specific Globals { - files: [ - 'networks/**/*.{js,jsx,ts,tsx}', - 'packages/asset-calculator/**/*.{js,jsx,ts,tsx}', - ], + files: ['{packages,wallets}/**/*.{js,jsx,ts,tsx}'], + ignores: ['packages/asset-calculator/**/*.{js,jsx,ts,tsx}'], languageOptions: { - globals: globals.node, + globals: globals.browser, }, }, + + // Node-Specific Globals { files: [ - 'packages/common-hooks/**/*.{js,jsx,ts,tsx}', - 'packages/constants/**/*.{js,jsx,ts,tsx}', - 'packages/icons/**/*.{js,jsx,ts,tsx}', - 'packages/swr-helpers/**/*.{js,jsx,ts,tsx}', - 'packages/swr-mock/**/*.{js,jsx,ts,tsx}', - 'packages/types/**/*.{js,jsx,ts,tsx}', - 'packages/utils/**/*.{js,jsx,ts,tsx}', - 'wallets/**/*.{js,jsx,ts,tsx}', + 'networks/**/*.{js,jsx,ts,tsx}', + 'packages/asset-calculator/**/*.{js,jsx,ts,tsx}', ], languageOptions: { - globals: globals.browser, + globals: globals.node, }, }, + + // React-Specific Rules and Plugins { files: [ 'packages/shared-contexts/**/*.{js,jsx,ts,tsx}', @@ -67,15 +64,17 @@ export default [ ...reactHooks.configs.recommended.rules, }, }, - /** - * TODO: revise the global ESLint configuration rules - * local:ergo/rosen-bridge/ui#442 - */ + + // Additional Global Rules { rules: { - 'no-undef': 'off', - '@typescript-eslint/no-unused-expressions': 'off', + '@typescript-eslint/no-unused-expressions': [ + 'error', + { allowShortCircuit: true }, + ], }, }, + + // Integrate Prettier for Formatting prettier, ]; diff --git a/networks/cardano/src/types.ts b/networks/cardano/src/types.ts index 400ae867..4bd9f2f6 100644 --- a/networks/cardano/src/types.ts +++ b/networks/cardano/src/types.ts @@ -40,5 +40,7 @@ export interface ConnectorAPI { * global type augmentation for wallets */ declare global { - let cardano: { [key: string]: ConnectorAPI }; + interface Window { + cardano: { [key: string]: ConnectorAPI }; + } } diff --git a/packages/shared-contexts/src/contexts/apiKeyContext.tsx b/packages/shared-contexts/src/contexts/apiKeyContext.tsx index 19f79769..559c5b87 100644 --- a/packages/shared-contexts/src/contexts/apiKeyContext.tsx +++ b/packages/shared-contexts/src/contexts/apiKeyContext.tsx @@ -1,4 +1,4 @@ -import { createContext, useReducer, useMemo } from 'react'; +import React, { createContext, useReducer, useMemo } from 'react'; type Action = | { diff --git a/packages/swr-mock/src/SWRConfig.tsx b/packages/swr-mock/src/SWRConfig.tsx index d7c78a68..b291ff1d 100644 --- a/packages/swr-mock/src/SWRConfig.tsx +++ b/packages/swr-mock/src/SWRConfig.tsx @@ -1,3 +1,5 @@ +import React from 'react'; + import { SWRConfig as SWRConfigBase } from 'swr'; import { mockMiddlewareFactory } from './mockMiddlewareFactory'; diff --git a/packages/swr-mock/src/mockMiddlewareFactory.ts b/packages/swr-mock/src/mockMiddlewareFactory.ts index 8902fee8..d7fa5139 100644 --- a/packages/swr-mock/src/mockMiddlewareFactory.ts +++ b/packages/swr-mock/src/mockMiddlewareFactory.ts @@ -2,6 +2,7 @@ * TODO: remove the inline ESLint comment * local:ergo/rosen-bridge/ui#441 */ + /* eslint-disable */ import { Key, Middleware, SWRHook } from 'swr'; diff --git a/packages/types/src/next.ts b/packages/types/src/next.ts index b41343f2..d6ecc7bb 100644 --- a/packages/types/src/next.ts +++ b/packages/types/src/next.ts @@ -1 +1,3 @@ +import React from 'react'; + export type LayoutProps = Record; diff --git a/packages/ui-kit/src/Providers/ThemeProvider.tsx b/packages/ui-kit/src/Providers/ThemeProvider.tsx index 2c7923bd..5fe4acd9 100644 --- a/packages/ui-kit/src/Providers/ThemeProvider.tsx +++ b/packages/ui-kit/src/Providers/ThemeProvider.tsx @@ -1,4 +1,4 @@ -import { createContext, useState } from 'react'; +import React, { createContext, useState } from 'react'; import { Theme, useMediaQuery } from '@mui/material'; import { ThemeProvider as MuiThemeProvider } from '@mui/material/styles'; @@ -6,12 +6,11 @@ import { useLocalStorageManager } from '@rosen-ui/common-hooks'; export const ThemeTogglerContext = createContext({ mode: 'light', - // eslint-disable-next-line @typescript-eslint/no-empty-function toggle: () => {}, }); export interface ThemeProviderProps { - children: JSX.Element; + children: React.ReactNode; theme: | Theme | { diff --git a/packages/ui-kit/src/components/common/ApiKeyModal.tsx b/packages/ui-kit/src/components/common/ApiKeyModal.tsx index 7a947206..e5772e4a 100644 --- a/packages/ui-kit/src/components/common/ApiKeyModal.tsx +++ b/packages/ui-kit/src/components/common/ApiKeyModal.tsx @@ -1,4 +1,4 @@ -import { FormEvent, useEffect, useState } from 'react'; +import React, { FormEvent, useEffect, useState } from 'react'; import { useForm, Controller } from 'react-hook-form'; import { KeySkeleton, Eye, EyeSlash, Times } from '@rosen-bridge/icons'; diff --git a/packages/ui-kit/src/components/common/EnhancedDialogTitle.tsx b/packages/ui-kit/src/components/common/EnhancedDialogTitle.tsx index a116b92a..bfa02267 100644 --- a/packages/ui-kit/src/components/common/EnhancedDialogTitle.tsx +++ b/packages/ui-kit/src/components/common/EnhancedDialogTitle.tsx @@ -1,3 +1,5 @@ +import React from 'react'; + import { styled } from '@mui/material'; import { Times } from '@rosen-bridge/icons'; @@ -11,7 +13,7 @@ const IconContainer = styled('div')(({ theme }) => ({ })); export type EnhancedDialogTitleProps = { - icon?: JSX.Element; + icon?: React.ReactNode; onClose?: React.MouseEventHandler; } & DialogTitleProps; diff --git a/packages/ui-kit/src/components/common/SuccessfulCopySnackbar.tsx b/packages/ui-kit/src/components/common/SuccessfulCopySnackbar.tsx index b5a71bdd..bd31a6ce 100644 --- a/packages/ui-kit/src/components/common/SuccessfulCopySnackbar.tsx +++ b/packages/ui-kit/src/components/common/SuccessfulCopySnackbar.tsx @@ -1,3 +1,5 @@ +import React from 'react'; + import { Alert, Snackbar } from '../base'; interface SuccessfulCopySnackbarProps { diff --git a/packages/ui-kit/src/components/common/Toolbar.tsx b/packages/ui-kit/src/components/common/Toolbar.tsx index e5134f7c..bd2afcc9 100644 --- a/packages/ui-kit/src/components/common/Toolbar.tsx +++ b/packages/ui-kit/src/components/common/Toolbar.tsx @@ -1,4 +1,4 @@ -import { ReactNode } from 'react'; +import React from 'react'; import { isLegacyTheme, useTheme } from '../../hooks/useTheme'; import { styled } from '../../styling'; @@ -22,7 +22,7 @@ export interface ToolbarProps { title: string; description?: string; isCentered?: boolean; - toolbarActions?: ReactNode; + toolbarActions?: React.ReactNode; } /** diff --git a/packages/ui-kit/src/contexts/snackbarContext.tsx b/packages/ui-kit/src/contexts/snackbarContext.tsx index 06d6f6b3..043740b5 100644 --- a/packages/ui-kit/src/contexts/snackbarContext.tsx +++ b/packages/ui-kit/src/contexts/snackbarContext.tsx @@ -1,4 +1,4 @@ -import { useReducer, createContext } from 'react'; +import React, { useReducer, createContext } from 'react'; import { SnackbarOrigin } from '@mui/material'; diff --git a/wallets/eternl-wallet/src/connectWallet.ts b/wallets/eternl-wallet/src/connectWallet.ts index f80ec4a0..7ec50ef3 100644 --- a/wallets/eternl-wallet/src/connectWallet.ts +++ b/wallets/eternl-wallet/src/connectWallet.ts @@ -3,7 +3,7 @@ */ export const connectWallet = async (): Promise => { - const granted = await cardano.eternl?.enable(); + const granted = await window.cardano.eternl?.enable(); if (!granted) { console.error('Failed to connect!'); diff --git a/wallets/eternl-wallet/src/getEternlWallet.ts b/wallets/eternl-wallet/src/getEternlWallet.ts index 247186e8..5989a438 100644 --- a/wallets/eternl-wallet/src/getEternlWallet.ts +++ b/wallets/eternl-wallet/src/getEternlWallet.ts @@ -13,6 +13,6 @@ export const getEternlWallet = () => { ...eternlWalletInfo, connectWallet, }, - () => cardano.eternl, + () => window.cardano.eternl, ); }; diff --git a/wallets/eternl-wallet/src/isEternlAvailable.ts b/wallets/eternl-wallet/src/isEternlAvailable.ts index 145216ed..538e0dc4 100644 --- a/wallets/eternl-wallet/src/isEternlAvailable.ts +++ b/wallets/eternl-wallet/src/isEternlAvailable.ts @@ -1,3 +1,3 @@ export const isEternlAvailable = (): boolean => { - return typeof cardano !== 'undefined' && !!cardano?.eternl; + return typeof window.cardano !== 'undefined' && !!window.cardano?.eternl; }; diff --git a/wallets/flint-wallet/src/connectWallet.ts b/wallets/flint-wallet/src/connectWallet.ts index a3dfb565..451ccd86 100644 --- a/wallets/flint-wallet/src/connectWallet.ts +++ b/wallets/flint-wallet/src/connectWallet.ts @@ -3,7 +3,7 @@ */ export const connectWallet = async () => { - const granted = await cardano.flint?.enable(); + const granted = await window.cardano.flint?.enable(); if (!granted) { console.error('Failed to connect!'); diff --git a/wallets/flint-wallet/src/getFlintWallet.ts b/wallets/flint-wallet/src/getFlintWallet.ts index a9a9b25e..7c7eeebc 100644 --- a/wallets/flint-wallet/src/getFlintWallet.ts +++ b/wallets/flint-wallet/src/getFlintWallet.ts @@ -13,5 +13,5 @@ export const getFlintWallet = () => ...flintWalletInfo, connectWallet, }, - () => cardano.flint, + () => window.cardano.flint, ); diff --git a/wallets/flint-wallet/src/isFlintAvailable.ts b/wallets/flint-wallet/src/isFlintAvailable.ts index f478eefa..ca8a1f87 100644 --- a/wallets/flint-wallet/src/isFlintAvailable.ts +++ b/wallets/flint-wallet/src/isFlintAvailable.ts @@ -1,3 +1,3 @@ export const isFlintAvailable = (): boolean => { - return typeof cardano !== 'undefined' && !!cardano?.flint; + return typeof window.cardano !== 'undefined' && !!window.cardano?.flint; }; diff --git a/wallets/lace-wallet/src/connectWallet.ts b/wallets/lace-wallet/src/connectWallet.ts index 4f8a2423..864cea80 100644 --- a/wallets/lace-wallet/src/connectWallet.ts +++ b/wallets/lace-wallet/src/connectWallet.ts @@ -3,7 +3,7 @@ */ export const connectWallet = async () => { - const granted = await cardano.lace?.enable(); + const granted = await window.cardano.lace?.enable(); if (!granted) { console.error('Failed to connect!'); diff --git a/wallets/lace-wallet/src/getLaceWallet.ts b/wallets/lace-wallet/src/getLaceWallet.ts index f280b619..0f05792b 100644 --- a/wallets/lace-wallet/src/getLaceWallet.ts +++ b/wallets/lace-wallet/src/getLaceWallet.ts @@ -13,6 +13,6 @@ export const getLaceWallet = () => { ...laceWalletInfo, connectWallet, }, - () => cardano.lace, + () => window.cardano.lace, ); }; diff --git a/wallets/lace-wallet/src/isLaceAvailable.ts b/wallets/lace-wallet/src/isLaceAvailable.ts index caa83538..c9394659 100644 --- a/wallets/lace-wallet/src/isLaceAvailable.ts +++ b/wallets/lace-wallet/src/isLaceAvailable.ts @@ -1,3 +1,3 @@ export const isLaceAvailable = () => { - return typeof cardano !== 'undefined' && !!cardano?.lace; + return typeof window.cardano !== 'undefined' && !!window.cardano?.lace; }; diff --git a/wallets/metamask-wallet/src/global.d.ts b/wallets/metamask-wallet/src/global.d.ts new file mode 100644 index 00000000..5514dd83 --- /dev/null +++ b/wallets/metamask-wallet/src/global.d.ts @@ -0,0 +1,11 @@ +/** + * global type augmentation for the wallet + */ +declare global { + interface Window { + ethereum: { + isMetaMask: boolean; + _metamask: unknown; + }; + } +} diff --git a/wallets/metamask-wallet/src/isMetaMaskAvailable.ts b/wallets/metamask-wallet/src/isMetaMaskAvailable.ts index efbc8924..ce4efc89 100644 --- a/wallets/metamask-wallet/src/isMetaMaskAvailable.ts +++ b/wallets/metamask-wallet/src/isMetaMaskAvailable.ts @@ -1,17 +1,7 @@ -/** - * global type augmentation for the wallet - */ -declare global { - let ethereum: { - isMetaMask: boolean; - _metamask: unknown; - }; -} - export const isMetaMaskAvailable = (): boolean => { return ( - typeof ethereum !== 'undefined' && - ethereum.isMetaMask && - !!ethereum._metamask + typeof window.ethereum !== 'undefined' && + window.ethereum.isMetaMask && + !!window.ethereum._metamask ); }; diff --git a/wallets/nami-wallet/src/connectWallet.ts b/wallets/nami-wallet/src/connectWallet.ts index 659b95ea..370becb1 100644 --- a/wallets/nami-wallet/src/connectWallet.ts +++ b/wallets/nami-wallet/src/connectWallet.ts @@ -3,7 +3,7 @@ */ export const connectWallet = async () => { - const granted = await cardano.nami?.enable(); + const granted = await window.cardano.nami?.enable(); if (!granted) { console.error('Failed to connect!'); diff --git a/wallets/nami-wallet/src/getNamiWallet.ts b/wallets/nami-wallet/src/getNamiWallet.ts index a139b59c..c74177c8 100644 --- a/wallets/nami-wallet/src/getNamiWallet.ts +++ b/wallets/nami-wallet/src/getNamiWallet.ts @@ -13,6 +13,6 @@ export const getNamiWallet = () => { ...namiWalletInfo, connectWallet, }, - () => cardano.nami, + () => window.cardano.nami, ); }; diff --git a/wallets/nami-wallet/src/isNamiAvailable.ts b/wallets/nami-wallet/src/isNamiAvailable.ts index 311ecff1..a540f3a9 100644 --- a/wallets/nami-wallet/src/isNamiAvailable.ts +++ b/wallets/nami-wallet/src/isNamiAvailable.ts @@ -1,3 +1,3 @@ export const isNamiAvailable = () => { - return typeof cardano !== 'undefined' && !!cardano?.nami; + return typeof window.cardano !== 'undefined' && !!window.cardano?.nami; }; diff --git a/wallets/nautilus-wallet/src/connectWallet.ts b/wallets/nautilus-wallet/src/connectWallet.ts index b87f9922..aef71f82 100644 --- a/wallets/nautilus-wallet/src/connectWallet.ts +++ b/wallets/nautilus-wallet/src/connectWallet.ts @@ -2,14 +2,14 @@ * handles the nautilus wallet connection */ export const connectWallet = async () => { - if (!ergoConnector?.nautilus) { + if (!window.ergoConnector?.nautilus) { throw new Error('EXTENSION_NOT_FOUND'); } - if (!ergoConnector.nautilus?.getContext) { + if (!window.ergoConnector.nautilus?.getContext) { return 'Wallet API has changed. Be sure to update your wallet to continue using it'; } - const nautilus = ergoConnector.nautilus; + const nautilus = window.ergoConnector.nautilus; return await nautilus.connect({ createErgoObject: false }); }; diff --git a/wallets/nautilus-wallet/src/getNautilusWallet.ts b/wallets/nautilus-wallet/src/getNautilusWallet.ts index e8de3192..9fd201d1 100644 --- a/wallets/nautilus-wallet/src/getNautilusWallet.ts +++ b/wallets/nautilus-wallet/src/getNautilusWallet.ts @@ -14,6 +14,6 @@ export const getNautilusWallet = () => { ...nautilusWalletInfo, connectWallet, }, - () => ergoConnector.nautilus, + () => window.ergoConnector.nautilus, ); }; diff --git a/wallets/nautilus-wallet/src/global.d.ts b/wallets/nautilus-wallet/src/global.d.ts index c8e403aa..3067f879 100644 --- a/wallets/nautilus-wallet/src/global.d.ts +++ b/wallets/nautilus-wallet/src/global.d.ts @@ -4,12 +4,14 @@ import { EipWalletApi } from '@rosen-ui/wallet-api'; * global type augmentation for nautilus wallet */ declare global { - let ergoConnector: { - nautilus: { - connect: (params: { createErgoObject: boolean }) => Promise; - getContext: () => Promise; + interface Window { + ergoConnector: { + nautilus: { + connect: (params: { createErgoObject: boolean }) => Promise; + getContext: () => Promise; + }; }; - }; + } } export {}; diff --git a/wallets/nautilus-wallet/src/isNautilusAvailable.ts b/wallets/nautilus-wallet/src/isNautilusAvailable.ts index 3db866a0..02dacd84 100644 --- a/wallets/nautilus-wallet/src/isNautilusAvailable.ts +++ b/wallets/nautilus-wallet/src/isNautilusAvailable.ts @@ -1,3 +1,6 @@ export const isNautilusAvailable = (): boolean => { - return typeof ergoConnector !== 'undefined' && !!ergoConnector.nautilus; + return ( + typeof window.ergoConnector !== 'undefined' && + !!window.ergoConnector.nautilus + ); }; diff --git a/wallets/vespr-wallet/src/connectWallet.ts b/wallets/vespr-wallet/src/connectWallet.ts index 7771be3c..0531ede6 100644 --- a/wallets/vespr-wallet/src/connectWallet.ts +++ b/wallets/vespr-wallet/src/connectWallet.ts @@ -3,7 +3,7 @@ */ export const connectWallet = async () => { - const granted = await cardano.vespr?.enable(); + const granted = await window.cardano.vespr?.enable(); if (!granted) { console.error('Failed to connect!'); diff --git a/wallets/vespr-wallet/src/index.ts b/wallets/vespr-wallet/src/index.ts index 93cab2af..f532390f 100644 --- a/wallets/vespr-wallet/src/index.ts +++ b/wallets/vespr-wallet/src/index.ts @@ -20,10 +20,10 @@ const getVesprWallet = () => ...walletInfo, connectWallet, }, - () => cardano.vespr, + () => window.cardano.vespr, ); export const isVesprAvailable = () => - typeof cardano !== 'undefined' && cardano?.vespr; + typeof window.cardano !== 'undefined' && window.cardano?.vespr; export default getVesprWallet; diff --git a/wallets/vespr-wallet/src/types/index.d.ts b/wallets/vespr-wallet/src/types/index.d.ts index d0bc8157..d912aa88 100644 --- a/wallets/vespr-wallet/src/types/index.d.ts +++ b/wallets/vespr-wallet/src/types/index.d.ts @@ -10,5 +10,7 @@ export interface ConnectorAPI { * global type augmentation for Vespr wallet */ declare global { - declare let cardano: { [key: string]: ConnectorAPI }; + interface Window { + cardano: { [key: string]: ConnectorAPI }; + } } diff --git a/wallets/xdefi-wallet/src/connectWallet.ts b/wallets/xdefi-wallet/src/connectWallet.ts index cb78752c..dbb1f285 100644 --- a/wallets/xdefi-wallet/src/connectWallet.ts +++ b/wallets/xdefi-wallet/src/connectWallet.ts @@ -10,9 +10,7 @@ export const connectWallet = async (): Promise => { message: '', purposes: [AddressPurpose.Payment], }, - // eslint-disable-next-line @typescript-eslint/no-empty-function onFinish: () => {}, - // eslint-disable-next-line @typescript-eslint/no-empty-function onCancel: () => {}, }); return true; diff --git a/wallets/xdefi-wallet/src/global.d.ts b/wallets/xdefi-wallet/src/global.d.ts index e2058011..a804d974 100644 --- a/wallets/xdefi-wallet/src/global.d.ts +++ b/wallets/xdefi-wallet/src/global.d.ts @@ -1,5 +1,7 @@ declare global { - declare let xfi: { bitcoin: unknown }; + interface Window { + xfi: { bitcoin: unknown }; + } } export {}; diff --git a/wallets/xdefi-wallet/src/isXdefiAvailable.ts b/wallets/xdefi-wallet/src/isXdefiAvailable.ts index db4b4e3a..958b7db8 100644 --- a/wallets/xdefi-wallet/src/isXdefiAvailable.ts +++ b/wallets/xdefi-wallet/src/isXdefiAvailable.ts @@ -1,3 +1,3 @@ export const isXdefiAvailable = (): boolean => { - return typeof xfi !== 'undefined' && !!xfi?.bitcoin; + return typeof window.xfi !== 'undefined' && !!window.xfi.bitcoin; };