diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 2605a248..42d0f2ac 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -3,8 +3,7 @@ module.exports = { // this should be just temporary. env: {browser: true, es2020: true}, extends: [ - // 'eslint:recommended', - // 'plugin:@typescript-eslint/recommended', + "plugin:@typescript-eslint/recommended", "plugin:react-hooks/recommended", ], parser: "@typescript-eslint/parser", @@ -12,5 +11,8 @@ module.exports = { // plugins: ['react-refresh'], rules: { // 'react-refresh/only-export-components': 'warn', + // TODO: Remove these exceptions once we have better guards + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-non-null-asserted-optional-chain': 'off' }, }; diff --git a/src/api/hooks/useGetANS.ts b/src/api/hooks/useGetANS.ts index 28780176..9dbdc52f 100644 --- a/src/api/hooks/useGetANS.ts +++ b/src/api/hooks/useGetANS.ts @@ -30,7 +30,7 @@ export function useGetNameFromAddress( shouldCache = false, isValidator = false, ) { - const [state, _] = useGlobalState(); + const [state] = useGlobalState(); const queryResult = useQuery({ queryKey: ["ANSName", address, shouldCache, state.network_name], queryFn: () => { diff --git a/src/api/hooks/useGetAccount.ts b/src/api/hooks/useGetAccount.ts index 10445e1e..f548615e 100644 --- a/src/api/hooks/useGetAccount.ts +++ b/src/api/hooks/useGetAccount.ts @@ -5,7 +5,7 @@ import {ResponseError} from "../client"; import {useGlobalState} from "../../global-config/GlobalConfig"; export function useGetAccount(address: string) { - const [state, _setState] = useGlobalState(); + const [state] = useGlobalState(); const result = useQuery( ["account", {address}, state.network_value], diff --git a/src/api/hooks/useGetAccountModule.ts b/src/api/hooks/useGetAccountModule.ts index b847b53f..c99ae036 100644 --- a/src/api/hooks/useGetAccountModule.ts +++ b/src/api/hooks/useGetAccountModule.ts @@ -8,7 +8,7 @@ export function useGetAccountModule( address: string, moduleName: string, ): UseQueryResult { - const [state, _setState] = useGlobalState(); + const [state] = useGlobalState(); return useQuery( ["accountModule", {address, moduleName}, state.network_value], diff --git a/src/api/hooks/useGetAccountModules.ts b/src/api/hooks/useGetAccountModules.ts index 17bf293c..c16e22d5 100644 --- a/src/api/hooks/useGetAccountModules.ts +++ b/src/api/hooks/useGetAccountModules.ts @@ -7,7 +7,7 @@ import {useGlobalState} from "../../global-config/GlobalConfig"; export function useGetAccountModules( address: string, ): UseQueryResult { - const [state, _setState] = useGlobalState(); + const [state] = useGlobalState(); return useQuery, ResponseError>( ["accountModules", {address}, state.network_value], diff --git a/src/api/hooks/useGetAccountResource.ts b/src/api/hooks/useGetAccountResource.ts index 9868877a..55df5263 100644 --- a/src/api/hooks/useGetAccountResource.ts +++ b/src/api/hooks/useGetAccountResource.ts @@ -19,7 +19,7 @@ export function useGetAccountResource( address: string, resource: string, ): UseQueryResult { - const [state, _setState] = useGlobalState(); + const [state] = useGlobalState(); return useQuery( ["accountResource", {address, resource}, state.network_value], diff --git a/src/api/hooks/useGetAccountResources.ts b/src/api/hooks/useGetAccountResources.ts index e66c7bbf..69f91cc5 100644 --- a/src/api/hooks/useGetAccountResources.ts +++ b/src/api/hooks/useGetAccountResources.ts @@ -7,7 +7,7 @@ import {useGlobalState} from "../../global-config/GlobalConfig"; export function useGetAccountResources( address: string, ): UseQueryResult { - const [state, _setState] = useGlobalState(); + const [state] = useGlobalState(); return useQuery, ResponseError>( ["accountResources", {address}, state.network_value], diff --git a/src/api/hooks/useGetAccountTokens.ts b/src/api/hooks/useGetAccountTokens.ts index 0d1de967..296df918 100644 --- a/src/api/hooks/useGetAccountTokens.ts +++ b/src/api/hooks/useGetAccountTokens.ts @@ -1,8 +1,3 @@ -import { - Current_Token_Datas, - Current_Token_Datas_V2, - Current_Token_Ownerships_V2, -} from "aptos"; import {useGlobalState} from "../../global-config/GlobalConfig"; import {useQuery} from "@tanstack/react-query"; import {normalizeAddress} from "../../utils"; diff --git a/src/api/hooks/useGetAccountTransactions.ts b/src/api/hooks/useGetAccountTransactions.ts index 8a6aeeed..fae211cb 100644 --- a/src/api/hooks/useGetAccountTransactions.ts +++ b/src/api/hooks/useGetAccountTransactions.ts @@ -9,7 +9,7 @@ export function useGetAccountTransactions( start?: number, limit?: number, ): UseQueryResult, ResponseError> { - const [state, _setState] = useGlobalState(); + const [state] = useGlobalState(); const accountTransactionsResult = useQuery< Array, diff --git a/src/api/hooks/useGetAnalyticsData.ts b/src/api/hooks/useGetAnalyticsData.ts index f55dbb6d..4ef759f0 100644 --- a/src/api/hooks/useGetAnalyticsData.ts +++ b/src/api/hooks/useGetAnalyticsData.ts @@ -70,7 +70,7 @@ export type DailyUserTxnData = { }; export function useGetAnalyticsData() { - const [state, _] = useGlobalState(); + const [state] = useGlobalState(); const [data, setData] = useState(); useEffect(() => { diff --git a/src/api/hooks/useGetBlock.ts b/src/api/hooks/useGetBlock.ts index 9edaf9b9..f3aa6b49 100644 --- a/src/api/hooks/useGetBlock.ts +++ b/src/api/hooks/useGetBlock.ts @@ -11,7 +11,7 @@ export function useGetBlockByHeight({ height: number; withTransactions?: boolean; }) { - const [state, _setState] = useGlobalState(); + const [state] = useGlobalState(); const result = useQuery( ["block", height, state.network_value], @@ -28,7 +28,7 @@ export function useGetBlockByVersion({ version: number; withTransactions?: boolean; }) { - const [state, _setState] = useGlobalState(); + const [state] = useGlobalState(); const result = useQuery( ["block", version, state.network_value], diff --git a/src/api/hooks/useGetCoinSupplyLimit.tsx b/src/api/hooks/useGetCoinSupplyLimit.tsx index ab54e142..67a87acc 100644 --- a/src/api/hooks/useGetCoinSupplyLimit.tsx +++ b/src/api/hooks/useGetCoinSupplyLimit.tsx @@ -56,7 +56,7 @@ async function fetchTotalSupply( } export function useGetCoinSupplyLimit(): number | null { - const [state, _] = useGlobalState(); + const [state] = useGlobalState(); const [totalSupply, setTotalSupply] = useState(null); const {data: coinInfo} = useGetAccountResource( "0x1", diff --git a/src/api/hooks/useGetDelegationNodeInfo.ts b/src/api/hooks/useGetDelegationNodeInfo.ts index 55a7bc18..5b4478b8 100644 --- a/src/api/hooks/useGetDelegationNodeInfo.ts +++ b/src/api/hooks/useGetDelegationNodeInfo.ts @@ -30,7 +30,7 @@ type DelegationNodeInfoProps = { export function useGetDelegationNodeInfo({ validatorAddress, }: DelegationNodeInfoProps): DelegationNodeInfoResponse { - const [{aptos_client: client}, _] = useGlobalState(); + const [{aptos_client: client}] = useGlobalState(); const {totalVotingPower} = useGetValidatorSet(); const { diff --git a/src/api/hooks/useGetDelegatorStakeInfo.ts b/src/api/hooks/useGetDelegatorStakeInfo.ts index 0419d5e9..51d49caa 100644 --- a/src/api/hooks/useGetDelegatorStakeInfo.ts +++ b/src/api/hooks/useGetDelegatorStakeInfo.ts @@ -7,7 +7,7 @@ export function useGetDelegatorStakeInfo( delegatorAddress: Types.Address, validatorAddress: Types.Address, ) { - const [state, _] = useGlobalState(); + const [state] = useGlobalState(); const [stakes, setStakes] = useState([]); useEffect(() => { diff --git a/src/api/hooks/useGetEpochTime.ts b/src/api/hooks/useGetEpochTime.ts index fa6d8c97..613d4b87 100644 --- a/src/api/hooks/useGetEpochTime.ts +++ b/src/api/hooks/useGetEpochTime.ts @@ -12,7 +12,7 @@ interface BlockResourceData { } export function useGetEpochTime() { - const [state, _] = useGlobalState(); + const [state] = useGlobalState(); const [curEpoch, setCurEpoch] = useState(); const [lastEpochTime, setLastEpochTime] = useState(); const [epochInterval, setEpochInterval] = useState(); diff --git a/src/api/hooks/useGetInDevMode.ts b/src/api/hooks/useGetInDevMode.ts index abb6fd9b..7da51f73 100644 --- a/src/api/hooks/useGetInDevMode.ts +++ b/src/api/hooks/useGetInDevMode.ts @@ -1,6 +1,6 @@ import {useGlobalState} from "../../global-config/GlobalConfig"; export function useGetInDevMode(): boolean { - const [state, _] = useGlobalState(); + const [state] = useGlobalState(); return state.feature_name && state.feature_name === "dev"; } diff --git a/src/api/hooks/useGetInMainnet.ts b/src/api/hooks/useGetInMainnet.ts index b55d3f67..fd2b129f 100644 --- a/src/api/hooks/useGetInMainnet.ts +++ b/src/api/hooks/useGetInMainnet.ts @@ -2,6 +2,6 @@ import {useGlobalState} from "../../global-config/GlobalConfig"; // TODO: replace existing mainnet checks across the code base with this hook export function useGetInMainnet(): boolean { - const [state, _] = useGlobalState(); + const [state] = useGlobalState(); return state.network_name === "mainnet"; } diff --git a/src/api/hooks/useGetMostRecentBlocks.ts b/src/api/hooks/useGetMostRecentBlocks.ts index f8b326e0..ef00010c 100644 --- a/src/api/hooks/useGetMostRecentBlocks.ts +++ b/src/api/hooks/useGetMostRecentBlocks.ts @@ -5,7 +5,7 @@ import {getLedgerInfo, getRecentBlocks} from ".."; import {Types} from "aptos"; export function useGetMostRecentBlocks(count: number) { - const [state, _] = useGlobalState(); + const [state] = useGlobalState(); const [isLoading, setIsLoading] = useState(true); const [recentBlocks, setRecentBlocks] = useState([]); diff --git a/src/api/hooks/useGetSearchResults.ts b/src/api/hooks/useGetSearchResults.ts index 72b4ef6e..71c7c877 100644 --- a/src/api/hooks/useGetSearchResults.ts +++ b/src/api/hooks/useGetSearchResults.ts @@ -30,7 +30,7 @@ export const NotFoundResult: SearchResult = { export default function useGetSearchResults(input: string) { const [results, setResults] = useState([]); - const [state, _setState] = useGlobalState(); + const [state] = useGlobalState(); const searchText = input.trim(); diff --git a/src/api/hooks/useGetStakingRewardsRate.ts b/src/api/hooks/useGetStakingRewardsRate.ts index 423f70d6..c8586684 100644 --- a/src/api/hooks/useGetStakingRewardsRate.ts +++ b/src/api/hooks/useGetStakingRewardsRate.ts @@ -9,7 +9,7 @@ interface ConfigurationData { } function useGetStakingConfig() { - const [state, _] = useGlobalState(); + const [state] = useGlobalState(); const [rewardsRatePerEpoch, setRewardsRatePerEpoch] = useState(); const [rewardsRateDenominator, setRewardsRateDenominator] = useState(); diff --git a/src/api/hooks/useGetTPS.ts b/src/api/hooks/useGetTPS.ts index 91ce1f4f..73fb3b29 100644 --- a/src/api/hooks/useGetTPS.ts +++ b/src/api/hooks/useGetTPS.ts @@ -6,7 +6,7 @@ import {useGetTPSByBlockHeight} from "./useGetTPSByBlockHeight"; import {AnalyticsData, ANALYTICS_DATA_URL} from "./useGetAnalyticsData"; export function useGetTPS() { - const [state, _] = useGlobalState(); + const [state] = useGlobalState(); const [blockHeight, setBlockHeight] = useState(); const {tps} = useGetTPSByBlockHeight(blockHeight); @@ -27,7 +27,7 @@ export function useGetTPS() { } export function useGetPeakTPS() { - const [state, _] = useGlobalState(); + const [state] = useGlobalState(); const [peakTps, setPeakTps] = useState(); useEffect(() => { diff --git a/src/api/hooks/useGetTransaction.ts b/src/api/hooks/useGetTransaction.ts index c2816e55..e6cff4a7 100644 --- a/src/api/hooks/useGetTransaction.ts +++ b/src/api/hooks/useGetTransaction.ts @@ -5,7 +5,7 @@ import {ResponseError} from "../../api/client"; import {useGlobalState} from "../../global-config/GlobalConfig"; export function useGetTransaction(txnHashOrVersion: string) { - const [state, _setState] = useGlobalState(); + const [state] = useGlobalState(); const result = useQuery( ["transaction", {txnHashOrVersion}, state.network_value], diff --git a/src/api/hooks/useGetValidatorSet.ts b/src/api/hooks/useGetValidatorSet.ts index a086d35d..33b0e93b 100644 --- a/src/api/hooks/useGetValidatorSet.ts +++ b/src/api/hooks/useGetValidatorSet.ts @@ -20,7 +20,7 @@ export interface Validator { } export function useGetValidatorSet() { - const [state, _] = useGlobalState(); + const [state] = useGlobalState(); const [totalVotingPower, setTotalVotingPower] = useState(null); const [numberOfActiveValidators, setNumberOfActiveValidators] = useState< number | null diff --git a/src/api/hooks/useGetValidators.ts b/src/api/hooks/useGetValidators.ts index d3b567cc..80016d2e 100644 --- a/src/api/hooks/useGetValidators.ts +++ b/src/api/hooks/useGetValidators.ts @@ -1,7 +1,7 @@ import {useGlobalState} from "../../global-config/GlobalConfig"; import {useEffect, useState} from "react"; import {useGetValidatorSet} from "./useGetValidatorSet"; -import {Network, NetworkName} from "../../constants"; +import {Network} from "../../constants"; import {standardizeAddress} from "../../utils"; const MAINNET_VALIDATORS_DATA_URL = @@ -36,8 +36,8 @@ export interface GeoData { epoch: number; } -function useGetValidatorsRawData(network: NetworkName) { - const [state, _] = useGlobalState(); +function useGetValidatorsRawData() { + const [state] = useGlobalState(); const [validatorsRawData, setValidatorsRawData] = useState( [], ); @@ -85,12 +85,9 @@ function useGetValidatorsRawData(network: NetworkName) { return {validatorsRawData}; } -export function useGetValidators(network?: NetworkName) { - const [state] = useGlobalState(); +export function useGetValidators() { const {activeValidators} = useGetValidatorSet(); - const {validatorsRawData} = useGetValidatorsRawData( - network ?? state.network_name, - ); + const {validatorsRawData} = useGetValidatorsRawData(); const [validators, setValidators] = useState([]); diff --git a/src/api/hooks/useGoogleTagManager.ts b/src/api/hooks/useGoogleTagManager.ts index 32d3e190..f3bffa81 100644 --- a/src/api/hooks/useGoogleTagManager.ts +++ b/src/api/hooks/useGoogleTagManager.ts @@ -1,4 +1,4 @@ -import TagManager from "react-gtm-module"; +import TagManager, {DataLayerArgs} from "react-gtm-module"; type GTMParams = { events: object; @@ -12,6 +12,6 @@ export const initGTM = ({events}: GTMParams) => { TagManager.initialize(tagManagerArgs); }; -export const sendToGTM = (dataLayer: Object): void => { +export const sendToGTM = (dataLayer: DataLayerArgs): void => { TagManager.dataLayer(dataLayer); }; diff --git a/src/api/hooks/useGraphqlClient.tsx b/src/api/hooks/useGraphqlClient.tsx index ec9973cf..ec31d54d 100644 --- a/src/api/hooks/useGraphqlClient.tsx +++ b/src/api/hooks/useGraphqlClient.tsx @@ -42,7 +42,7 @@ function getGraphqlClient( } export function useGetGraphqlClient() { - const [state, _] = useGlobalState(); + const [state] = useGlobalState(); const [graphqlClient, setGraphqlClient] = useState< ApolloClient >(getGraphqlClient(state.network_name)); @@ -65,7 +65,7 @@ export function GraphqlClientProvider({children}: GraphqlClientProviderProps) { } export function useGetIsGraphqlClientSupported(): boolean { - const [state, _] = useGlobalState(); + const [state] = useGlobalState(); const [isGraphqlClientSupported, setIsGraphqlClientSupported] = useState(getIsGraphqlClientSupportedFor(state.network_name)); diff --git a/src/api/hooks/useSubmitTransaction.ts b/src/api/hooks/useSubmitTransaction.ts index 1fecdcf4..f7807697 100644 --- a/src/api/hooks/useSubmitTransaction.ts +++ b/src/api/hooks/useSubmitTransaction.ts @@ -72,7 +72,7 @@ const useSubmitTransaction = () => { } // transaction failed return {...responseOnError, message: response.message}; - } catch (error: any) { + } catch (error) { if (error instanceof FailedTransactionError) { return { transactionSubmitted: true, @@ -80,8 +80,9 @@ const useSubmitTransaction = () => { message: error.message, success: false, }; + } else if (error instanceof Error) { + return {...responseOnError, message: error.message}; } - responseOnError.message = error; } return responseOnError; }; diff --git a/src/components/IndividualPageContent/ContentValue/CurrencyValue.tsx b/src/components/IndividualPageContent/ContentValue/CurrencyValue.tsx index a08c34b0..e6e3aca7 100644 --- a/src/components/IndividualPageContent/ContentValue/CurrencyValue.tsx +++ b/src/components/IndividualPageContent/ContentValue/CurrencyValue.tsx @@ -65,7 +65,7 @@ export default function CurrencyValue({ fixedDecimalPlaces, currencyCode, }: CurrencyValueProps) { - let number = getFormattedBalanceStr(amount, decimals, fixedDecimalPlaces); + const number = getFormattedBalanceStr(amount, decimals, fixedDecimalPlaces); if (currencyCode) { return ( diff --git a/src/components/IndividualPageContent/ContentValue/TimestampValue.tsx b/src/components/IndividualPageContent/ContentValue/TimestampValue.tsx index 90d22dcd..56f57242 100644 --- a/src/components/IndividualPageContent/ContentValue/TimestampValue.tsx +++ b/src/components/IndividualPageContent/ContentValue/TimestampValue.tsx @@ -26,7 +26,7 @@ export default function TimestampValue({timestamp}: TimestampValueProps) { const moment = parseTimestamp(timestamp); const timestamp_display = timestampDisplay(moment); - const copyTimestamp = async (event: React.MouseEvent) => { + const copyTimestamp = async () => { await navigator.clipboard.writeText(timestamp); setTooltipOpen(true); diff --git a/src/components/IndividualPageContent/JsonCard.tsx b/src/components/IndividualPageContent/JsonCard.tsx index a78398ff..6deb5513 100644 --- a/src/components/IndividualPageContent/JsonCard.tsx +++ b/src/components/IndividualPageContent/JsonCard.tsx @@ -45,7 +45,7 @@ export default function JsonCard({ } }; - const copyCard = async (event: React.MouseEvent) => { + const copyCard = async () => { await navigator.clipboard.writeText(jsonData); setTooltipOpen(true); diff --git a/src/components/Table/TableTooltip.tsx b/src/components/Table/TableTooltip.tsx index d1b392a9..7c51cc41 100644 --- a/src/components/Table/TableTooltip.tsx +++ b/src/components/Table/TableTooltip.tsx @@ -28,7 +28,7 @@ export default function TableTooltip({children, title}: TableTooltipProps) { (false); - const copyAddress = async (_event: React.MouseEvent) => { + const copyAddress = async () => { await navigator.clipboard.writeText(hash); setTooltipOpen(true); diff --git a/src/pages/Account/Components/AccountAllTransactions.tsx b/src/pages/Account/Components/AccountAllTransactions.tsx index 7b3afcaf..4887089b 100644 --- a/src/pages/Account/Components/AccountAllTransactions.tsx +++ b/src/pages/Account/Components/AccountAllTransactions.tsx @@ -8,7 +8,6 @@ import { useGetAccountAllTransactionVersions, } from "../../../api/hooks/useGetAccountAllTransactions"; import EmptyTabContent from "../../../components/IndividualPageContent/EmptyTabContent"; -import {Statsig} from "statsig-react"; import {useLogEventWithBasic} from "../hooks/useLogEventWithBasic"; function RenderPagination({ @@ -62,7 +61,7 @@ export function AccountAllTransactionsWithPagination({ numPages, countPerPage, }: AccountAllTransactionsWithPaginationProps) { - const [searchParams, _setSearchParams] = useSearchParams(); + const [searchParams] = useSearchParams(); const currentPage = parseInt(searchParams.get("page") ?? "1"); const offset = (currentPage - 1) * countPerPage; diff --git a/src/pages/Account/Components/CodeSnippet.tsx b/src/pages/Account/Components/CodeSnippet.tsx index e518cdfc..d0bfe157 100644 --- a/src/pages/Account/Components/CodeSnippet.tsx +++ b/src/pages/Account/Components/CodeSnippet.tsx @@ -116,7 +116,7 @@ export function Code({bytecode}: {bytecode: string}) { const theme = useTheme(); const [tooltipOpen, setTooltipOpen] = useState(false); - async function copyCode(event: React.MouseEvent) { + async function copyCode() { if (!sourceCode) return; await navigator.clipboard.writeText(sourceCode); @@ -168,9 +168,9 @@ export function Code({bytecode}: {bytecode: string}) { >